mac80211-ops.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. mutex_lock(&sc->lock);
  197. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  198. ret = ath5k_chan_set(sc, conf->channel);
  199. if (ret < 0)
  200. goto unlock;
  201. }
  202. if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
  203. (sc->power_level != conf->power_level)) {
  204. sc->power_level = conf->power_level;
  205. /* Half dB steps */
  206. ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
  207. }
  208. /* TODO:
  209. * 1) Move this on config_interface and handle each case
  210. * separately eg. when we have only one STA vif, use
  211. * AR5K_ANTMODE_SINGLE_AP
  212. *
  213. * 2) Allow the user to change antenna mode eg. when only
  214. * one antenna is present
  215. *
  216. * 3) Allow the user to set default/tx antenna when possible
  217. *
  218. * 4) Default mode should handle 90% of the cases, together
  219. * with fixed a/b and single AP modes we should be able to
  220. * handle 99%. Sectored modes are extreme cases and i still
  221. * haven't found a usage for them. If we decide to support them,
  222. * then we must allow the user to set how many tx antennas we
  223. * have available
  224. */
  225. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  226. unlock:
  227. mutex_unlock(&sc->lock);
  228. return ret;
  229. }
  230. static void
  231. ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  232. struct ieee80211_bss_conf *bss_conf, u32 changes)
  233. {
  234. struct ath5k_vif *avf = (void *)vif->drv_priv;
  235. struct ath5k_softc *sc = hw->priv;
  236. struct ath5k_hw *ah = sc->ah;
  237. struct ath_common *common = ath5k_hw_common(ah);
  238. unsigned long flags;
  239. mutex_lock(&sc->lock);
  240. if (changes & BSS_CHANGED_BSSID) {
  241. /* Cache for later use during resets */
  242. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  243. common->curaid = 0;
  244. ath5k_hw_set_bssid(ah);
  245. mmiowb();
  246. }
  247. if (changes & BSS_CHANGED_BEACON_INT)
  248. sc->bintval = bss_conf->beacon_int;
  249. if (changes & BSS_CHANGED_ASSOC) {
  250. avf->assoc = bss_conf->assoc;
  251. if (bss_conf->assoc)
  252. sc->assoc = bss_conf->assoc;
  253. else
  254. sc->assoc = ath_any_vif_assoc(sc);
  255. if (sc->opmode == NL80211_IFTYPE_STATION)
  256. set_beacon_filter(hw, sc->assoc);
  257. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  258. AR5K_LED_ASSOC : AR5K_LED_INIT);
  259. if (bss_conf->assoc) {
  260. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  261. "Bss Info ASSOC %d, bssid: %pM\n",
  262. bss_conf->aid, common->curbssid);
  263. common->curaid = bss_conf->aid;
  264. ath5k_hw_set_bssid(ah);
  265. /* Once ANI is available you would start it here */
  266. }
  267. }
  268. if (changes & BSS_CHANGED_BEACON) {
  269. spin_lock_irqsave(&sc->block, flags);
  270. ath5k_beacon_update(hw, vif);
  271. spin_unlock_irqrestore(&sc->block, flags);
  272. }
  273. if (changes & BSS_CHANGED_BEACON_ENABLED)
  274. sc->enable_beacon = bss_conf->enable_beacon;
  275. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
  276. BSS_CHANGED_BEACON_INT))
  277. ath5k_beacon_config(sc);
  278. mutex_unlock(&sc->lock);
  279. }
  280. static u64
  281. ath5k_prepare_multicast(struct ieee80211_hw *hw,
  282. struct netdev_hw_addr_list *mc_list)
  283. {
  284. u32 mfilt[2], val;
  285. u8 pos;
  286. struct netdev_hw_addr *ha;
  287. mfilt[0] = 0;
  288. mfilt[1] = 1;
  289. netdev_hw_addr_list_for_each(ha, mc_list) {
  290. /* calculate XOR of eight 6-bit values */
  291. val = get_unaligned_le32(ha->addr + 0);
  292. pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  293. val = get_unaligned_le32(ha->addr + 3);
  294. pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  295. pos &= 0x3f;
  296. mfilt[pos / 32] |= (1 << (pos % 32));
  297. /* XXX: we might be able to just do this instead,
  298. * but not sure, needs testing, if we do use this we'd
  299. * neet to inform below to not reset the mcast */
  300. /* ath5k_hw_set_mcast_filterindex(ah,
  301. * ha->addr[5]); */
  302. }
  303. return ((u64)(mfilt[1]) << 32) | mfilt[0];
  304. }
  305. /*
  306. * o always accept unicast, broadcast, and multicast traffic
  307. * o multicast traffic for all BSSIDs will be enabled if mac80211
  308. * says it should be
  309. * o maintain current state of phy ofdm or phy cck error reception.
  310. * If the hardware detects any of these type of errors then
  311. * ath5k_hw_get_rx_filter() will pass to us the respective
  312. * hardware filters to be able to receive these type of frames.
  313. * o probe request frames are accepted only when operating in
  314. * hostap, adhoc, or monitor modes
  315. * o enable promiscuous mode according to the interface state
  316. * o accept beacons:
  317. * - when operating in adhoc mode so the 802.11 layer creates
  318. * node table entries for peers,
  319. * - when operating in station mode for collecting rssi data when
  320. * the station is otherwise quiet, or
  321. * - when scanning
  322. */
  323. static void
  324. ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  325. unsigned int *new_flags, u64 multicast)
  326. {
  327. #define SUPPORTED_FIF_FLAGS \
  328. (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
  329. FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
  330. FIF_BCN_PRBRESP_PROMISC)
  331. struct ath5k_softc *sc = hw->priv;
  332. struct ath5k_hw *ah = sc->ah;
  333. u32 mfilt[2], rfilt;
  334. mutex_lock(&sc->lock);
  335. mfilt[0] = multicast;
  336. mfilt[1] = multicast >> 32;
  337. /* Only deal with supported flags */
  338. changed_flags &= SUPPORTED_FIF_FLAGS;
  339. *new_flags &= SUPPORTED_FIF_FLAGS;
  340. /* If HW detects any phy or radar errors, leave those filters on.
  341. * Also, always enable Unicast, Broadcasts and Multicast
  342. * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
  343. rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
  344. (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
  345. AR5K_RX_FILTER_MCAST);
  346. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  347. if (*new_flags & FIF_PROMISC_IN_BSS)
  348. __set_bit(ATH_STAT_PROMISC, sc->status);
  349. else
  350. __clear_bit(ATH_STAT_PROMISC, sc->status);
  351. }
  352. if (test_bit(ATH_STAT_PROMISC, sc->status))
  353. rfilt |= AR5K_RX_FILTER_PROM;
  354. /* Note, AR5K_RX_FILTER_MCAST is already enabled */
  355. if (*new_flags & FIF_ALLMULTI) {
  356. mfilt[0] = ~0;
  357. mfilt[1] = ~0;
  358. }
  359. /* This is the best we can do */
  360. if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
  361. rfilt |= AR5K_RX_FILTER_PHYERR;
  362. /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
  363. * and probes for any BSSID */
  364. if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (sc->nvifs > 1))
  365. rfilt |= AR5K_RX_FILTER_BEACON;
  366. /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
  367. * set we should only pass on control frames for this
  368. * station. This needs testing. I believe right now this
  369. * enables *all* control frames, which is OK.. but
  370. * but we should see if we can improve on granularity */
  371. if (*new_flags & FIF_CONTROL)
  372. rfilt |= AR5K_RX_FILTER_CONTROL;
  373. /* Additional settings per mode -- this is per ath5k */
  374. /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
  375. switch (sc->opmode) {
  376. case NL80211_IFTYPE_MESH_POINT:
  377. rfilt |= AR5K_RX_FILTER_CONTROL |
  378. AR5K_RX_FILTER_BEACON |
  379. AR5K_RX_FILTER_PROBEREQ |
  380. AR5K_RX_FILTER_PROM;
  381. break;
  382. case NL80211_IFTYPE_AP:
  383. case NL80211_IFTYPE_ADHOC:
  384. rfilt |= AR5K_RX_FILTER_PROBEREQ |
  385. AR5K_RX_FILTER_BEACON;
  386. break;
  387. case NL80211_IFTYPE_STATION:
  388. if (sc->assoc)
  389. rfilt |= AR5K_RX_FILTER_BEACON;
  390. default:
  391. break;
  392. }
  393. /* Set filters */
  394. ath5k_hw_set_rx_filter(ah, rfilt);
  395. /* Set multicast bits */
  396. ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
  397. /* Set the cached hw filter flags, this will later actually
  398. * be set in HW */
  399. sc->filter_flags = rfilt;
  400. mutex_unlock(&sc->lock);
  401. }
  402. static int
  403. ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  404. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  405. struct ieee80211_key_conf *key)
  406. {
  407. struct ath5k_softc *sc = hw->priv;
  408. struct ath5k_hw *ah = sc->ah;
  409. struct ath_common *common = ath5k_hw_common(ah);
  410. int ret = 0;
  411. if (ath5k_modparam_nohwcrypt)
  412. return -EOPNOTSUPP;
  413. switch (key->cipher) {
  414. case WLAN_CIPHER_SUITE_WEP40:
  415. case WLAN_CIPHER_SUITE_WEP104:
  416. case WLAN_CIPHER_SUITE_TKIP:
  417. break;
  418. case WLAN_CIPHER_SUITE_CCMP:
  419. if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
  420. break;
  421. return -EOPNOTSUPP;
  422. default:
  423. WARN_ON(1);
  424. return -EINVAL;
  425. }
  426. mutex_lock(&sc->lock);
  427. switch (cmd) {
  428. case SET_KEY:
  429. ret = ath_key_config(common, vif, sta, key);
  430. if (ret >= 0) {
  431. key->hw_key_idx = ret;
  432. /* push IV and Michael MIC generation to stack */
  433. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  434. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  435. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  436. if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
  437. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  438. ret = 0;
  439. }
  440. break;
  441. case DISABLE_KEY:
  442. ath_key_delete(common, key);
  443. break;
  444. default:
  445. ret = -EINVAL;
  446. }
  447. mmiowb();
  448. mutex_unlock(&sc->lock);
  449. return ret;
  450. }
  451. static void
  452. ath5k_sw_scan_start(struct ieee80211_hw *hw)
  453. {
  454. struct ath5k_softc *sc = hw->priv;
  455. if (!sc->assoc)
  456. ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
  457. }
  458. static void
  459. ath5k_sw_scan_complete(struct ieee80211_hw *hw)
  460. {
  461. struct ath5k_softc *sc = hw->priv;
  462. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  463. AR5K_LED_ASSOC : AR5K_LED_INIT);
  464. }
  465. static int
  466. ath5k_get_stats(struct ieee80211_hw *hw,
  467. struct ieee80211_low_level_stats *stats)
  468. {
  469. struct ath5k_softc *sc = hw->priv;
  470. /* Force update */
  471. ath5k_hw_update_mib_counters(sc->ah);
  472. stats->dot11ACKFailureCount = sc->stats.ack_fail;
  473. stats->dot11RTSFailureCount = sc->stats.rts_fail;
  474. stats->dot11RTSSuccessCount = sc->stats.rts_ok;
  475. stats->dot11FCSErrorCount = sc->stats.fcs_error;
  476. return 0;
  477. }
  478. static int
  479. ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  480. const struct ieee80211_tx_queue_params *params)
  481. {
  482. struct ath5k_softc *sc = hw->priv;
  483. struct ath5k_hw *ah = sc->ah;
  484. struct ath5k_txq_info qi;
  485. int ret = 0;
  486. if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
  487. return 0;
  488. mutex_lock(&sc->lock);
  489. ath5k_hw_get_tx_queueprops(ah, queue, &qi);
  490. qi.tqi_aifs = params->aifs;
  491. qi.tqi_cw_min = params->cw_min;
  492. qi.tqi_cw_max = params->cw_max;
  493. qi.tqi_burst_time = params->txop;
  494. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  495. "Configure tx [queue %d], "
  496. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  497. queue, params->aifs, params->cw_min,
  498. params->cw_max, params->txop);
  499. if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
  500. ATH5K_ERR(sc,
  501. "Unable to update hardware queue %u!\n", queue);
  502. ret = -EIO;
  503. } else
  504. ath5k_hw_reset_tx_queue(ah, queue);
  505. mutex_unlock(&sc->lock);
  506. return ret;
  507. }
  508. static u64
  509. ath5k_get_tsf(struct ieee80211_hw *hw)
  510. {
  511. struct ath5k_softc *sc = hw->priv;
  512. return ath5k_hw_get_tsf64(sc->ah);
  513. }
  514. static void
  515. ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  516. {
  517. struct ath5k_softc *sc = hw->priv;
  518. ath5k_hw_set_tsf64(sc->ah, tsf);
  519. }
  520. static void
  521. ath5k_reset_tsf(struct ieee80211_hw *hw)
  522. {
  523. struct ath5k_softc *sc = hw->priv;
  524. /*
  525. * in IBSS mode we need to update the beacon timers too.
  526. * this will also reset the TSF if we call it with 0
  527. */
  528. if (sc->opmode == NL80211_IFTYPE_ADHOC)
  529. ath5k_beacon_update_timers(sc, 0);
  530. else
  531. ath5k_hw_reset_tsf(sc->ah);
  532. }
  533. static int
  534. ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
  535. {
  536. struct ath5k_softc *sc = hw->priv;
  537. struct ieee80211_conf *conf = &hw->conf;
  538. struct ath_common *common = ath5k_hw_common(sc->ah);
  539. struct ath_cycle_counters *cc = &common->cc_survey;
  540. unsigned int div = common->clockrate * 1000;
  541. if (idx != 0)
  542. return -ENOENT;
  543. spin_lock_bh(&common->cc_lock);
  544. ath_hw_cycle_counters_update(common);
  545. if (cc->cycles > 0) {
  546. sc->survey.channel_time += cc->cycles / div;
  547. sc->survey.channel_time_busy += cc->rx_busy / div;
  548. sc->survey.channel_time_rx += cc->rx_frame / div;
  549. sc->survey.channel_time_tx += cc->tx_frame / div;
  550. }
  551. memset(cc, 0, sizeof(*cc));
  552. spin_unlock_bh(&common->cc_lock);
  553. memcpy(survey, &sc->survey, sizeof(*survey));
  554. survey->channel = conf->channel;
  555. survey->noise = sc->ah->ah_noise_floor;
  556. survey->filled = SURVEY_INFO_NOISE_DBM |
  557. SURVEY_INFO_CHANNEL_TIME |
  558. SURVEY_INFO_CHANNEL_TIME_BUSY |
  559. SURVEY_INFO_CHANNEL_TIME_RX |
  560. SURVEY_INFO_CHANNEL_TIME_TX;
  561. return 0;
  562. }
  563. /**
  564. * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
  565. *
  566. * @hw: struct ieee80211_hw pointer
  567. * @coverage_class: IEEE 802.11 coverage class number
  568. *
  569. * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
  570. * coverage class. The values are persistent, they are restored after device
  571. * reset.
  572. */
  573. static void
  574. ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  575. {
  576. struct ath5k_softc *sc = hw->priv;
  577. mutex_lock(&sc->lock);
  578. ath5k_hw_set_coverage_class(sc->ah, coverage_class);
  579. mutex_unlock(&sc->lock);
  580. }
  581. static int
  582. ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  583. {
  584. struct ath5k_softc *sc = hw->priv;
  585. if (tx_ant == 1 && rx_ant == 1)
  586. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
  587. else if (tx_ant == 2 && rx_ant == 2)
  588. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
  589. else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
  590. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
  591. else
  592. return -EINVAL;
  593. return 0;
  594. }
  595. static int
  596. ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  597. {
  598. struct ath5k_softc *sc = hw->priv;
  599. switch (sc->ah->ah_ant_mode) {
  600. case AR5K_ANTMODE_FIXED_A:
  601. *tx_ant = 1; *rx_ant = 1; break;
  602. case AR5K_ANTMODE_FIXED_B:
  603. *tx_ant = 2; *rx_ant = 2; break;
  604. case AR5K_ANTMODE_DEFAULT:
  605. *tx_ant = 3; *rx_ant = 3; break;
  606. }
  607. return 0;
  608. }
  609. const struct ieee80211_ops ath5k_hw_ops = {
  610. .tx = ath5k_tx,
  611. .start = ath5k_start,
  612. .stop = ath5k_stop,
  613. .add_interface = ath5k_add_interface,
  614. /* .change_interface = not implemented */
  615. .remove_interface = ath5k_remove_interface,
  616. .config = ath5k_config,
  617. .bss_info_changed = ath5k_bss_info_changed,
  618. .prepare_multicast = ath5k_prepare_multicast,
  619. .configure_filter = ath5k_configure_filter,
  620. /* .set_tim = not implemented */
  621. .set_key = ath5k_set_key,
  622. /* .update_tkip_key = not implemented */
  623. /* .hw_scan = not implemented */
  624. .sw_scan_start = ath5k_sw_scan_start,
  625. .sw_scan_complete = ath5k_sw_scan_complete,
  626. .get_stats = ath5k_get_stats,
  627. /* .get_tkip_seq = not implemented */
  628. /* .set_frag_threshold = not implemented */
  629. /* .set_rts_threshold = not implemented */
  630. /* .sta_add = not implemented */
  631. /* .sta_remove = not implemented */
  632. /* .sta_notify = not implemented */
  633. .conf_tx = ath5k_conf_tx,
  634. .get_tsf = ath5k_get_tsf,
  635. .set_tsf = ath5k_set_tsf,
  636. .reset_tsf = ath5k_reset_tsf,
  637. /* .tx_last_beacon = not implemented */
  638. /* .ampdu_action = not needed */
  639. .get_survey = ath5k_get_survey,
  640. .set_coverage_class = ath5k_set_coverage_class,
  641. /* .rfkill_poll = not implemented */
  642. /* .flush = not implemented */
  643. /* .channel_switch = not implemented */
  644. /* .napi_poll = not implemented */
  645. .set_antenna = ath5k_set_antenna,
  646. .get_antenna = ath5k_get_antenna,
  647. };