Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | /* mac80211 and PCI callbacks */ |
| 18 | |
| 19 | #include <linux/nl80211.h> |
| 20 | #include "core.h" |
| 21 | |
| 22 | #define ATH_PCI_VERSION "0.1" |
| 23 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 24 | static char *dev_info = "ath9k"; |
| 25 | |
| 26 | MODULE_AUTHOR("Atheros Communications"); |
| 27 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 28 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 29 | MODULE_LICENSE("Dual BSD/GPL"); |
| 30 | |
| 31 | static struct pci_device_id ath_pci_id_table[] __devinitdata = { |
| 32 | { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */ |
| 33 | { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */ |
| 34 | { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */ |
| 35 | { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */ |
| 36 | { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */ |
| 37 | { 0 } |
| 38 | }; |
| 39 | |
| 40 | static int ath_get_channel(struct ath_softc *sc, |
| 41 | struct ieee80211_channel *chan) |
| 42 | { |
| 43 | int i; |
| 44 | |
| 45 | for (i = 0; i < sc->sc_ah->ah_nchan; i++) { |
| 46 | if (sc->sc_ah->ah_channels[i].channel == chan->center_freq) |
| 47 | return i; |
| 48 | } |
| 49 | |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | static u32 ath_get_extchanmode(struct ath_softc *sc, |
| 54 | struct ieee80211_channel *chan) |
| 55 | { |
| 56 | u32 chanmode = 0; |
| 57 | u8 ext_chan_offset = sc->sc_ht_info.ext_chan_offset; |
| 58 | enum ath9k_ht_macmode tx_chan_width = sc->sc_ht_info.tx_chan_width; |
| 59 | |
| 60 | switch (chan->band) { |
| 61 | case IEEE80211_BAND_2GHZ: |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 62 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_NONE) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 63 | (tx_chan_width == ATH9K_HT_MACMODE_20)) |
| 64 | chanmode = CHANNEL_G_HT20; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 65 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | (tx_chan_width == ATH9K_HT_MACMODE_2040)) |
| 67 | chanmode = CHANNEL_G_HT40PLUS; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 68 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 69 | (tx_chan_width == ATH9K_HT_MACMODE_2040)) |
| 70 | chanmode = CHANNEL_G_HT40MINUS; |
| 71 | break; |
| 72 | case IEEE80211_BAND_5GHZ: |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 73 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_NONE) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 74 | (tx_chan_width == ATH9K_HT_MACMODE_20)) |
| 75 | chanmode = CHANNEL_A_HT20; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 76 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 77 | (tx_chan_width == ATH9K_HT_MACMODE_2040)) |
| 78 | chanmode = CHANNEL_A_HT40PLUS; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 79 | if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 80 | (tx_chan_width == ATH9K_HT_MACMODE_2040)) |
| 81 | chanmode = CHANNEL_A_HT40MINUS; |
| 82 | break; |
| 83 | default: |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | return chanmode; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | static int ath_setkey_tkip(struct ath_softc *sc, |
| 92 | struct ieee80211_key_conf *key, |
| 93 | struct ath9k_keyval *hk, |
| 94 | const u8 *addr) |
| 95 | { |
| 96 | u8 *key_rxmic = NULL; |
| 97 | u8 *key_txmic = NULL; |
| 98 | |
| 99 | key_txmic = key->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY; |
| 100 | key_rxmic = key->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY; |
| 101 | |
| 102 | if (addr == NULL) { |
| 103 | /* Group key installation */ |
| 104 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 105 | return ath_keyset(sc, key->keyidx, hk, addr); |
| 106 | } |
| 107 | if (!sc->sc_splitmic) { |
| 108 | /* |
| 109 | * data key goes at first index, |
| 110 | * the hal handles the MIC keys at index+64. |
| 111 | */ |
| 112 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 113 | memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic)); |
| 114 | return ath_keyset(sc, key->keyidx, hk, addr); |
| 115 | } |
| 116 | /* |
| 117 | * TX key goes at first index, RX key at +32. |
| 118 | * The hal handles the MIC keys at index+64. |
| 119 | */ |
| 120 | memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic)); |
| 121 | if (!ath_keyset(sc, key->keyidx, hk, NULL)) { |
| 122 | /* Txmic entry failed. No need to proceed further */ |
| 123 | DPRINTF(sc, ATH_DBG_KEYCACHE, |
| 124 | "%s Setting TX MIC Key Failed\n", __func__); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic)); |
| 129 | /* XXX delete tx key on failure? */ |
| 130 | return ath_keyset(sc, key->keyidx+32, hk, addr); |
| 131 | } |
| 132 | |
| 133 | static int ath_key_config(struct ath_softc *sc, |
| 134 | const u8 *addr, |
| 135 | struct ieee80211_key_conf *key) |
| 136 | { |
| 137 | struct ieee80211_vif *vif; |
| 138 | struct ath9k_keyval hk; |
| 139 | const u8 *mac = NULL; |
| 140 | int ret = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 141 | enum nl80211_iftype opmode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 142 | |
| 143 | memset(&hk, 0, sizeof(hk)); |
| 144 | |
| 145 | switch (key->alg) { |
| 146 | case ALG_WEP: |
| 147 | hk.kv_type = ATH9K_CIPHER_WEP; |
| 148 | break; |
| 149 | case ALG_TKIP: |
| 150 | hk.kv_type = ATH9K_CIPHER_TKIP; |
| 151 | break; |
| 152 | case ALG_CCMP: |
| 153 | hk.kv_type = ATH9K_CIPHER_AES_CCM; |
| 154 | break; |
| 155 | default: |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | |
| 159 | hk.kv_len = key->keylen; |
| 160 | memcpy(hk.kv_val, key->key, key->keylen); |
| 161 | |
| 162 | if (!sc->sc_vaps[0]) |
| 163 | return -EIO; |
| 164 | |
| 165 | vif = sc->sc_vaps[0]->av_if_data; |
| 166 | opmode = vif->type; |
| 167 | |
| 168 | /* |
| 169 | * Strategy: |
| 170 | * For _M_STA mc tx, we will not setup a key at all since we never |
| 171 | * tx mc. |
| 172 | * _M_STA mc rx, we will use the keyID. |
| 173 | * for _M_IBSS mc tx, we will use the keyID, and no macaddr. |
| 174 | * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the |
| 175 | * peer node. BUT we will plumb a cleartext key so that we can do |
| 176 | * perSta default key table lookup in software. |
| 177 | */ |
| 178 | if (is_broadcast_ether_addr(addr)) { |
| 179 | switch (opmode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 180 | case NL80211_IFTYPE_STATION: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 181 | /* default key: could be group WPA key |
| 182 | * or could be static WEP key */ |
| 183 | mac = NULL; |
| 184 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 185 | case NL80211_IFTYPE_ADHOC: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 186 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 187 | case NL80211_IFTYPE_AP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 188 | break; |
| 189 | default: |
| 190 | ASSERT(0); |
| 191 | break; |
| 192 | } |
| 193 | } else { |
| 194 | mac = addr; |
| 195 | } |
| 196 | |
| 197 | if (key->alg == ALG_TKIP) |
| 198 | ret = ath_setkey_tkip(sc, key, &hk, mac); |
| 199 | else |
| 200 | ret = ath_keyset(sc, key->keyidx, &hk, mac); |
| 201 | |
| 202 | if (!ret) |
| 203 | return -EIO; |
| 204 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key) |
| 209 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 210 | int freeslot; |
| 211 | |
Sujith | ff9b662 | 2008-08-14 13:27:16 +0530 | [diff] [blame] | 212 | freeslot = (key->keyidx >= 4) ? 1 : 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 213 | ath_key_reset(sc, key->keyidx, freeslot); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 216 | static void setup_ht_cap(struct ieee80211_sta_ht_cap *ht_info) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 217 | { |
Sujith | 6065367 | 2008-08-14 13:28:02 +0530 | [diff] [blame] | 218 | #define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */ |
| 219 | #define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 220 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 221 | ht_info->ht_supported = true; |
| 222 | ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 223 | IEEE80211_HT_CAP_SM_PS | |
| 224 | IEEE80211_HT_CAP_SGI_40 | |
| 225 | IEEE80211_HT_CAP_DSSSCCK40; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 226 | |
Sujith | 6065367 | 2008-08-14 13:28:02 +0530 | [diff] [blame] | 227 | ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536; |
| 228 | ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 229 | /* set up supported mcs set */ |
| 230 | memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); |
| 231 | ht_info->mcs.rx_mask[0] = 0xff; |
| 232 | ht_info->mcs.rx_mask[1] = 0xff; |
| 233 | ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static int ath_rate2idx(struct ath_softc *sc, int rate) |
| 237 | { |
| 238 | int i = 0, cur_band, n_rates; |
| 239 | struct ieee80211_hw *hw = sc->hw; |
| 240 | |
| 241 | cur_band = hw->conf.channel->band; |
| 242 | n_rates = sc->sbands[cur_band].n_bitrates; |
| 243 | |
| 244 | for (i = 0; i < n_rates; i++) { |
| 245 | if (sc->sbands[cur_band].bitrates[i].bitrate == rate) |
| 246 | break; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * NB:mac80211 validates rx rate index against the supported legacy rate |
| 251 | * index only (should be done against ht rates also), return the highest |
| 252 | * legacy rate index for rx rate which does not match any one of the |
| 253 | * supported basic and extended rates to make mac80211 happy. |
| 254 | * The following hack will be cleaned up once the issue with |
| 255 | * the rx rate index validation in mac80211 is fixed. |
| 256 | */ |
| 257 | if (i == n_rates) |
| 258 | return n_rates - 1; |
| 259 | return i; |
| 260 | } |
| 261 | |
| 262 | static void ath9k_rx_prepare(struct ath_softc *sc, |
| 263 | struct sk_buff *skb, |
| 264 | struct ath_recv_status *status, |
| 265 | struct ieee80211_rx_status *rx_status) |
| 266 | { |
| 267 | struct ieee80211_hw *hw = sc->hw; |
| 268 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 269 | |
| 270 | memset(rx_status, 0, sizeof(struct ieee80211_rx_status)); |
| 271 | |
| 272 | rx_status->mactime = status->tsf; |
| 273 | rx_status->band = curchan->band; |
| 274 | rx_status->freq = curchan->center_freq; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 275 | rx_status->noise = sc->sc_ani.sc_noise_floor; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 276 | rx_status->signal = rx_status->noise + status->rssi; |
| 277 | rx_status->rate_idx = ath_rate2idx(sc, (status->rateKbps / 100)); |
| 278 | rx_status->antenna = status->antenna; |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 279 | |
Luis R. Rodriguez | c49d154 | 2008-10-13 14:08:09 -0700 | [diff] [blame] | 280 | /* at 45 you will be able to use MCS 15 reliably. A more elaborate |
| 281 | * scheme can be used here but it requires tables of SNR/throughput for |
| 282 | * each possible mode used. */ |
| 283 | rx_status->qual = status->rssi * 100 / 45; |
| 284 | |
| 285 | /* rssi can be more than 45 though, anything above that |
| 286 | * should be considered at 100% */ |
| 287 | if (rx_status->qual > 100) |
| 288 | rx_status->qual = 100; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 289 | |
| 290 | if (status->flags & ATH_RX_MIC_ERROR) |
| 291 | rx_status->flag |= RX_FLAG_MMIC_ERROR; |
| 292 | if (status->flags & ATH_RX_FCS_ERROR) |
| 293 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 294 | |
| 295 | rx_status->flag |= RX_FLAG_TSFT; |
| 296 | } |
| 297 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 298 | static void ath9k_ht_conf(struct ath_softc *sc, |
| 299 | struct ieee80211_bss_conf *bss_conf) |
| 300 | { |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 301 | struct ath_ht_info *ht_info = &sc->sc_ht_info; |
| 302 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 303 | if (sc->hw->conf.ht.enabled) { |
| 304 | ht_info->ext_chan_offset = bss_conf->ht.secondary_channel_offset; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 305 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 306 | if (bss_conf->ht.width_40_ok) |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 307 | ht_info->tx_chan_width = ATH9K_HT_MACMODE_2040; |
| 308 | else |
| 309 | ht_info->tx_chan_width = ATH9K_HT_MACMODE_20; |
| 310 | |
| 311 | ath9k_hw_set11nmac2040(sc->sc_ah, ht_info->tx_chan_width); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 312 | } |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static void ath9k_bss_assoc_info(struct ath_softc *sc, |
| 316 | struct ieee80211_bss_conf *bss_conf) |
| 317 | { |
| 318 | struct ieee80211_hw *hw = sc->hw; |
| 319 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 320 | struct ath_vap *avp; |
| 321 | int pos; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 322 | |
| 323 | if (bss_conf->assoc) { |
| 324 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Bss Info ASSOC %d\n", |
| 325 | __func__, |
| 326 | bss_conf->aid); |
| 327 | |
| 328 | avp = sc->sc_vaps[0]; |
| 329 | if (avp == NULL) { |
| 330 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n", |
| 331 | __func__); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | /* New association, store aid */ |
| 336 | if (avp->av_opmode == ATH9K_M_STA) { |
| 337 | sc->sc_curaid = bss_conf->aid; |
| 338 | ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid, |
| 339 | sc->sc_curaid); |
| 340 | } |
| 341 | |
| 342 | /* Configure the beacon */ |
| 343 | ath_beacon_config(sc, 0); |
| 344 | sc->sc_flags |= SC_OP_BEACONS; |
| 345 | |
| 346 | /* Reset rssi stats */ |
| 347 | sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER; |
| 348 | sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER; |
| 349 | sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER; |
| 350 | sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER; |
| 351 | |
| 352 | /* Update chainmask */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 353 | ath_update_chainmask(sc, hw->conf.ht.enabled); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 354 | |
| 355 | DPRINTF(sc, ATH_DBG_CONFIG, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 356 | "%s: bssid %pM aid 0x%x\n", |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 357 | __func__, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 358 | sc->sc_curbssid, sc->sc_curaid); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 359 | |
| 360 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n", |
| 361 | __func__, |
| 362 | curchan->center_freq); |
| 363 | |
| 364 | pos = ath_get_channel(sc, curchan); |
| 365 | if (pos == -1) { |
| 366 | DPRINTF(sc, ATH_DBG_FATAL, |
| 367 | "%s: Invalid channel\n", __func__); |
| 368 | return; |
| 369 | } |
| 370 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 371 | if (hw->conf.ht.enabled) |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 372 | sc->sc_ah->ah_channels[pos].chanmode = |
| 373 | ath_get_extchanmode(sc, curchan); |
| 374 | else |
| 375 | sc->sc_ah->ah_channels[pos].chanmode = |
| 376 | (curchan->band == IEEE80211_BAND_2GHZ) ? |
| 377 | CHANNEL_G : CHANNEL_A; |
| 378 | |
| 379 | /* set h/w channel */ |
| 380 | if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0) |
| 381 | DPRINTF(sc, ATH_DBG_FATAL, |
| 382 | "%s: Unable to set channel\n", |
| 383 | __func__); |
| 384 | |
| 385 | ath_rate_newstate(sc, avp); |
| 386 | /* Update ratectrl about the new state */ |
| 387 | ath_rc_node_update(hw, avp->rc_node); |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 388 | |
| 389 | /* Start ANI */ |
| 390 | mod_timer(&sc->sc_ani.timer, |
| 391 | jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 392 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 393 | } else { |
| 394 | DPRINTF(sc, ATH_DBG_CONFIG, |
| 395 | "%s: Bss Info DISSOC\n", __func__); |
| 396 | sc->sc_curaid = 0; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | void ath_get_beaconconfig(struct ath_softc *sc, |
| 401 | int if_id, |
| 402 | struct ath_beacon_config *conf) |
| 403 | { |
| 404 | struct ieee80211_hw *hw = sc->hw; |
| 405 | |
| 406 | /* fill in beacon config data */ |
| 407 | |
| 408 | conf->beacon_interval = hw->conf.beacon_int; |
| 409 | conf->listen_interval = 100; |
| 410 | conf->dtim_count = 1; |
| 411 | conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval; |
| 412 | } |
| 413 | |
| 414 | void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 415 | struct ath_xmit_status *tx_status) |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 416 | { |
| 417 | struct ieee80211_hw *hw = sc->hw; |
| 418 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 419 | |
| 420 | DPRINTF(sc, ATH_DBG_XMIT, |
| 421 | "%s: TX complete: skb: %p\n", __func__, skb); |
| 422 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 423 | ieee80211_tx_info_clear_status(tx_info); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 424 | if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK || |
| 425 | tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) { |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 426 | /* free driver's private data area of tx_info, XXX: HACK! */ |
| 427 | if (tx_info->control.vif != NULL) |
| 428 | kfree(tx_info->control.vif); |
| 429 | tx_info->control.vif = NULL; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | if (tx_status->flags & ATH_TX_BAR) { |
| 433 | tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
| 434 | tx_status->flags &= ~ATH_TX_BAR; |
| 435 | } |
| 436 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 437 | if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) { |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 438 | /* Frame was ACKed */ |
| 439 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 440 | } |
| 441 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 442 | tx_info->status.rates[0].count = tx_status->retries + 1; |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 443 | |
| 444 | ieee80211_tx_status(hw, skb); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | int _ath_rx_indicate(struct ath_softc *sc, |
| 448 | struct sk_buff *skb, |
| 449 | struct ath_recv_status *status, |
| 450 | u16 keyix) |
| 451 | { |
| 452 | struct ieee80211_hw *hw = sc->hw; |
| 453 | struct ath_node *an = NULL; |
| 454 | struct ieee80211_rx_status rx_status; |
| 455 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 456 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 457 | int padsize; |
| 458 | enum ATH_RX_TYPE st; |
| 459 | |
| 460 | /* see if any padding is done by the hw and remove it */ |
| 461 | if (hdrlen & 3) { |
| 462 | padsize = hdrlen % 4; |
| 463 | memmove(skb->data + padsize, skb->data, hdrlen); |
| 464 | skb_pull(skb, padsize); |
| 465 | } |
| 466 | |
| 467 | /* Prepare rx status */ |
| 468 | ath9k_rx_prepare(sc, skb, status, &rx_status); |
| 469 | |
| 470 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && |
| 471 | !(status->flags & ATH_RX_DECRYPT_ERROR)) { |
| 472 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 473 | } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED) |
| 474 | && !(status->flags & ATH_RX_DECRYPT_ERROR) |
| 475 | && skb->len >= hdrlen + 4) { |
| 476 | keyix = skb->data[hdrlen + 3] >> 6; |
| 477 | |
| 478 | if (test_bit(keyix, sc->sc_keymap)) |
| 479 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 480 | } |
| 481 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 482 | if (an) { |
| 483 | ath_rx_input(sc, an, |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 484 | skb, status, &st); |
| 485 | } |
| 486 | if (!an || (st != ATH_RX_CONSUMED)) |
| 487 | __ieee80211_rx(hw, skb, &rx_status); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame^] | 492 | int ath_rx_subframe(struct ath_node *an, struct sk_buff *skb, |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 493 | struct ath_recv_status *status) |
| 494 | { |
| 495 | struct ath_softc *sc = an->an_sc; |
| 496 | struct ieee80211_hw *hw = sc->hw; |
| 497 | struct ieee80211_rx_status rx_status; |
| 498 | |
| 499 | /* Prepare rx status */ |
| 500 | ath9k_rx_prepare(sc, skb, status, &rx_status); |
| 501 | if (!(status->flags & ATH_RX_DECRYPT_ERROR)) |
| 502 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 503 | |
| 504 | __ieee80211_rx(hw, skb, &rx_status); |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | /********************************/ |
| 510 | /* LED functions */ |
| 511 | /********************************/ |
| 512 | |
| 513 | static void ath_led_brightness(struct led_classdev *led_cdev, |
| 514 | enum led_brightness brightness) |
| 515 | { |
| 516 | struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev); |
| 517 | struct ath_softc *sc = led->sc; |
| 518 | |
| 519 | switch (brightness) { |
| 520 | case LED_OFF: |
| 521 | if (led->led_type == ATH_LED_ASSOC || |
| 522 | led->led_type == ATH_LED_RADIO) |
| 523 | sc->sc_flags &= ~SC_OP_LED_ASSOCIATED; |
| 524 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, |
| 525 | (led->led_type == ATH_LED_RADIO) ? 1 : |
| 526 | !!(sc->sc_flags & SC_OP_LED_ASSOCIATED)); |
| 527 | break; |
| 528 | case LED_FULL: |
| 529 | if (led->led_type == ATH_LED_ASSOC) |
| 530 | sc->sc_flags |= SC_OP_LED_ASSOCIATED; |
| 531 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0); |
| 532 | break; |
| 533 | default: |
| 534 | break; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | static int ath_register_led(struct ath_softc *sc, struct ath_led *led, |
| 539 | char *trigger) |
| 540 | { |
| 541 | int ret; |
| 542 | |
| 543 | led->sc = sc; |
| 544 | led->led_cdev.name = led->name; |
| 545 | led->led_cdev.default_trigger = trigger; |
| 546 | led->led_cdev.brightness_set = ath_led_brightness; |
| 547 | |
| 548 | ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev); |
| 549 | if (ret) |
| 550 | DPRINTF(sc, ATH_DBG_FATAL, |
| 551 | "Failed to register led:%s", led->name); |
| 552 | else |
| 553 | led->registered = 1; |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | static void ath_unregister_led(struct ath_led *led) |
| 558 | { |
| 559 | if (led->registered) { |
| 560 | led_classdev_unregister(&led->led_cdev); |
| 561 | led->registered = 0; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | static void ath_deinit_leds(struct ath_softc *sc) |
| 566 | { |
| 567 | ath_unregister_led(&sc->assoc_led); |
| 568 | sc->sc_flags &= ~SC_OP_LED_ASSOCIATED; |
| 569 | ath_unregister_led(&sc->tx_led); |
| 570 | ath_unregister_led(&sc->rx_led); |
| 571 | ath_unregister_led(&sc->radio_led); |
| 572 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); |
| 573 | } |
| 574 | |
| 575 | static void ath_init_leds(struct ath_softc *sc) |
| 576 | { |
| 577 | char *trigger; |
| 578 | int ret; |
| 579 | |
| 580 | /* Configure gpio 1 for output */ |
| 581 | ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN, |
| 582 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 583 | /* LED off, active low */ |
| 584 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); |
| 585 | |
| 586 | trigger = ieee80211_get_radio_led_name(sc->hw); |
| 587 | snprintf(sc->radio_led.name, sizeof(sc->radio_led.name), |
| 588 | "ath9k-%s:radio", wiphy_name(sc->hw->wiphy)); |
| 589 | ret = ath_register_led(sc, &sc->radio_led, trigger); |
| 590 | sc->radio_led.led_type = ATH_LED_RADIO; |
| 591 | if (ret) |
| 592 | goto fail; |
| 593 | |
| 594 | trigger = ieee80211_get_assoc_led_name(sc->hw); |
| 595 | snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name), |
| 596 | "ath9k-%s:assoc", wiphy_name(sc->hw->wiphy)); |
| 597 | ret = ath_register_led(sc, &sc->assoc_led, trigger); |
| 598 | sc->assoc_led.led_type = ATH_LED_ASSOC; |
| 599 | if (ret) |
| 600 | goto fail; |
| 601 | |
| 602 | trigger = ieee80211_get_tx_led_name(sc->hw); |
| 603 | snprintf(sc->tx_led.name, sizeof(sc->tx_led.name), |
| 604 | "ath9k-%s:tx", wiphy_name(sc->hw->wiphy)); |
| 605 | ret = ath_register_led(sc, &sc->tx_led, trigger); |
| 606 | sc->tx_led.led_type = ATH_LED_TX; |
| 607 | if (ret) |
| 608 | goto fail; |
| 609 | |
| 610 | trigger = ieee80211_get_rx_led_name(sc->hw); |
| 611 | snprintf(sc->rx_led.name, sizeof(sc->rx_led.name), |
| 612 | "ath9k-%s:rx", wiphy_name(sc->hw->wiphy)); |
| 613 | ret = ath_register_led(sc, &sc->rx_led, trigger); |
| 614 | sc->rx_led.led_type = ATH_LED_RX; |
| 615 | if (ret) |
| 616 | goto fail; |
| 617 | |
| 618 | return; |
| 619 | |
| 620 | fail: |
| 621 | ath_deinit_leds(sc); |
| 622 | } |
| 623 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 624 | #ifdef CONFIG_RFKILL |
| 625 | /*******************/ |
| 626 | /* Rfkill */ |
| 627 | /*******************/ |
| 628 | |
| 629 | static void ath_radio_enable(struct ath_softc *sc) |
| 630 | { |
| 631 | struct ath_hal *ah = sc->sc_ah; |
| 632 | int status; |
| 633 | |
| 634 | spin_lock_bh(&sc->sc_resetlock); |
| 635 | if (!ath9k_hw_reset(ah, ah->ah_curchan, |
| 636 | sc->sc_ht_info.tx_chan_width, |
| 637 | sc->sc_tx_chainmask, |
| 638 | sc->sc_rx_chainmask, |
| 639 | sc->sc_ht_extprotspacing, |
| 640 | false, &status)) { |
| 641 | DPRINTF(sc, ATH_DBG_FATAL, |
| 642 | "%s: unable to reset channel %u (%uMhz) " |
| 643 | "flags 0x%x hal status %u\n", __func__, |
| 644 | ath9k_hw_mhz2ieee(ah, |
| 645 | ah->ah_curchan->channel, |
| 646 | ah->ah_curchan->channelFlags), |
| 647 | ah->ah_curchan->channel, |
| 648 | ah->ah_curchan->channelFlags, status); |
| 649 | } |
| 650 | spin_unlock_bh(&sc->sc_resetlock); |
| 651 | |
| 652 | ath_update_txpow(sc); |
| 653 | if (ath_startrecv(sc) != 0) { |
| 654 | DPRINTF(sc, ATH_DBG_FATAL, |
| 655 | "%s: unable to restart recv logic\n", __func__); |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | if (sc->sc_flags & SC_OP_BEACONS) |
| 660 | ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */ |
| 661 | |
| 662 | /* Re-Enable interrupts */ |
| 663 | ath9k_hw_set_interrupts(ah, sc->sc_imask); |
| 664 | |
| 665 | /* Enable LED */ |
| 666 | ath9k_hw_cfg_output(ah, ATH_LED_PIN, |
| 667 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 668 | ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0); |
| 669 | |
| 670 | ieee80211_wake_queues(sc->hw); |
| 671 | } |
| 672 | |
| 673 | static void ath_radio_disable(struct ath_softc *sc) |
| 674 | { |
| 675 | struct ath_hal *ah = sc->sc_ah; |
| 676 | int status; |
| 677 | |
| 678 | |
| 679 | ieee80211_stop_queues(sc->hw); |
| 680 | |
| 681 | /* Disable LED */ |
| 682 | ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1); |
| 683 | ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN); |
| 684 | |
| 685 | /* Disable interrupts */ |
| 686 | ath9k_hw_set_interrupts(ah, 0); |
| 687 | |
| 688 | ath_draintxq(sc, false); /* clear pending tx frames */ |
| 689 | ath_stoprecv(sc); /* turn off frame recv */ |
| 690 | ath_flushrecv(sc); /* flush recv queue */ |
| 691 | |
| 692 | spin_lock_bh(&sc->sc_resetlock); |
| 693 | if (!ath9k_hw_reset(ah, ah->ah_curchan, |
| 694 | sc->sc_ht_info.tx_chan_width, |
| 695 | sc->sc_tx_chainmask, |
| 696 | sc->sc_rx_chainmask, |
| 697 | sc->sc_ht_extprotspacing, |
| 698 | false, &status)) { |
| 699 | DPRINTF(sc, ATH_DBG_FATAL, |
| 700 | "%s: unable to reset channel %u (%uMhz) " |
| 701 | "flags 0x%x hal status %u\n", __func__, |
| 702 | ath9k_hw_mhz2ieee(ah, |
| 703 | ah->ah_curchan->channel, |
| 704 | ah->ah_curchan->channelFlags), |
| 705 | ah->ah_curchan->channel, |
| 706 | ah->ah_curchan->channelFlags, status); |
| 707 | } |
| 708 | spin_unlock_bh(&sc->sc_resetlock); |
| 709 | |
| 710 | ath9k_hw_phy_disable(ah); |
| 711 | ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); |
| 712 | } |
| 713 | |
| 714 | static bool ath_is_rfkill_set(struct ath_softc *sc) |
| 715 | { |
| 716 | struct ath_hal *ah = sc->sc_ah; |
| 717 | |
| 718 | return ath9k_hw_gpio_get(ah, ah->ah_rfkill_gpio) == |
| 719 | ah->ah_rfkill_polarity; |
| 720 | } |
| 721 | |
| 722 | /* h/w rfkill poll function */ |
| 723 | static void ath_rfkill_poll(struct work_struct *work) |
| 724 | { |
| 725 | struct ath_softc *sc = container_of(work, struct ath_softc, |
| 726 | rf_kill.rfkill_poll.work); |
| 727 | bool radio_on; |
| 728 | |
| 729 | if (sc->sc_flags & SC_OP_INVALID) |
| 730 | return; |
| 731 | |
| 732 | radio_on = !ath_is_rfkill_set(sc); |
| 733 | |
| 734 | /* |
| 735 | * enable/disable radio only when there is a |
| 736 | * state change in RF switch |
| 737 | */ |
| 738 | if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) { |
| 739 | enum rfkill_state state; |
| 740 | |
| 741 | if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) { |
| 742 | state = radio_on ? RFKILL_STATE_SOFT_BLOCKED |
| 743 | : RFKILL_STATE_HARD_BLOCKED; |
| 744 | } else if (radio_on) { |
| 745 | ath_radio_enable(sc); |
| 746 | state = RFKILL_STATE_UNBLOCKED; |
| 747 | } else { |
| 748 | ath_radio_disable(sc); |
| 749 | state = RFKILL_STATE_HARD_BLOCKED; |
| 750 | } |
| 751 | |
| 752 | if (state == RFKILL_STATE_HARD_BLOCKED) |
| 753 | sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED; |
| 754 | else |
| 755 | sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED; |
| 756 | |
| 757 | rfkill_force_state(sc->rf_kill.rfkill, state); |
| 758 | } |
| 759 | |
| 760 | queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll, |
| 761 | msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL)); |
| 762 | } |
| 763 | |
| 764 | /* s/w rfkill handler */ |
| 765 | static int ath_sw_toggle_radio(void *data, enum rfkill_state state) |
| 766 | { |
| 767 | struct ath_softc *sc = data; |
| 768 | |
| 769 | switch (state) { |
| 770 | case RFKILL_STATE_SOFT_BLOCKED: |
| 771 | if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED | |
| 772 | SC_OP_RFKILL_SW_BLOCKED))) |
| 773 | ath_radio_disable(sc); |
| 774 | sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED; |
| 775 | return 0; |
| 776 | case RFKILL_STATE_UNBLOCKED: |
| 777 | if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) { |
| 778 | sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED; |
| 779 | if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) { |
| 780 | DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the" |
| 781 | "radio as it is disabled by h/w \n"); |
| 782 | return -EPERM; |
| 783 | } |
| 784 | ath_radio_enable(sc); |
| 785 | } |
| 786 | return 0; |
| 787 | default: |
| 788 | return -EINVAL; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /* Init s/w rfkill */ |
| 793 | static int ath_init_sw_rfkill(struct ath_softc *sc) |
| 794 | { |
| 795 | sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy), |
| 796 | RFKILL_TYPE_WLAN); |
| 797 | if (!sc->rf_kill.rfkill) { |
| 798 | DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n"); |
| 799 | return -ENOMEM; |
| 800 | } |
| 801 | |
| 802 | snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name), |
| 803 | "ath9k-%s:rfkill", wiphy_name(sc->hw->wiphy)); |
| 804 | sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name; |
| 805 | sc->rf_kill.rfkill->data = sc; |
| 806 | sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio; |
| 807 | sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 808 | sc->rf_kill.rfkill->user_claim_unsupported = 1; |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | /* Deinitialize rfkill */ |
| 814 | static void ath_deinit_rfkill(struct ath_softc *sc) |
| 815 | { |
| 816 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 817 | cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); |
| 818 | |
| 819 | if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) { |
| 820 | rfkill_unregister(sc->rf_kill.rfkill); |
| 821 | sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED; |
| 822 | sc->rf_kill.rfkill = NULL; |
| 823 | } |
| 824 | } |
| 825 | #endif /* CONFIG_RFKILL */ |
| 826 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 827 | static int ath_detach(struct ath_softc *sc) |
| 828 | { |
| 829 | struct ieee80211_hw *hw = sc->hw; |
| 830 | |
| 831 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__); |
| 832 | |
| 833 | /* Deinit LED control */ |
| 834 | ath_deinit_leds(sc); |
| 835 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 836 | #ifdef CONFIG_RFKILL |
| 837 | /* deinit rfkill */ |
| 838 | ath_deinit_rfkill(sc); |
| 839 | #endif |
| 840 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 841 | /* Unregister hw */ |
| 842 | |
| 843 | ieee80211_unregister_hw(hw); |
| 844 | |
| 845 | /* unregister Rate control */ |
| 846 | ath_rate_control_unregister(); |
| 847 | |
| 848 | /* tx/rx cleanup */ |
| 849 | |
| 850 | ath_rx_cleanup(sc); |
| 851 | ath_tx_cleanup(sc); |
| 852 | |
| 853 | /* Deinit */ |
| 854 | |
| 855 | ath_deinit(sc); |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int ath_attach(u16 devid, |
| 861 | struct ath_softc *sc) |
| 862 | { |
| 863 | struct ieee80211_hw *hw = sc->hw; |
| 864 | int error = 0; |
| 865 | |
| 866 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach ATH hw\n", __func__); |
| 867 | |
| 868 | error = ath_init(devid, sc); |
| 869 | if (error != 0) |
| 870 | return error; |
| 871 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 872 | /* get mac address from hardware and set in mac80211 */ |
| 873 | |
| 874 | SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr); |
| 875 | |
| 876 | /* setup channels and rates */ |
| 877 | |
| 878 | sc->sbands[IEEE80211_BAND_2GHZ].channels = |
| 879 | sc->channels[IEEE80211_BAND_2GHZ]; |
| 880 | sc->sbands[IEEE80211_BAND_2GHZ].bitrates = |
| 881 | sc->rates[IEEE80211_BAND_2GHZ]; |
| 882 | sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ; |
| 883 | |
| 884 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) |
| 885 | /* Setup HT capabilities for 2.4Ghz*/ |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 886 | setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_cap); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 887 | |
| 888 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 889 | &sc->sbands[IEEE80211_BAND_2GHZ]; |
| 890 | |
| 891 | if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) { |
| 892 | sc->sbands[IEEE80211_BAND_5GHZ].channels = |
| 893 | sc->channels[IEEE80211_BAND_5GHZ]; |
| 894 | sc->sbands[IEEE80211_BAND_5GHZ].bitrates = |
| 895 | sc->rates[IEEE80211_BAND_5GHZ]; |
| 896 | sc->sbands[IEEE80211_BAND_5GHZ].band = |
| 897 | IEEE80211_BAND_5GHZ; |
| 898 | |
| 899 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) |
| 900 | /* Setup HT capabilities for 5Ghz*/ |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 901 | setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_cap); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 902 | |
| 903 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 904 | &sc->sbands[IEEE80211_BAND_5GHZ]; |
| 905 | } |
| 906 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 907 | hw->queues = 4; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 908 | hw->sta_data_size = sizeof(struct ath_node); |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 909 | |
| 910 | /* Register rate control */ |
| 911 | hw->rate_control_algorithm = "ath9k_rate_control"; |
| 912 | error = ath_rate_control_register(); |
| 913 | if (error != 0) { |
| 914 | DPRINTF(sc, ATH_DBG_FATAL, |
| 915 | "%s: Unable to register rate control " |
| 916 | "algorithm:%d\n", __func__, error); |
| 917 | ath_rate_control_unregister(); |
| 918 | goto bad; |
| 919 | } |
| 920 | |
| 921 | error = ieee80211_register_hw(hw); |
| 922 | if (error != 0) { |
| 923 | ath_rate_control_unregister(); |
| 924 | goto bad; |
| 925 | } |
| 926 | |
| 927 | /* Initialize LED control */ |
| 928 | ath_init_leds(sc); |
| 929 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 930 | #ifdef CONFIG_RFKILL |
| 931 | /* Initialze h/w Rfkill */ |
| 932 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 933 | INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll); |
| 934 | |
| 935 | /* Initialize s/w rfkill */ |
| 936 | if (ath_init_sw_rfkill(sc)) |
| 937 | goto detach; |
| 938 | #endif |
| 939 | |
Vasanthakumar Thiagarajan | 8feceb6 | 2008-09-10 18:49:27 +0530 | [diff] [blame] | 940 | /* initialize tx/rx engine */ |
| 941 | |
| 942 | error = ath_tx_init(sc, ATH_TXBUF); |
| 943 | if (error != 0) |
| 944 | goto detach; |
| 945 | |
| 946 | error = ath_rx_init(sc, ATH_RXBUF); |
| 947 | if (error != 0) |
| 948 | goto detach; |
| 949 | |
| 950 | return 0; |
| 951 | detach: |
| 952 | ath_detach(sc); |
| 953 | bad: |
| 954 | return error; |
| 955 | } |
| 956 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 957 | static int ath9k_start(struct ieee80211_hw *hw) |
| 958 | { |
| 959 | struct ath_softc *sc = hw->priv; |
| 960 | struct ieee80211_channel *curchan = hw->conf.channel; |
| 961 | int error = 0, pos; |
| 962 | |
| 963 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with " |
| 964 | "initial channel: %d MHz\n", __func__, curchan->center_freq); |
| 965 | |
| 966 | /* setup initial channel */ |
| 967 | |
| 968 | pos = ath_get_channel(sc, curchan); |
| 969 | if (pos == -1) { |
| 970 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__); |
| 971 | return -EINVAL; |
| 972 | } |
| 973 | |
| 974 | sc->sc_ah->ah_channels[pos].chanmode = |
| 975 | (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A; |
| 976 | |
| 977 | /* open ath_dev */ |
| 978 | error = ath_open(sc, &sc->sc_ah->ah_channels[pos]); |
| 979 | if (error) { |
| 980 | DPRINTF(sc, ATH_DBG_FATAL, |
| 981 | "%s: Unable to complete ath_open\n", __func__); |
| 982 | return error; |
| 983 | } |
| 984 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 985 | #ifdef CONFIG_RFKILL |
| 986 | /* Start rfkill polling */ |
| 987 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 988 | queue_delayed_work(sc->hw->workqueue, |
| 989 | &sc->rf_kill.rfkill_poll, 0); |
| 990 | |
| 991 | if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) { |
| 992 | if (rfkill_register(sc->rf_kill.rfkill)) { |
| 993 | DPRINTF(sc, ATH_DBG_FATAL, |
| 994 | "Unable to register rfkill\n"); |
| 995 | rfkill_free(sc->rf_kill.rfkill); |
| 996 | |
| 997 | /* Deinitialize the device */ |
| 998 | if (sc->pdev->irq) |
| 999 | free_irq(sc->pdev->irq, sc); |
| 1000 | ath_detach(sc); |
| 1001 | pci_iounmap(sc->pdev, sc->mem); |
| 1002 | pci_release_region(sc->pdev, 0); |
| 1003 | pci_disable_device(sc->pdev); |
| 1004 | ieee80211_free_hw(hw); |
| 1005 | return -EIO; |
| 1006 | } else { |
| 1007 | sc->sc_flags |= SC_OP_RFKILL_REGISTERED; |
| 1008 | } |
| 1009 | } |
| 1010 | #endif |
| 1011 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1012 | ieee80211_wake_queues(hw); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static int ath9k_tx(struct ieee80211_hw *hw, |
| 1017 | struct sk_buff *skb) |
| 1018 | { |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1019 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1020 | struct ath_softc *sc = hw->priv; |
| 1021 | struct ath_tx_control txctl; |
| 1022 | int hdrlen, padsize; |
| 1023 | |
| 1024 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 1025 | |
| 1026 | /* |
| 1027 | * As a temporary workaround, assign seq# here; this will likely need |
| 1028 | * to be cleaned up to work better with Beacon transmission and virtual |
| 1029 | * BSSes. |
| 1030 | */ |
| 1031 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 1032 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 1033 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
| 1034 | sc->seq_no += 0x10; |
| 1035 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 1036 | hdr->seq_ctrl |= cpu_to_le16(sc->seq_no); |
| 1037 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1038 | |
| 1039 | /* Add the padding after the header if this is not already done */ |
| 1040 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 1041 | if (hdrlen & 3) { |
| 1042 | padsize = hdrlen % 4; |
| 1043 | if (skb_headroom(skb) < padsize) |
| 1044 | return -1; |
| 1045 | skb_push(skb, padsize); |
| 1046 | memmove(skb->data, skb->data + padsize, hdrlen); |
| 1047 | } |
| 1048 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1049 | /* Check if a tx queue is available */ |
| 1050 | |
| 1051 | txctl.txq = ath_test_get_txq(sc, skb); |
| 1052 | if (!txctl.txq) |
| 1053 | goto exit; |
| 1054 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1055 | DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n", |
| 1056 | __func__, |
| 1057 | skb); |
| 1058 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1059 | if (ath_tx_start(sc, skb, &txctl) != 0) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1060 | DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1061 | goto exit; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | return 0; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1065 | exit: |
| 1066 | dev_kfree_skb_any(skb); |
| 1067 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static void ath9k_stop(struct ieee80211_hw *hw) |
| 1071 | { |
| 1072 | struct ath_softc *sc = hw->priv; |
| 1073 | int error; |
| 1074 | |
| 1075 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__); |
| 1076 | |
| 1077 | error = ath_suspend(sc); |
| 1078 | if (error) |
| 1079 | DPRINTF(sc, ATH_DBG_CONFIG, |
| 1080 | "%s: Device is no longer present\n", __func__); |
| 1081 | |
| 1082 | ieee80211_stop_queues(hw); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1083 | |
| 1084 | #ifdef CONFIG_RFKILL |
| 1085 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 1086 | cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); |
| 1087 | #endif |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
| 1091 | struct ieee80211_if_init_conf *conf) |
| 1092 | { |
| 1093 | struct ath_softc *sc = hw->priv; |
| 1094 | int error, ic_opmode = 0; |
| 1095 | |
| 1096 | /* Support only vap for now */ |
| 1097 | |
| 1098 | if (sc->sc_nvaps) |
| 1099 | return -ENOBUFS; |
| 1100 | |
| 1101 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1102 | case NL80211_IFTYPE_STATION: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1103 | ic_opmode = ATH9K_M_STA; |
| 1104 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1105 | case NL80211_IFTYPE_ADHOC: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1106 | ic_opmode = ATH9K_M_IBSS; |
| 1107 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1108 | case NL80211_IFTYPE_AP: |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1109 | ic_opmode = ATH9K_M_HOSTAP; |
| 1110 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1111 | default: |
| 1112 | DPRINTF(sc, ATH_DBG_FATAL, |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1113 | "%s: Interface type %d not yet supported\n", |
| 1114 | __func__, conf->type); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1115 | return -EOPNOTSUPP; |
| 1116 | } |
| 1117 | |
| 1118 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a VAP of type: %d\n", |
| 1119 | __func__, |
| 1120 | ic_opmode); |
| 1121 | |
| 1122 | error = ath_vap_attach(sc, 0, conf->vif, ic_opmode); |
| 1123 | if (error) { |
| 1124 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1125 | "%s: Unable to attach vap, error: %d\n", |
| 1126 | __func__, error); |
| 1127 | return error; |
| 1128 | } |
| 1129 | |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 1130 | if (conf->type == NL80211_IFTYPE_AP) { |
| 1131 | /* TODO: is this a suitable place to start ANI for AP mode? */ |
| 1132 | /* Start ANI */ |
| 1133 | mod_timer(&sc->sc_ani.timer, |
| 1134 | jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL)); |
| 1135 | } |
| 1136 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
| 1141 | struct ieee80211_if_init_conf *conf) |
| 1142 | { |
| 1143 | struct ath_softc *sc = hw->priv; |
| 1144 | struct ath_vap *avp; |
| 1145 | int error; |
| 1146 | |
| 1147 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__); |
| 1148 | |
| 1149 | avp = sc->sc_vaps[0]; |
| 1150 | if (avp == NULL) { |
| 1151 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n", |
| 1152 | __func__); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | #ifdef CONFIG_SLOW_ANT_DIV |
| 1157 | ath_slow_ant_div_stop(&sc->sc_antdiv); |
| 1158 | #endif |
Luis R. Rodriguez | 6f25542 | 2008-10-03 15:45:27 -0700 | [diff] [blame] | 1159 | /* Stop ANI */ |
| 1160 | del_timer_sync(&sc->sc_ani.timer); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1161 | |
| 1162 | /* Update ratectrl */ |
| 1163 | ath_rate_newstate(sc, avp); |
| 1164 | |
| 1165 | /* Reclaim beacon resources */ |
Sujith | b4696c8b | 2008-08-11 14:04:52 +0530 | [diff] [blame] | 1166 | if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP || |
| 1167 | sc->sc_ah->ah_opmode == ATH9K_M_IBSS) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1168 | ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq); |
| 1169 | ath_beacon_return(sc, avp); |
| 1170 | } |
| 1171 | |
| 1172 | /* Set interrupt mask */ |
| 1173 | sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); |
| 1174 | ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL); |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1175 | sc->sc_flags &= ~SC_OP_BEACONS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1176 | |
| 1177 | error = ath_vap_detach(sc, 0); |
| 1178 | if (error) |
| 1179 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1180 | "%s: Unable to detach vap, error: %d\n", |
| 1181 | __func__, error); |
| 1182 | } |
| 1183 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1184 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1185 | { |
| 1186 | struct ath_softc *sc = hw->priv; |
| 1187 | struct ieee80211_channel *curchan = hw->conf.channel; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1188 | struct ieee80211_conf *conf = &hw->conf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1189 | int pos; |
| 1190 | |
| 1191 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n", |
| 1192 | __func__, |
| 1193 | curchan->center_freq); |
| 1194 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1195 | /* Update chainmask */ |
| 1196 | ath_update_chainmask(sc, conf->ht.enabled); |
| 1197 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1198 | pos = ath_get_channel(sc, curchan); |
| 1199 | if (pos == -1) { |
| 1200 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__); |
| 1201 | return -EINVAL; |
| 1202 | } |
| 1203 | |
| 1204 | sc->sc_ah->ah_channels[pos].chanmode = |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 1205 | (curchan->band == IEEE80211_BAND_2GHZ) ? |
| 1206 | CHANNEL_G : CHANNEL_A; |
| 1207 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1208 | if (sc->sc_curaid && hw->conf.ht.enabled) |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 1209 | sc->sc_ah->ah_channels[pos].chanmode = |
| 1210 | ath_get_extchanmode(sc, curchan); |
| 1211 | |
Luis R. Rodriguez | 5c020dc | 2008-10-22 13:28:45 -0700 | [diff] [blame] | 1212 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 1213 | sc->sc_config.txpowlimit = 2 * conf->power_level; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1214 | |
| 1215 | /* set h/w channel */ |
| 1216 | if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0) |
| 1217 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Unable to set channel\n", |
| 1218 | __func__); |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static int ath9k_config_interface(struct ieee80211_hw *hw, |
| 1224 | struct ieee80211_vif *vif, |
| 1225 | struct ieee80211_if_conf *conf) |
| 1226 | { |
| 1227 | struct ath_softc *sc = hw->priv; |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1228 | struct ath_hal *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1229 | struct ath_vap *avp; |
| 1230 | u32 rfilt = 0; |
| 1231 | int error, i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1232 | |
| 1233 | avp = sc->sc_vaps[0]; |
| 1234 | if (avp == NULL) { |
| 1235 | DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n", |
| 1236 | __func__); |
| 1237 | return -EINVAL; |
| 1238 | } |
| 1239 | |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1240 | /* TODO: Need to decide which hw opmode to use for multi-interface |
| 1241 | * cases */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1242 | if (vif->type == NL80211_IFTYPE_AP && |
Jouni Malinen | 2ad67de | 2008-08-11 14:01:47 +0300 | [diff] [blame] | 1243 | ah->ah_opmode != ATH9K_M_HOSTAP) { |
| 1244 | ah->ah_opmode = ATH9K_M_HOSTAP; |
| 1245 | ath9k_hw_setopmode(ah); |
| 1246 | ath9k_hw_write_associd(ah, sc->sc_myaddr, 0); |
| 1247 | /* Request full reset to get hw opmode changed properly */ |
| 1248 | sc->sc_flags |= SC_OP_FULL_RESET; |
| 1249 | } |
| 1250 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1251 | if ((conf->changed & IEEE80211_IFCC_BSSID) && |
| 1252 | !is_zero_ether_addr(conf->bssid)) { |
| 1253 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1254 | case NL80211_IFTYPE_STATION: |
| 1255 | case NL80211_IFTYPE_ADHOC: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1256 | /* Update ratectrl about the new state */ |
| 1257 | ath_rate_newstate(sc, avp); |
| 1258 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1259 | /* Set BSSID */ |
| 1260 | memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN); |
| 1261 | sc->sc_curaid = 0; |
| 1262 | ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid, |
| 1263 | sc->sc_curaid); |
| 1264 | |
| 1265 | /* Set aggregation protection mode parameters */ |
| 1266 | sc->sc_config.ath_aggr_prot = 0; |
| 1267 | |
| 1268 | /* |
| 1269 | * Reset our TSF so that its value is lower than the |
| 1270 | * beacon that we are trying to catch. |
| 1271 | * Only then hw will update its TSF register with the |
| 1272 | * new beacon. Reset the TSF before setting the BSSID |
| 1273 | * to avoid allowing in any frames that would update |
| 1274 | * our TSF only to have us clear it |
| 1275 | * immediately thereafter. |
| 1276 | */ |
| 1277 | ath9k_hw_reset_tsf(sc->sc_ah); |
| 1278 | |
| 1279 | /* Disable BMISS interrupt when we're not associated */ |
| 1280 | ath9k_hw_set_interrupts(sc->sc_ah, |
| 1281 | sc->sc_imask & |
| 1282 | ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS)); |
| 1283 | sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS); |
| 1284 | |
| 1285 | DPRINTF(sc, ATH_DBG_CONFIG, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1286 | "%s: RX filter 0x%x bssid %pM aid 0x%x\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1287 | __func__, rfilt, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1288 | sc->sc_curbssid, sc->sc_curaid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1289 | |
| 1290 | /* need to reconfigure the beacon */ |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1291 | sc->sc_flags &= ~SC_OP_BEACONS ; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1292 | |
| 1293 | break; |
| 1294 | default: |
| 1295 | break; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | if ((conf->changed & IEEE80211_IFCC_BEACON) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1300 | ((vif->type == NL80211_IFTYPE_ADHOC) || |
| 1301 | (vif->type == NL80211_IFTYPE_AP))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1302 | /* |
| 1303 | * Allocate and setup the beacon frame. |
| 1304 | * |
| 1305 | * Stop any previous beacon DMA. This may be |
| 1306 | * necessary, for example, when an ibss merge |
| 1307 | * causes reconfiguration; we may be called |
| 1308 | * with beacon transmission active. |
| 1309 | */ |
| 1310 | ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq); |
| 1311 | |
| 1312 | error = ath_beacon_alloc(sc, 0); |
| 1313 | if (error != 0) |
| 1314 | return error; |
| 1315 | |
| 1316 | ath_beacon_sync(sc, 0); |
| 1317 | } |
| 1318 | |
| 1319 | /* Check for WLAN_CAPABILITY_PRIVACY ? */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1320 | if ((avp->av_opmode != NL80211_IFTYPE_STATION)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1321 | for (i = 0; i < IEEE80211_WEP_NKID; i++) |
| 1322 | if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i)) |
| 1323 | ath9k_hw_keysetmac(sc->sc_ah, |
| 1324 | (u16)i, |
| 1325 | sc->sc_curbssid); |
| 1326 | } |
| 1327 | |
| 1328 | /* Only legacy IBSS for now */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1329 | if (vif->type == NL80211_IFTYPE_ADHOC) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1330 | ath_update_chainmask(sc, 0); |
| 1331 | |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | #define SUPPORTED_FILTERS \ |
| 1336 | (FIF_PROMISC_IN_BSS | \ |
| 1337 | FIF_ALLMULTI | \ |
| 1338 | FIF_CONTROL | \ |
| 1339 | FIF_OTHER_BSS | \ |
| 1340 | FIF_BCN_PRBRESP_PROMISC | \ |
| 1341 | FIF_FCSFAIL) |
| 1342 | |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1343 | /* FIXME: sc->sc_full_reset ? */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1344 | static void ath9k_configure_filter(struct ieee80211_hw *hw, |
| 1345 | unsigned int changed_flags, |
| 1346 | unsigned int *total_flags, |
| 1347 | int mc_count, |
| 1348 | struct dev_mc_list *mclist) |
| 1349 | { |
| 1350 | struct ath_softc *sc = hw->priv; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1351 | u32 rfilt; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1352 | |
| 1353 | changed_flags &= SUPPORTED_FILTERS; |
| 1354 | *total_flags &= SUPPORTED_FILTERS; |
| 1355 | |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1356 | sc->rx_filter = *total_flags; |
| 1357 | rfilt = ath_calcrxfilter(sc); |
| 1358 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); |
| 1359 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1360 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 1361 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1362 | ath9k_hw_write_associd(sc->sc_ah, ath_bcast_mac, 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1363 | } |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1364 | |
| 1365 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set HW RX filter: 0x%x\n", |
| 1366 | __func__, sc->rx_filter); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1369 | /* Only a single interface is currently supported, |
| 1370 | so pass 0 as the interface id to ath_node_attach */ |
| 1371 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1372 | static void ath9k_sta_notify(struct ieee80211_hw *hw, |
| 1373 | struct ieee80211_vif *vif, |
| 1374 | enum sta_notify_cmd cmd, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1375 | struct ieee80211_sta *sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1376 | { |
| 1377 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1378 | |
| 1379 | switch (cmd) { |
| 1380 | case STA_NOTIFY_ADD: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1381 | ath_node_attach(sc, sta, 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1382 | break; |
| 1383 | case STA_NOTIFY_REMOVE: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1384 | ath_node_detach(sc, sta); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1385 | break; |
| 1386 | default: |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static int ath9k_conf_tx(struct ieee80211_hw *hw, |
| 1392 | u16 queue, |
| 1393 | const struct ieee80211_tx_queue_params *params) |
| 1394 | { |
| 1395 | struct ath_softc *sc = hw->priv; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 1396 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1397 | int ret = 0, qnum; |
| 1398 | |
| 1399 | if (queue >= WME_NUM_AC) |
| 1400 | return 0; |
| 1401 | |
| 1402 | qi.tqi_aifs = params->aifs; |
| 1403 | qi.tqi_cwmin = params->cw_min; |
| 1404 | qi.tqi_cwmax = params->cw_max; |
| 1405 | qi.tqi_burstTime = params->txop; |
| 1406 | qnum = ath_get_hal_qnum(queue, sc); |
| 1407 | |
| 1408 | DPRINTF(sc, ATH_DBG_CONFIG, |
| 1409 | "%s: Configure tx [queue/halq] [%d/%d], " |
| 1410 | "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1411 | __func__, |
| 1412 | queue, |
| 1413 | qnum, |
| 1414 | params->aifs, |
| 1415 | params->cw_min, |
| 1416 | params->cw_max, |
| 1417 | params->txop); |
| 1418 | |
| 1419 | ret = ath_txq_update(sc, qnum, &qi); |
| 1420 | if (ret) |
| 1421 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1422 | "%s: TXQ Update failed\n", __func__); |
| 1423 | |
| 1424 | return ret; |
| 1425 | } |
| 1426 | |
| 1427 | static int ath9k_set_key(struct ieee80211_hw *hw, |
| 1428 | enum set_key_cmd cmd, |
| 1429 | const u8 *local_addr, |
| 1430 | const u8 *addr, |
| 1431 | struct ieee80211_key_conf *key) |
| 1432 | { |
| 1433 | struct ath_softc *sc = hw->priv; |
| 1434 | int ret = 0; |
| 1435 | |
| 1436 | DPRINTF(sc, ATH_DBG_KEYCACHE, " %s: Set HW Key\n", __func__); |
| 1437 | |
| 1438 | switch (cmd) { |
| 1439 | case SET_KEY: |
| 1440 | ret = ath_key_config(sc, addr, key); |
| 1441 | if (!ret) { |
| 1442 | set_bit(key->keyidx, sc->sc_keymap); |
| 1443 | key->hw_key_idx = key->keyidx; |
| 1444 | /* push IV and Michael MIC generation to stack */ |
| 1445 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Senthil Balasubramanian | 1b96175 | 2008-09-01 19:45:21 +0530 | [diff] [blame] | 1446 | if (key->alg == ALG_TKIP) |
| 1447 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1448 | } |
| 1449 | break; |
| 1450 | case DISABLE_KEY: |
| 1451 | ath_key_delete(sc, key); |
| 1452 | clear_bit(key->keyidx, sc->sc_keymap); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1453 | break; |
| 1454 | default: |
| 1455 | ret = -EINVAL; |
| 1456 | } |
| 1457 | |
| 1458 | return ret; |
| 1459 | } |
| 1460 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1461 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
| 1462 | struct ieee80211_vif *vif, |
| 1463 | struct ieee80211_bss_conf *bss_conf, |
| 1464 | u32 changed) |
| 1465 | { |
| 1466 | struct ath_softc *sc = hw->priv; |
| 1467 | |
| 1468 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 1469 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed PREAMBLE %d\n", |
| 1470 | __func__, |
| 1471 | bss_conf->use_short_preamble); |
| 1472 | if (bss_conf->use_short_preamble) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1473 | sc->sc_flags |= SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1474 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1475 | sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 1479 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed CTS PROT %d\n", |
| 1480 | __func__, |
| 1481 | bss_conf->use_cts_prot); |
| 1482 | if (bss_conf->use_cts_prot && |
| 1483 | hw->conf.channel->band != IEEE80211_BAND_5GHZ) |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1484 | sc->sc_flags |= SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1485 | else |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1486 | sc->sc_flags &= ~SC_OP_PROTECT_ENABLE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | if (changed & BSS_CHANGED_HT) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1490 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed HT\n", |
| 1491 | __func__); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1492 | ath9k_ht_conf(sc, bss_conf); |
| 1493 | } |
| 1494 | |
| 1495 | if (changed & BSS_CHANGED_ASSOC) { |
| 1496 | DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n", |
| 1497 | __func__, |
| 1498 | bss_conf->assoc); |
| 1499 | ath9k_bss_assoc_info(sc, bss_conf); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw) |
| 1504 | { |
| 1505 | u64 tsf; |
| 1506 | struct ath_softc *sc = hw->priv; |
| 1507 | struct ath_hal *ah = sc->sc_ah; |
| 1508 | |
| 1509 | tsf = ath9k_hw_gettsf64(ah); |
| 1510 | |
| 1511 | return tsf; |
| 1512 | } |
| 1513 | |
| 1514 | static void ath9k_reset_tsf(struct ieee80211_hw *hw) |
| 1515 | { |
| 1516 | struct ath_softc *sc = hw->priv; |
| 1517 | struct ath_hal *ah = sc->sc_ah; |
| 1518 | |
| 1519 | ath9k_hw_reset_tsf(ah); |
| 1520 | } |
| 1521 | |
| 1522 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
| 1523 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1524 | struct ieee80211_sta *sta, |
| 1525 | u16 tid, u16 *ssn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1526 | { |
| 1527 | struct ath_softc *sc = hw->priv; |
| 1528 | int ret = 0; |
| 1529 | |
| 1530 | switch (action) { |
| 1531 | case IEEE80211_AMPDU_RX_START: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1532 | ret = ath_rx_aggr_start(sc, sta, tid, ssn); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1533 | if (ret < 0) |
| 1534 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1535 | "%s: Unable to start RX aggregation\n", |
| 1536 | __func__); |
| 1537 | break; |
| 1538 | case IEEE80211_AMPDU_RX_STOP: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1539 | ret = ath_rx_aggr_stop(sc, sta, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1540 | if (ret < 0) |
| 1541 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1542 | "%s: Unable to stop RX aggregation\n", |
| 1543 | __func__); |
| 1544 | break; |
| 1545 | case IEEE80211_AMPDU_TX_START: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1546 | ret = ath_tx_aggr_start(sc, sta, tid, ssn); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1547 | if (ret < 0) |
| 1548 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1549 | "%s: Unable to start TX aggregation\n", |
| 1550 | __func__); |
| 1551 | else |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1552 | ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1553 | break; |
| 1554 | case IEEE80211_AMPDU_TX_STOP: |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1555 | ret = ath_tx_aggr_stop(sc, sta, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1556 | if (ret < 0) |
| 1557 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1558 | "%s: Unable to stop TX aggregation\n", |
| 1559 | __func__); |
| 1560 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1561 | ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | default: |
| 1564 | DPRINTF(sc, ATH_DBG_FATAL, |
| 1565 | "%s: Unknown AMPDU action\n", __func__); |
| 1566 | } |
| 1567 | |
| 1568 | return ret; |
| 1569 | } |
| 1570 | |
Johannes Berg | 4233df6 | 2008-10-13 13:35:05 +0200 | [diff] [blame] | 1571 | static int ath9k_no_fragmentation(struct ieee80211_hw *hw, u32 value) |
| 1572 | { |
| 1573 | return -EOPNOTSUPP; |
| 1574 | } |
| 1575 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1576 | static struct ieee80211_ops ath9k_ops = { |
| 1577 | .tx = ath9k_tx, |
| 1578 | .start = ath9k_start, |
| 1579 | .stop = ath9k_stop, |
| 1580 | .add_interface = ath9k_add_interface, |
| 1581 | .remove_interface = ath9k_remove_interface, |
| 1582 | .config = ath9k_config, |
| 1583 | .config_interface = ath9k_config_interface, |
| 1584 | .configure_filter = ath9k_configure_filter, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1585 | .sta_notify = ath9k_sta_notify, |
| 1586 | .conf_tx = ath9k_conf_tx, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1587 | .bss_info_changed = ath9k_bss_info_changed, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1588 | .set_key = ath9k_set_key, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1589 | .get_tsf = ath9k_get_tsf, |
| 1590 | .reset_tsf = ath9k_reset_tsf, |
Johannes Berg | 4233df6 | 2008-10-13 13:35:05 +0200 | [diff] [blame] | 1591 | .ampdu_action = ath9k_ampdu_action, |
| 1592 | .set_frag_threshold = ath9k_no_fragmentation, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1593 | }; |
| 1594 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1595 | static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 1596 | { |
| 1597 | void __iomem *mem; |
| 1598 | struct ath_softc *sc; |
| 1599 | struct ieee80211_hw *hw; |
| 1600 | const char *athname; |
| 1601 | u8 csz; |
| 1602 | u32 val; |
| 1603 | int ret = 0; |
| 1604 | |
| 1605 | if (pci_enable_device(pdev)) |
| 1606 | return -EIO; |
| 1607 | |
| 1608 | /* XXX 32-bit addressing only */ |
| 1609 | if (pci_set_dma_mask(pdev, 0xffffffff)) { |
| 1610 | printk(KERN_ERR "ath_pci: 32-bit DMA not available\n"); |
| 1611 | ret = -ENODEV; |
| 1612 | goto bad; |
| 1613 | } |
| 1614 | |
| 1615 | /* |
| 1616 | * Cache line size is used to size and align various |
| 1617 | * structures used to communicate with the hardware. |
| 1618 | */ |
| 1619 | pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz); |
| 1620 | if (csz == 0) { |
| 1621 | /* |
| 1622 | * Linux 2.4.18 (at least) writes the cache line size |
| 1623 | * register as a 16-bit wide register which is wrong. |
| 1624 | * We must have this setup properly for rx buffer |
| 1625 | * DMA to work so force a reasonable value here if it |
| 1626 | * comes up zero. |
| 1627 | */ |
| 1628 | csz = L1_CACHE_BYTES / sizeof(u32); |
| 1629 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz); |
| 1630 | } |
| 1631 | /* |
| 1632 | * The default setting of latency timer yields poor results, |
| 1633 | * set it to the value used by other systems. It may be worth |
| 1634 | * tweaking this setting more. |
| 1635 | */ |
| 1636 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8); |
| 1637 | |
| 1638 | pci_set_master(pdev); |
| 1639 | |
| 1640 | /* |
| 1641 | * Disable the RETRY_TIMEOUT register (0x41) to keep |
| 1642 | * PCI Tx retries from interfering with C3 CPU state. |
| 1643 | */ |
| 1644 | pci_read_config_dword(pdev, 0x40, &val); |
| 1645 | if ((val & 0x0000ff00) != 0) |
| 1646 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 1647 | |
| 1648 | ret = pci_request_region(pdev, 0, "ath9k"); |
| 1649 | if (ret) { |
| 1650 | dev_err(&pdev->dev, "PCI memory region reserve error\n"); |
| 1651 | ret = -ENODEV; |
| 1652 | goto bad; |
| 1653 | } |
| 1654 | |
| 1655 | mem = pci_iomap(pdev, 0, 0); |
| 1656 | if (!mem) { |
| 1657 | printk(KERN_ERR "PCI memory map error\n") ; |
| 1658 | ret = -EIO; |
| 1659 | goto bad1; |
| 1660 | } |
| 1661 | |
| 1662 | hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops); |
| 1663 | if (hw == NULL) { |
| 1664 | printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n"); |
| 1665 | goto bad2; |
| 1666 | } |
| 1667 | |
Sujith | 19b73c7 | 2008-08-14 13:28:20 +0530 | [diff] [blame] | 1668 | hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 1669 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
Sujith | 19b73c7 | 2008-08-14 13:28:20 +0530 | [diff] [blame] | 1670 | IEEE80211_HW_SIGNAL_DBM | |
Sujith | 8b30b1f | 2008-10-24 09:55:27 +0530 | [diff] [blame] | 1671 | IEEE80211_HW_NOISE_DBM | |
| 1672 | IEEE80211_HW_AMPDU_AGGREGATION; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1673 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1674 | hw->wiphy->interface_modes = |
| 1675 | BIT(NL80211_IFTYPE_AP) | |
| 1676 | BIT(NL80211_IFTYPE_STATION) | |
| 1677 | BIT(NL80211_IFTYPE_ADHOC); |
| 1678 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1679 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 1680 | pci_set_drvdata(pdev, hw); |
| 1681 | |
| 1682 | sc = hw->priv; |
| 1683 | sc->hw = hw; |
| 1684 | sc->pdev = pdev; |
| 1685 | sc->mem = mem; |
| 1686 | |
| 1687 | if (ath_attach(id->device, sc) != 0) { |
| 1688 | ret = -ENODEV; |
| 1689 | goto bad3; |
| 1690 | } |
| 1691 | |
| 1692 | /* setup interrupt service routine */ |
| 1693 | |
| 1694 | if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) { |
| 1695 | printk(KERN_ERR "%s: request_irq failed\n", |
| 1696 | wiphy_name(hw->wiphy)); |
| 1697 | ret = -EIO; |
| 1698 | goto bad4; |
| 1699 | } |
| 1700 | |
| 1701 | athname = ath9k_hw_probe(id->vendor, id->device); |
| 1702 | |
| 1703 | printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n", |
| 1704 | wiphy_name(hw->wiphy), |
| 1705 | athname ? athname : "Atheros ???", |
| 1706 | (unsigned long)mem, pdev->irq); |
| 1707 | |
| 1708 | return 0; |
| 1709 | bad4: |
| 1710 | ath_detach(sc); |
| 1711 | bad3: |
| 1712 | ieee80211_free_hw(hw); |
| 1713 | bad2: |
| 1714 | pci_iounmap(pdev, mem); |
| 1715 | bad1: |
| 1716 | pci_release_region(pdev, 0); |
| 1717 | bad: |
| 1718 | pci_disable_device(pdev); |
| 1719 | return ret; |
| 1720 | } |
| 1721 | |
| 1722 | static void ath_pci_remove(struct pci_dev *pdev) |
| 1723 | { |
| 1724 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 1725 | struct ath_softc *sc = hw->priv; |
Senthil Balasubramanian | 6115e85 | 2008-09-22 14:22:39 +0530 | [diff] [blame] | 1726 | enum ath9k_int status; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1727 | |
Senthil Balasubramanian | 6115e85 | 2008-09-22 14:22:39 +0530 | [diff] [blame] | 1728 | if (pdev->irq) { |
| 1729 | ath9k_hw_set_interrupts(sc->sc_ah, 0); |
| 1730 | /* clear the ISR */ |
| 1731 | ath9k_hw_getisr(sc->sc_ah, &status); |
David S. Miller | b262e60 | 2008-10-01 06:12:56 -0700 | [diff] [blame] | 1732 | sc->sc_flags |= SC_OP_INVALID; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1733 | free_irq(pdev->irq, sc); |
Senthil Balasubramanian | 6115e85 | 2008-09-22 14:22:39 +0530 | [diff] [blame] | 1734 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1735 | ath_detach(sc); |
Senthil Balasubramanian | 6115e85 | 2008-09-22 14:22:39 +0530 | [diff] [blame] | 1736 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1737 | pci_iounmap(pdev, sc->mem); |
| 1738 | pci_release_region(pdev, 0); |
| 1739 | pci_disable_device(pdev); |
| 1740 | ieee80211_free_hw(hw); |
| 1741 | } |
| 1742 | |
| 1743 | #ifdef CONFIG_PM |
| 1744 | |
| 1745 | static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1746 | { |
Vasanthakumar Thiagarajan | c83be68 | 2008-08-25 20:47:29 +0530 | [diff] [blame] | 1747 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 1748 | struct ath_softc *sc = hw->priv; |
| 1749 | |
| 1750 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1751 | |
| 1752 | #ifdef CONFIG_RFKILL |
| 1753 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 1754 | cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); |
| 1755 | #endif |
| 1756 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1757 | pci_save_state(pdev); |
| 1758 | pci_disable_device(pdev); |
| 1759 | pci_set_power_state(pdev, 3); |
| 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static int ath_pci_resume(struct pci_dev *pdev) |
| 1765 | { |
Vasanthakumar Thiagarajan | c83be68 | 2008-08-25 20:47:29 +0530 | [diff] [blame] | 1766 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 1767 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1768 | u32 val; |
| 1769 | int err; |
| 1770 | |
| 1771 | err = pci_enable_device(pdev); |
| 1772 | if (err) |
| 1773 | return err; |
| 1774 | pci_restore_state(pdev); |
| 1775 | /* |
| 1776 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 1777 | * re-disable the RETRY_TIMEOUT register (0x41) to keep |
| 1778 | * PCI Tx retries from interfering with C3 CPU state |
| 1779 | */ |
| 1780 | pci_read_config_dword(pdev, 0x40, &val); |
| 1781 | if ((val & 0x0000ff00) != 0) |
| 1782 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 1783 | |
Vasanthakumar Thiagarajan | c83be68 | 2008-08-25 20:47:29 +0530 | [diff] [blame] | 1784 | /* Enable LED */ |
| 1785 | ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN, |
| 1786 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 1787 | ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); |
| 1788 | |
Vasanthakumar Thiagarajan | 500c064 | 2008-09-10 18:50:17 +0530 | [diff] [blame] | 1789 | #ifdef CONFIG_RFKILL |
| 1790 | /* |
| 1791 | * check the h/w rfkill state on resume |
| 1792 | * and start the rfkill poll timer |
| 1793 | */ |
| 1794 | if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT) |
| 1795 | queue_delayed_work(sc->hw->workqueue, |
| 1796 | &sc->rf_kill.rfkill_poll, 0); |
| 1797 | #endif |
| 1798 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | #endif /* CONFIG_PM */ |
| 1803 | |
| 1804 | MODULE_DEVICE_TABLE(pci, ath_pci_id_table); |
| 1805 | |
| 1806 | static struct pci_driver ath_pci_driver = { |
| 1807 | .name = "ath9k", |
| 1808 | .id_table = ath_pci_id_table, |
| 1809 | .probe = ath_pci_probe, |
| 1810 | .remove = ath_pci_remove, |
| 1811 | #ifdef CONFIG_PM |
| 1812 | .suspend = ath_pci_suspend, |
| 1813 | .resume = ath_pci_resume, |
| 1814 | #endif /* CONFIG_PM */ |
| 1815 | }; |
| 1816 | |
| 1817 | static int __init init_ath_pci(void) |
| 1818 | { |
| 1819 | printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION); |
| 1820 | |
| 1821 | if (pci_register_driver(&ath_pci_driver) < 0) { |
| 1822 | printk(KERN_ERR |
| 1823 | "ath_pci: No devices found, driver not installed.\n"); |
| 1824 | pci_unregister_driver(&ath_pci_driver); |
| 1825 | return -ENODEV; |
| 1826 | } |
| 1827 | |
| 1828 | return 0; |
| 1829 | } |
| 1830 | module_init(init_ath_pci); |
| 1831 | |
| 1832 | static void __exit exit_ath_pci(void) |
| 1833 | { |
| 1834 | pci_unregister_driver(&ath_pci_driver); |
| 1835 | printk(KERN_INFO "%s: driver unloaded\n", dev_info); |
| 1836 | } |
| 1837 | module_exit(exit_ath_pci); |