mac80211-ops.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /*-
  2. * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  3. * Copyright (c) 2004-2005 Atheros Communications, Inc.
  4. * Copyright (c) 2006 Devicescape Software, Inc.
  5. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  6. * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
  7. * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  19. * redistribution must be conditioned upon including a substantially
  20. * similar Disclaimer requirement for further binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  33. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  34. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  35. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  38. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  40. * THE POSSIBILITY OF SUCH DAMAGES.
  41. *
  42. */
  43. #include <asm/unaligned.h>
  44. #include "base.h"
  45. #include "reg.h"
  46. extern int ath5k_modparam_nohwcrypt;
  47. /* functions used from base.c */
  48. void set_beacon_filter(struct ieee80211_hw *hw, bool enable);
  49. bool ath_any_vif_assoc(struct ath5k_softc *sc);
  50. int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
  51. struct ath5k_txq *txq);
  52. int ath5k_init_hw(struct ath5k_softc *sc);
  53. int ath5k_stop_hw(struct ath5k_softc *sc);
  54. void ath5k_mode_setup(struct ath5k_softc *sc, struct ieee80211_vif *vif);
  55. void ath5k_update_bssid_mask_and_opmode(struct ath5k_softc *sc,
  56. struct ieee80211_vif *vif);
  57. int ath5k_chan_set(struct ath5k_softc *sc, struct ieee80211_channel *chan);
  58. void ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf);
  59. int ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
  60. void ath5k_beacon_config(struct ath5k_softc *sc);
  61. void ath5k_txbuf_free_skb(struct ath5k_softc *sc, struct ath5k_buf *bf);
  62. void ath5k_rxbuf_free_skb(struct ath5k_softc *sc, struct ath5k_buf *bf);
  63. /********************\
  64. * Mac80211 functions *
  65. \********************/
  66. static int
  67. ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  68. {
  69. struct ath5k_softc *sc = hw->priv;
  70. u16 qnum = skb_get_queue_mapping(skb);
  71. if (WARN_ON(qnum >= sc->ah->ah_capabilities.cap_queues.q_tx_num)) {
  72. dev_kfree_skb_any(skb);
  73. return 0;
  74. }
  75. return ath5k_tx_queue(hw, skb, &sc->txqs[qnum]);
  76. }
  77. static int
  78. ath5k_start(struct ieee80211_hw *hw)
  79. {
  80. return ath5k_init_hw(hw->priv);
  81. }
  82. static void
  83. ath5k_stop(struct ieee80211_hw *hw)
  84. {
  85. ath5k_stop_hw(hw->priv);
  86. }
  87. static int
  88. ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  89. {
  90. struct ath5k_softc *sc = hw->priv;
  91. int ret;
  92. struct ath5k_vif *avf = (void *)vif->drv_priv;
  93. mutex_lock(&sc->lock);
  94. if ((vif->type == NL80211_IFTYPE_AP ||
  95. vif->type == NL80211_IFTYPE_ADHOC)
  96. && (sc->num_ap_vifs + sc->num_adhoc_vifs) >= ATH_BCBUF) {
  97. ret = -ELNRNG;
  98. goto end;
  99. }
  100. /* Don't allow other interfaces if one ad-hoc is configured.
  101. * TODO: Fix the problems with ad-hoc and multiple other interfaces.
  102. * We would need to operate the HW in ad-hoc mode to allow TSF updates
  103. * for the IBSS, but this breaks with additional AP or STA interfaces
  104. * at the moment. */
  105. if (sc->num_adhoc_vifs ||
  106. (sc->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
  107. ATH5K_ERR(sc, "Only one single ad-hoc interface is allowed.\n");
  108. ret = -ELNRNG;
  109. goto end;
  110. }
  111. switch (vif->type) {
  112. case NL80211_IFTYPE_AP:
  113. case NL80211_IFTYPE_STATION:
  114. case NL80211_IFTYPE_ADHOC:
  115. case NL80211_IFTYPE_MESH_POINT:
  116. avf->opmode = vif->type;
  117. break;
  118. default:
  119. ret = -EOPNOTSUPP;
  120. goto end;
  121. }
  122. sc->nvifs++;
  123. ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
  124. /* Assign the vap/adhoc to a beacon xmit slot. */
  125. if ((avf->opmode == NL80211_IFTYPE_AP) ||
  126. (avf->opmode == NL80211_IFTYPE_ADHOC) ||
  127. (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
  128. int slot;
  129. WARN_ON(list_empty(&sc->bcbuf));
  130. avf->bbuf = list_first_entry(&sc->bcbuf, struct ath5k_buf,
  131. list);
  132. list_del(&avf->bbuf->list);
  133. avf->bslot = 0;
  134. for (slot = 0; slot < ATH_BCBUF; slot++) {
  135. if (!sc->bslot[slot]) {
  136. avf->bslot = slot;
  137. break;
  138. }
  139. }
  140. BUG_ON(sc->bslot[avf->bslot] != NULL);
  141. sc->bslot[avf->bslot] = vif;
  142. if (avf->opmode == NL80211_IFTYPE_AP)
  143. sc->num_ap_vifs++;
  144. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  145. sc->num_adhoc_vifs++;
  146. }
  147. /* Any MAC address is fine, all others are included through the
  148. * filter.
  149. */
  150. memcpy(&sc->lladdr, vif->addr, ETH_ALEN);
  151. ath5k_hw_set_lladdr(sc->ah, vif->addr);
  152. memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
  153. ath5k_mode_setup(sc, vif);
  154. ret = 0;
  155. end:
  156. mutex_unlock(&sc->lock);
  157. return ret;
  158. }
  159. static void
  160. ath5k_remove_interface(struct ieee80211_hw *hw,
  161. struct ieee80211_vif *vif)
  162. {
  163. struct ath5k_softc *sc = hw->priv;
  164. struct ath5k_vif *avf = (void *)vif->drv_priv;
  165. unsigned int i;
  166. mutex_lock(&sc->lock);
  167. sc->nvifs--;
  168. if (avf->bbuf) {
  169. ath5k_txbuf_free_skb(sc, avf->bbuf);
  170. list_add_tail(&avf->bbuf->list, &sc->bcbuf);
  171. for (i = 0; i < ATH_BCBUF; i++) {
  172. if (sc->bslot[i] == vif) {
  173. sc->bslot[i] = NULL;
  174. break;
  175. }
  176. }
  177. avf->bbuf = NULL;
  178. }
  179. if (avf->opmode == NL80211_IFTYPE_AP)
  180. sc->num_ap_vifs--;
  181. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  182. sc->num_adhoc_vifs--;
  183. ath5k_update_bssid_mask_and_opmode(sc, NULL);
  184. mutex_unlock(&sc->lock);
  185. }
  186. /*
  187. * TODO: Phy disable/diversity etc
  188. */
  189. static int
  190. ath5k_config(struct ieee80211_hw *hw, u32 changed)
  191. {
  192. struct ath5k_softc *sc = hw->priv;
  193. struct ath5k_hw *ah = sc->ah;
  194. struct ieee80211_conf *conf = &hw->conf;
  195. int ret = 0;
  196. int i;
  197. mutex_lock(&sc->lock);
  198. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  199. ret = ath5k_chan_set(sc, conf->channel);
  200. if (ret < 0)
  201. goto unlock;
  202. }
  203. if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
  204. (sc->power_level != conf->power_level)) {
  205. sc->power_level = conf->power_level;
  206. /* Half dB steps */
  207. ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
  208. }
  209. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  210. ah->ah_retry_long = conf->long_frame_max_tx_count;
  211. ah->ah_retry_short = conf->short_frame_max_tx_count;
  212. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
  213. ath5k_hw_set_tx_retry_limits(ah, i);
  214. }
  215. /* TODO:
  216. * 1) Move this on config_interface and handle each case
  217. * separately eg. when we have only one STA vif, use
  218. * AR5K_ANTMODE_SINGLE_AP
  219. *
  220. * 2) Allow the user to change antenna mode eg. when only
  221. * one antenna is present
  222. *
  223. * 3) Allow the user to set default/tx antenna when possible
  224. *
  225. * 4) Default mode should handle 90% of the cases, together
  226. * with fixed a/b and single AP modes we should be able to
  227. * handle 99%. Sectored modes are extreme cases and i still
  228. * haven't found a usage for them. If we decide to support them,
  229. * then we must allow the user to set how many tx antennas we
  230. * have available
  231. */
  232. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  233. unlock:
  234. mutex_unlock(&sc->lock);
  235. return ret;
  236. }
  237. static void
  238. ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  239. struct ieee80211_bss_conf *bss_conf, u32 changes)
  240. {
  241. struct ath5k_vif *avf = (void *)vif->drv_priv;
  242. struct ath5k_softc *sc = hw->priv;
  243. struct ath5k_hw *ah = sc->ah;
  244. struct ath_common *common = ath5k_hw_common(ah);
  245. unsigned long flags;
  246. mutex_lock(&sc->lock);
  247. if (changes & BSS_CHANGED_BSSID) {
  248. /* Cache for later use during resets */
  249. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  250. common->curaid = 0;
  251. ath5k_hw_set_bssid(ah);
  252. mmiowb();
  253. }
  254. if (changes & BSS_CHANGED_BEACON_INT)
  255. sc->bintval = bss_conf->beacon_int;
  256. if (changes & BSS_CHANGED_ASSOC) {
  257. avf->assoc = bss_conf->assoc;
  258. if (bss_conf->assoc)
  259. sc->assoc = bss_conf->assoc;
  260. else
  261. sc->assoc = ath_any_vif_assoc(sc);
  262. if (sc->opmode == NL80211_IFTYPE_STATION)
  263. set_beacon_filter(hw, sc->assoc);
  264. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  265. AR5K_LED_ASSOC : AR5K_LED_INIT);
  266. if (bss_conf->assoc) {
  267. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  268. "Bss Info ASSOC %d, bssid: %pM\n",
  269. bss_conf->aid, common->curbssid);
  270. common->curaid = bss_conf->aid;
  271. ath5k_hw_set_bssid(ah);
  272. /* Once ANI is available you would start it here */
  273. }
  274. }
  275. if (changes & BSS_CHANGED_BEACON) {
  276. spin_lock_irqsave(&sc->block, flags);
  277. ath5k_beacon_update(hw, vif);
  278. spin_unlock_irqrestore(&sc->block, flags);
  279. }
  280. if (changes & BSS_CHANGED_BEACON_ENABLED)
  281. sc->enable_beacon = bss_conf->enable_beacon;
  282. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
  283. BSS_CHANGED_BEACON_INT))
  284. ath5k_beacon_config(sc);
  285. mutex_unlock(&sc->lock);
  286. }
  287. static u64
  288. ath5k_prepare_multicast(struct ieee80211_hw *hw,
  289. struct netdev_hw_addr_list *mc_list)
  290. {
  291. u32 mfilt[2], val;
  292. u8 pos;
  293. struct netdev_hw_addr *ha;
  294. mfilt[0] = 0;
  295. mfilt[1] = 1;
  296. netdev_hw_addr_list_for_each(ha, mc_list) {
  297. /* calculate XOR of eight 6-bit values */
  298. val = get_unaligned_le32(ha->addr + 0);
  299. pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  300. val = get_unaligned_le32(ha->addr + 3);
  301. pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  302. pos &= 0x3f;
  303. mfilt[pos / 32] |= (1 << (pos % 32));
  304. /* XXX: we might be able to just do this instead,
  305. * but not sure, needs testing, if we do use this we'd
  306. * neet to inform below to not reset the mcast */
  307. /* ath5k_hw_set_mcast_filterindex(ah,
  308. * ha->addr[5]); */
  309. }
  310. return ((u64)(mfilt[1]) << 32) | mfilt[0];
  311. }
  312. /*
  313. * o always accept unicast, broadcast, and multicast traffic
  314. * o multicast traffic for all BSSIDs will be enabled if mac80211
  315. * says it should be
  316. * o maintain current state of phy ofdm or phy cck error reception.
  317. * If the hardware detects any of these type of errors then
  318. * ath5k_hw_get_rx_filter() will pass to us the respective
  319. * hardware filters to be able to receive these type of frames.
  320. * o probe request frames are accepted only when operating in
  321. * hostap, adhoc, or monitor modes
  322. * o enable promiscuous mode according to the interface state
  323. * o accept beacons:
  324. * - when operating in adhoc mode so the 802.11 layer creates
  325. * node table entries for peers,
  326. * - when operating in station mode for collecting rssi data when
  327. * the station is otherwise quiet, or
  328. * - when scanning
  329. */
  330. static void
  331. ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  332. unsigned int *new_flags, u64 multicast)
  333. {
  334. #define SUPPORTED_FIF_FLAGS \
  335. (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
  336. FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
  337. FIF_BCN_PRBRESP_PROMISC)
  338. struct ath5k_softc *sc = hw->priv;
  339. struct ath5k_hw *ah = sc->ah;
  340. u32 mfilt[2], rfilt;
  341. mutex_lock(&sc->lock);
  342. mfilt[0] = multicast;
  343. mfilt[1] = multicast >> 32;
  344. /* Only deal with supported flags */
  345. changed_flags &= SUPPORTED_FIF_FLAGS;
  346. *new_flags &= SUPPORTED_FIF_FLAGS;
  347. /* If HW detects any phy or radar errors, leave those filters on.
  348. * Also, always enable Unicast, Broadcasts and Multicast
  349. * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
  350. rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
  351. (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
  352. AR5K_RX_FILTER_MCAST);
  353. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  354. if (*new_flags & FIF_PROMISC_IN_BSS)
  355. __set_bit(ATH_STAT_PROMISC, sc->status);
  356. else
  357. __clear_bit(ATH_STAT_PROMISC, sc->status);
  358. }
  359. if (test_bit(ATH_STAT_PROMISC, sc->status))
  360. rfilt |= AR5K_RX_FILTER_PROM;
  361. /* Note, AR5K_RX_FILTER_MCAST is already enabled */
  362. if (*new_flags & FIF_ALLMULTI) {
  363. mfilt[0] = ~0;
  364. mfilt[1] = ~0;
  365. }
  366. /* This is the best we can do */
  367. if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
  368. rfilt |= AR5K_RX_FILTER_PHYERR;
  369. /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
  370. * and probes for any BSSID */
  371. if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (sc->nvifs > 1))
  372. rfilt |= AR5K_RX_FILTER_BEACON;
  373. /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
  374. * set we should only pass on control frames for this
  375. * station. This needs testing. I believe right now this
  376. * enables *all* control frames, which is OK.. but
  377. * but we should see if we can improve on granularity */
  378. if (*new_flags & FIF_CONTROL)
  379. rfilt |= AR5K_RX_FILTER_CONTROL;
  380. /* Additional settings per mode -- this is per ath5k */
  381. /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
  382. switch (sc->opmode) {
  383. case NL80211_IFTYPE_MESH_POINT:
  384. rfilt |= AR5K_RX_FILTER_CONTROL |
  385. AR5K_RX_FILTER_BEACON |
  386. AR5K_RX_FILTER_PROBEREQ |
  387. AR5K_RX_FILTER_PROM;
  388. break;
  389. case NL80211_IFTYPE_AP:
  390. case NL80211_IFTYPE_ADHOC:
  391. rfilt |= AR5K_RX_FILTER_PROBEREQ |
  392. AR5K_RX_FILTER_BEACON;
  393. break;
  394. case NL80211_IFTYPE_STATION:
  395. if (sc->assoc)
  396. rfilt |= AR5K_RX_FILTER_BEACON;
  397. default:
  398. break;
  399. }
  400. /* Set filters */
  401. ath5k_hw_set_rx_filter(ah, rfilt);
  402. /* Set multicast bits */
  403. ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
  404. /* Set the cached hw filter flags, this will later actually
  405. * be set in HW */
  406. sc->filter_flags = rfilt;
  407. mutex_unlock(&sc->lock);
  408. }
  409. static int
  410. ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  411. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  412. struct ieee80211_key_conf *key)
  413. {
  414. struct ath5k_softc *sc = hw->priv;
  415. struct ath5k_hw *ah = sc->ah;
  416. struct ath_common *common = ath5k_hw_common(ah);
  417. int ret = 0;
  418. if (ath5k_modparam_nohwcrypt)
  419. return -EOPNOTSUPP;
  420. switch (key->cipher) {
  421. case WLAN_CIPHER_SUITE_WEP40:
  422. case WLAN_CIPHER_SUITE_WEP104:
  423. case WLAN_CIPHER_SUITE_TKIP:
  424. break;
  425. case WLAN_CIPHER_SUITE_CCMP:
  426. if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
  427. break;
  428. return -EOPNOTSUPP;
  429. default:
  430. WARN_ON(1);
  431. return -EINVAL;
  432. }
  433. mutex_lock(&sc->lock);
  434. switch (cmd) {
  435. case SET_KEY:
  436. ret = ath_key_config(common, vif, sta, key);
  437. if (ret >= 0) {
  438. key->hw_key_idx = ret;
  439. /* push IV and Michael MIC generation to stack */
  440. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  441. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  442. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  443. if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
  444. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  445. ret = 0;
  446. }
  447. break;
  448. case DISABLE_KEY:
  449. ath_key_delete(common, key);
  450. break;
  451. default:
  452. ret = -EINVAL;
  453. }
  454. mmiowb();
  455. mutex_unlock(&sc->lock);
  456. return ret;
  457. }
  458. static void
  459. ath5k_sw_scan_start(struct ieee80211_hw *hw)
  460. {
  461. struct ath5k_softc *sc = hw->priv;
  462. if (!sc->assoc)
  463. ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
  464. }
  465. static void
  466. ath5k_sw_scan_complete(struct ieee80211_hw *hw)
  467. {
  468. struct ath5k_softc *sc = hw->priv;
  469. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  470. AR5K_LED_ASSOC : AR5K_LED_INIT);
  471. }
  472. static int
  473. ath5k_get_stats(struct ieee80211_hw *hw,
  474. struct ieee80211_low_level_stats *stats)
  475. {
  476. struct ath5k_softc *sc = hw->priv;
  477. /* Force update */
  478. ath5k_hw_update_mib_counters(sc->ah);
  479. stats->dot11ACKFailureCount = sc->stats.ack_fail;
  480. stats->dot11RTSFailureCount = sc->stats.rts_fail;
  481. stats->dot11RTSSuccessCount = sc->stats.rts_ok;
  482. stats->dot11FCSErrorCount = sc->stats.fcs_error;
  483. return 0;
  484. }
  485. static int
  486. ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  487. const struct ieee80211_tx_queue_params *params)
  488. {
  489. struct ath5k_softc *sc = hw->priv;
  490. struct ath5k_hw *ah = sc->ah;
  491. struct ath5k_txq_info qi;
  492. int ret = 0;
  493. if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
  494. return 0;
  495. mutex_lock(&sc->lock);
  496. ath5k_hw_get_tx_queueprops(ah, queue, &qi);
  497. qi.tqi_aifs = params->aifs;
  498. qi.tqi_cw_min = params->cw_min;
  499. qi.tqi_cw_max = params->cw_max;
  500. qi.tqi_burst_time = params->txop;
  501. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  502. "Configure tx [queue %d], "
  503. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  504. queue, params->aifs, params->cw_min,
  505. params->cw_max, params->txop);
  506. if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
  507. ATH5K_ERR(sc,
  508. "Unable to update hardware queue %u!\n", queue);
  509. ret = -EIO;
  510. } else
  511. ath5k_hw_reset_tx_queue(ah, queue);
  512. mutex_unlock(&sc->lock);
  513. return ret;
  514. }
  515. static u64
  516. ath5k_get_tsf(struct ieee80211_hw *hw)
  517. {
  518. struct ath5k_softc *sc = hw->priv;
  519. return ath5k_hw_get_tsf64(sc->ah);
  520. }
  521. static void
  522. ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  523. {
  524. struct ath5k_softc *sc = hw->priv;
  525. ath5k_hw_set_tsf64(sc->ah, tsf);
  526. }
  527. static void
  528. ath5k_reset_tsf(struct ieee80211_hw *hw)
  529. {
  530. struct ath5k_softc *sc = hw->priv;
  531. /*
  532. * in IBSS mode we need to update the beacon timers too.
  533. * this will also reset the TSF if we call it with 0
  534. */
  535. if (sc->opmode == NL80211_IFTYPE_ADHOC)
  536. ath5k_beacon_update_timers(sc, 0);
  537. else
  538. ath5k_hw_reset_tsf(sc->ah);
  539. }
  540. static int
  541. ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
  542. {
  543. struct ath5k_softc *sc = hw->priv;
  544. struct ieee80211_conf *conf = &hw->conf;
  545. struct ath_common *common = ath5k_hw_common(sc->ah);
  546. struct ath_cycle_counters *cc = &common->cc_survey;
  547. unsigned int div = common->clockrate * 1000;
  548. if (idx != 0)
  549. return -ENOENT;
  550. spin_lock_bh(&common->cc_lock);
  551. ath_hw_cycle_counters_update(common);
  552. if (cc->cycles > 0) {
  553. sc->survey.channel_time += cc->cycles / div;
  554. sc->survey.channel_time_busy += cc->rx_busy / div;
  555. sc->survey.channel_time_rx += cc->rx_frame / div;
  556. sc->survey.channel_time_tx += cc->tx_frame / div;
  557. }
  558. memset(cc, 0, sizeof(*cc));
  559. spin_unlock_bh(&common->cc_lock);
  560. memcpy(survey, &sc->survey, sizeof(*survey));
  561. survey->channel = conf->channel;
  562. survey->noise = sc->ah->ah_noise_floor;
  563. survey->filled = SURVEY_INFO_NOISE_DBM |
  564. SURVEY_INFO_CHANNEL_TIME |
  565. SURVEY_INFO_CHANNEL_TIME_BUSY |
  566. SURVEY_INFO_CHANNEL_TIME_RX |
  567. SURVEY_INFO_CHANNEL_TIME_TX;
  568. return 0;
  569. }
  570. /**
  571. * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
  572. *
  573. * @hw: struct ieee80211_hw pointer
  574. * @coverage_class: IEEE 802.11 coverage class number
  575. *
  576. * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
  577. * coverage class. The values are persistent, they are restored after device
  578. * reset.
  579. */
  580. static void
  581. ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  582. {
  583. struct ath5k_softc *sc = hw->priv;
  584. mutex_lock(&sc->lock);
  585. ath5k_hw_set_coverage_class(sc->ah, coverage_class);
  586. mutex_unlock(&sc->lock);
  587. }
  588. static int
  589. ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  590. {
  591. struct ath5k_softc *sc = hw->priv;
  592. if (tx_ant == 1 && rx_ant == 1)
  593. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
  594. else if (tx_ant == 2 && rx_ant == 2)
  595. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
  596. else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
  597. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
  598. else
  599. return -EINVAL;
  600. return 0;
  601. }
  602. static int
  603. ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  604. {
  605. struct ath5k_softc *sc = hw->priv;
  606. switch (sc->ah->ah_ant_mode) {
  607. case AR5K_ANTMODE_FIXED_A:
  608. *tx_ant = 1; *rx_ant = 1; break;
  609. case AR5K_ANTMODE_FIXED_B:
  610. *tx_ant = 2; *rx_ant = 2; break;
  611. case AR5K_ANTMODE_DEFAULT:
  612. *tx_ant = 3; *rx_ant = 3; break;
  613. }
  614. return 0;
  615. }
  616. const struct ieee80211_ops ath5k_hw_ops = {
  617. .tx = ath5k_tx,
  618. .start = ath5k_start,
  619. .stop = ath5k_stop,
  620. .add_interface = ath5k_add_interface,
  621. /* .change_interface = not implemented */
  622. .remove_interface = ath5k_remove_interface,
  623. .config = ath5k_config,
  624. .bss_info_changed = ath5k_bss_info_changed,
  625. .prepare_multicast = ath5k_prepare_multicast,
  626. .configure_filter = ath5k_configure_filter,
  627. /* .set_tim = not implemented */
  628. .set_key = ath5k_set_key,
  629. /* .update_tkip_key = not implemented */
  630. /* .hw_scan = not implemented */
  631. .sw_scan_start = ath5k_sw_scan_start,
  632. .sw_scan_complete = ath5k_sw_scan_complete,
  633. .get_stats = ath5k_get_stats,
  634. /* .get_tkip_seq = not implemented */
  635. /* .set_frag_threshold = not implemented */
  636. /* .set_rts_threshold = not implemented */
  637. /* .sta_add = not implemented */
  638. /* .sta_remove = not implemented */
  639. /* .sta_notify = not implemented */
  640. .conf_tx = ath5k_conf_tx,
  641. .get_tsf = ath5k_get_tsf,
  642. .set_tsf = ath5k_set_tsf,
  643. .reset_tsf = ath5k_reset_tsf,
  644. /* .tx_last_beacon = not implemented */
  645. /* .ampdu_action = not needed */
  646. .get_survey = ath5k_get_survey,
  647. .set_coverage_class = ath5k_set_coverage_class,
  648. /* .rfkill_poll = not implemented */
  649. /* .flush = not implemented */
  650. /* .channel_switch = not implemented */
  651. /* .napi_poll = not implemented */
  652. .set_antenna = ath5k_set_antenna,
  653. .get_antenna = ath5k_get_antenna,
  654. };