mac80211-ops.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. /********************\
  48. * Mac80211 functions *
  49. \********************/
  50. static void
  51. ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  52. {
  53. struct ath5k_softc *sc = hw->priv;
  54. u16 qnum = skb_get_queue_mapping(skb);
  55. if (WARN_ON(qnum >= sc->ah->ah_capabilities.cap_queues.q_tx_num)) {
  56. dev_kfree_skb_any(skb);
  57. return;
  58. }
  59. ath5k_tx_queue(hw, skb, &sc->txqs[qnum]);
  60. }
  61. static int
  62. ath5k_start(struct ieee80211_hw *hw)
  63. {
  64. return ath5k_init_hw(hw->priv);
  65. }
  66. static void
  67. ath5k_stop(struct ieee80211_hw *hw)
  68. {
  69. ath5k_stop_hw(hw->priv);
  70. }
  71. static int
  72. ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  73. {
  74. struct ath5k_softc *sc = hw->priv;
  75. int ret;
  76. struct ath5k_vif *avf = (void *)vif->drv_priv;
  77. mutex_lock(&sc->lock);
  78. if ((vif->type == NL80211_IFTYPE_AP ||
  79. vif->type == NL80211_IFTYPE_ADHOC)
  80. && (sc->num_ap_vifs + sc->num_adhoc_vifs) >= ATH_BCBUF) {
  81. ret = -ELNRNG;
  82. goto end;
  83. }
  84. /* Don't allow other interfaces if one ad-hoc is configured.
  85. * TODO: Fix the problems with ad-hoc and multiple other interfaces.
  86. * We would need to operate the HW in ad-hoc mode to allow TSF updates
  87. * for the IBSS, but this breaks with additional AP or STA interfaces
  88. * at the moment. */
  89. if (sc->num_adhoc_vifs ||
  90. (sc->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
  91. ATH5K_ERR(sc, "Only one single ad-hoc interface is allowed.\n");
  92. ret = -ELNRNG;
  93. goto end;
  94. }
  95. switch (vif->type) {
  96. case NL80211_IFTYPE_AP:
  97. case NL80211_IFTYPE_STATION:
  98. case NL80211_IFTYPE_ADHOC:
  99. case NL80211_IFTYPE_MESH_POINT:
  100. avf->opmode = vif->type;
  101. break;
  102. default:
  103. ret = -EOPNOTSUPP;
  104. goto end;
  105. }
  106. sc->nvifs++;
  107. ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
  108. /* Assign the vap/adhoc to a beacon xmit slot. */
  109. if ((avf->opmode == NL80211_IFTYPE_AP) ||
  110. (avf->opmode == NL80211_IFTYPE_ADHOC) ||
  111. (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
  112. int slot;
  113. WARN_ON(list_empty(&sc->bcbuf));
  114. avf->bbuf = list_first_entry(&sc->bcbuf, struct ath5k_buf,
  115. list);
  116. list_del(&avf->bbuf->list);
  117. avf->bslot = 0;
  118. for (slot = 0; slot < ATH_BCBUF; slot++) {
  119. if (!sc->bslot[slot]) {
  120. avf->bslot = slot;
  121. break;
  122. }
  123. }
  124. BUG_ON(sc->bslot[avf->bslot] != NULL);
  125. sc->bslot[avf->bslot] = vif;
  126. if (avf->opmode == NL80211_IFTYPE_AP)
  127. sc->num_ap_vifs++;
  128. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  129. sc->num_adhoc_vifs++;
  130. }
  131. /* Any MAC address is fine, all others are included through the
  132. * filter.
  133. */
  134. memcpy(&sc->lladdr, vif->addr, ETH_ALEN);
  135. ath5k_hw_set_lladdr(sc->ah, vif->addr);
  136. memcpy(&avf->lladdr, vif->addr, ETH_ALEN);
  137. ath5k_update_bssid_mask_and_opmode(sc, vif);
  138. ret = 0;
  139. end:
  140. mutex_unlock(&sc->lock);
  141. return ret;
  142. }
  143. static void
  144. ath5k_remove_interface(struct ieee80211_hw *hw,
  145. struct ieee80211_vif *vif)
  146. {
  147. struct ath5k_softc *sc = hw->priv;
  148. struct ath5k_vif *avf = (void *)vif->drv_priv;
  149. unsigned int i;
  150. mutex_lock(&sc->lock);
  151. sc->nvifs--;
  152. if (avf->bbuf) {
  153. ath5k_txbuf_free_skb(sc, avf->bbuf);
  154. list_add_tail(&avf->bbuf->list, &sc->bcbuf);
  155. for (i = 0; i < ATH_BCBUF; i++) {
  156. if (sc->bslot[i] == vif) {
  157. sc->bslot[i] = NULL;
  158. break;
  159. }
  160. }
  161. avf->bbuf = NULL;
  162. }
  163. if (avf->opmode == NL80211_IFTYPE_AP)
  164. sc->num_ap_vifs--;
  165. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  166. sc->num_adhoc_vifs--;
  167. ath5k_update_bssid_mask_and_opmode(sc, NULL);
  168. mutex_unlock(&sc->lock);
  169. }
  170. /*
  171. * TODO: Phy disable/diversity etc
  172. */
  173. static int
  174. ath5k_config(struct ieee80211_hw *hw, u32 changed)
  175. {
  176. struct ath5k_softc *sc = hw->priv;
  177. struct ath5k_hw *ah = sc->ah;
  178. struct ieee80211_conf *conf = &hw->conf;
  179. int ret = 0;
  180. int i;
  181. mutex_lock(&sc->lock);
  182. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  183. ret = ath5k_chan_set(sc, conf->channel);
  184. if (ret < 0)
  185. goto unlock;
  186. }
  187. if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
  188. (sc->power_level != conf->power_level)) {
  189. sc->power_level = conf->power_level;
  190. /* Half dB steps */
  191. ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
  192. }
  193. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  194. ah->ah_retry_long = conf->long_frame_max_tx_count;
  195. ah->ah_retry_short = conf->short_frame_max_tx_count;
  196. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
  197. ath5k_hw_set_tx_retry_limits(ah, i);
  198. }
  199. /* TODO:
  200. * 1) Move this on config_interface and handle each case
  201. * separately eg. when we have only one STA vif, use
  202. * AR5K_ANTMODE_SINGLE_AP
  203. *
  204. * 2) Allow the user to change antenna mode eg. when only
  205. * one antenna is present
  206. *
  207. * 3) Allow the user to set default/tx antenna when possible
  208. *
  209. * 4) Default mode should handle 90% of the cases, together
  210. * with fixed a/b and single AP modes we should be able to
  211. * handle 99%. Sectored modes are extreme cases and i still
  212. * haven't found a usage for them. If we decide to support them,
  213. * then we must allow the user to set how many tx antennas we
  214. * have available
  215. */
  216. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  217. unlock:
  218. mutex_unlock(&sc->lock);
  219. return ret;
  220. }
  221. static void
  222. ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  223. struct ieee80211_bss_conf *bss_conf, u32 changes)
  224. {
  225. struct ath5k_vif *avf = (void *)vif->drv_priv;
  226. struct ath5k_softc *sc = hw->priv;
  227. struct ath5k_hw *ah = sc->ah;
  228. struct ath_common *common = ath5k_hw_common(ah);
  229. unsigned long flags;
  230. mutex_lock(&sc->lock);
  231. if (changes & BSS_CHANGED_BSSID) {
  232. /* Cache for later use during resets */
  233. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  234. common->curaid = 0;
  235. ath5k_hw_set_bssid(ah);
  236. mmiowb();
  237. }
  238. if (changes & BSS_CHANGED_BEACON_INT)
  239. sc->bintval = bss_conf->beacon_int;
  240. if (changes & BSS_CHANGED_ERP_SLOT) {
  241. int slot_time;
  242. ah->ah_short_slot = bss_conf->use_short_slot;
  243. slot_time = ath5k_hw_get_default_slottime(ah) +
  244. 3 * ah->ah_coverage_class;
  245. ath5k_hw_set_ifs_intervals(ah, slot_time);
  246. }
  247. if (changes & BSS_CHANGED_ASSOC) {
  248. avf->assoc = bss_conf->assoc;
  249. if (bss_conf->assoc)
  250. sc->assoc = bss_conf->assoc;
  251. else
  252. sc->assoc = ath_any_vif_assoc(sc);
  253. if (sc->opmode == NL80211_IFTYPE_STATION)
  254. set_beacon_filter(hw, sc->assoc);
  255. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  256. AR5K_LED_ASSOC : AR5K_LED_INIT);
  257. if (bss_conf->assoc) {
  258. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  259. "Bss Info ASSOC %d, bssid: %pM\n",
  260. bss_conf->aid, common->curbssid);
  261. common->curaid = bss_conf->aid;
  262. ath5k_hw_set_bssid(ah);
  263. /* Once ANI is available you would start it here */
  264. }
  265. }
  266. if (changes & BSS_CHANGED_BEACON) {
  267. spin_lock_irqsave(&sc->block, flags);
  268. ath5k_beacon_update(hw, vif);
  269. spin_unlock_irqrestore(&sc->block, flags);
  270. }
  271. if (changes & BSS_CHANGED_BEACON_ENABLED)
  272. sc->enable_beacon = bss_conf->enable_beacon;
  273. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
  274. BSS_CHANGED_BEACON_INT))
  275. ath5k_beacon_config(sc);
  276. mutex_unlock(&sc->lock);
  277. }
  278. static u64
  279. ath5k_prepare_multicast(struct ieee80211_hw *hw,
  280. struct netdev_hw_addr_list *mc_list)
  281. {
  282. u32 mfilt[2], val;
  283. u8 pos;
  284. struct netdev_hw_addr *ha;
  285. mfilt[0] = 0;
  286. mfilt[1] = 1;
  287. netdev_hw_addr_list_for_each(ha, mc_list) {
  288. /* calculate XOR of eight 6-bit values */
  289. val = get_unaligned_le32(ha->addr + 0);
  290. pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  291. val = get_unaligned_le32(ha->addr + 3);
  292. pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  293. pos &= 0x3f;
  294. mfilt[pos / 32] |= (1 << (pos % 32));
  295. /* XXX: we might be able to just do this instead,
  296. * but not sure, needs testing, if we do use this we'd
  297. * neet to inform below to not reset the mcast */
  298. /* ath5k_hw_set_mcast_filterindex(ah,
  299. * ha->addr[5]); */
  300. }
  301. return ((u64)(mfilt[1]) << 32) | mfilt[0];
  302. }
  303. /*
  304. * o always accept unicast, broadcast, and multicast traffic
  305. * o multicast traffic for all BSSIDs will be enabled if mac80211
  306. * says it should be
  307. * o maintain current state of phy ofdm or phy cck error reception.
  308. * If the hardware detects any of these type of errors then
  309. * ath5k_hw_get_rx_filter() will pass to us the respective
  310. * hardware filters to be able to receive these type of frames.
  311. * o probe request frames are accepted only when operating in
  312. * hostap, adhoc, or monitor modes
  313. * o enable promiscuous mode according to the interface state
  314. * o accept beacons:
  315. * - when operating in adhoc mode so the 802.11 layer creates
  316. * node table entries for peers,
  317. * - when operating in station mode for collecting rssi data when
  318. * the station is otherwise quiet, or
  319. * - when scanning
  320. */
  321. static void
  322. ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  323. unsigned int *new_flags, u64 multicast)
  324. {
  325. #define SUPPORTED_FIF_FLAGS \
  326. (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
  327. FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
  328. FIF_BCN_PRBRESP_PROMISC)
  329. struct ath5k_softc *sc = hw->priv;
  330. struct ath5k_hw *ah = sc->ah;
  331. u32 mfilt[2], rfilt;
  332. struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
  333. mutex_lock(&sc->lock);
  334. mfilt[0] = multicast;
  335. mfilt[1] = multicast >> 32;
  336. /* Only deal with supported flags */
  337. changed_flags &= SUPPORTED_FIF_FLAGS;
  338. *new_flags &= SUPPORTED_FIF_FLAGS;
  339. /* If HW detects any phy or radar errors, leave those filters on.
  340. * Also, always enable Unicast, Broadcasts and Multicast
  341. * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
  342. rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
  343. (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
  344. AR5K_RX_FILTER_MCAST);
  345. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  346. if (*new_flags & FIF_PROMISC_IN_BSS)
  347. __set_bit(ATH_STAT_PROMISC, sc->status);
  348. else
  349. __clear_bit(ATH_STAT_PROMISC, sc->status);
  350. }
  351. if (test_bit(ATH_STAT_PROMISC, sc->status))
  352. rfilt |= AR5K_RX_FILTER_PROM;
  353. /* Note, AR5K_RX_FILTER_MCAST is already enabled */
  354. if (*new_flags & FIF_ALLMULTI) {
  355. mfilt[0] = ~0;
  356. mfilt[1] = ~0;
  357. }
  358. /* This is the best we can do */
  359. if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
  360. rfilt |= AR5K_RX_FILTER_PHYERR;
  361. /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
  362. * and probes for any BSSID */
  363. if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (sc->nvifs > 1))
  364. rfilt |= AR5K_RX_FILTER_BEACON;
  365. /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
  366. * set we should only pass on control frames for this
  367. * station. This needs testing. I believe right now this
  368. * enables *all* control frames, which is OK.. but
  369. * but we should see if we can improve on granularity */
  370. if (*new_flags & FIF_CONTROL)
  371. rfilt |= AR5K_RX_FILTER_CONTROL;
  372. /* Additional settings per mode -- this is per ath5k */
  373. /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
  374. switch (sc->opmode) {
  375. case NL80211_IFTYPE_MESH_POINT:
  376. rfilt |= AR5K_RX_FILTER_CONTROL |
  377. AR5K_RX_FILTER_BEACON |
  378. AR5K_RX_FILTER_PROBEREQ |
  379. AR5K_RX_FILTER_PROM;
  380. break;
  381. case NL80211_IFTYPE_AP:
  382. case NL80211_IFTYPE_ADHOC:
  383. rfilt |= AR5K_RX_FILTER_PROBEREQ |
  384. AR5K_RX_FILTER_BEACON;
  385. break;
  386. case NL80211_IFTYPE_STATION:
  387. if (sc->assoc)
  388. rfilt |= AR5K_RX_FILTER_BEACON;
  389. default:
  390. break;
  391. }
  392. iter_data.hw_macaddr = NULL;
  393. iter_data.n_stas = 0;
  394. iter_data.need_set_hw_addr = false;
  395. ieee80211_iterate_active_interfaces_atomic(sc->hw, ath5k_vif_iter,
  396. &iter_data);
  397. /* Set up RX Filter */
  398. if (iter_data.n_stas > 1) {
  399. /* If you have multiple STA interfaces connected to
  400. * different APs, ARPs are not received (most of the time?)
  401. * Enabling PROMISC appears to fix that probem.
  402. */
  403. rfilt |= AR5K_RX_FILTER_PROM;
  404. }
  405. /* Set filters */
  406. ath5k_hw_set_rx_filter(ah, rfilt);
  407. /* Set multicast bits */
  408. ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
  409. /* Set the cached hw filter flags, this will later actually
  410. * be set in HW */
  411. sc->filter_flags = rfilt;
  412. mutex_unlock(&sc->lock);
  413. }
  414. static int
  415. ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  416. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  417. struct ieee80211_key_conf *key)
  418. {
  419. struct ath5k_softc *sc = hw->priv;
  420. struct ath5k_hw *ah = sc->ah;
  421. struct ath_common *common = ath5k_hw_common(ah);
  422. int ret = 0;
  423. if (ath5k_modparam_nohwcrypt)
  424. return -EOPNOTSUPP;
  425. switch (key->cipher) {
  426. case WLAN_CIPHER_SUITE_WEP40:
  427. case WLAN_CIPHER_SUITE_WEP104:
  428. case WLAN_CIPHER_SUITE_TKIP:
  429. break;
  430. case WLAN_CIPHER_SUITE_CCMP:
  431. if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
  432. break;
  433. return -EOPNOTSUPP;
  434. default:
  435. WARN_ON(1);
  436. return -EINVAL;
  437. }
  438. mutex_lock(&sc->lock);
  439. switch (cmd) {
  440. case SET_KEY:
  441. ret = ath_key_config(common, vif, sta, key);
  442. if (ret >= 0) {
  443. key->hw_key_idx = ret;
  444. /* push IV and Michael MIC generation to stack */
  445. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  446. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  447. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  448. if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
  449. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  450. ret = 0;
  451. }
  452. break;
  453. case DISABLE_KEY:
  454. ath_key_delete(common, key);
  455. break;
  456. default:
  457. ret = -EINVAL;
  458. }
  459. mmiowb();
  460. mutex_unlock(&sc->lock);
  461. return ret;
  462. }
  463. static void
  464. ath5k_sw_scan_start(struct ieee80211_hw *hw)
  465. {
  466. struct ath5k_softc *sc = hw->priv;
  467. if (!sc->assoc)
  468. ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
  469. }
  470. static void
  471. ath5k_sw_scan_complete(struct ieee80211_hw *hw)
  472. {
  473. struct ath5k_softc *sc = hw->priv;
  474. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  475. AR5K_LED_ASSOC : AR5K_LED_INIT);
  476. }
  477. static int
  478. ath5k_get_stats(struct ieee80211_hw *hw,
  479. struct ieee80211_low_level_stats *stats)
  480. {
  481. struct ath5k_softc *sc = hw->priv;
  482. /* Force update */
  483. ath5k_hw_update_mib_counters(sc->ah);
  484. stats->dot11ACKFailureCount = sc->stats.ack_fail;
  485. stats->dot11RTSFailureCount = sc->stats.rts_fail;
  486. stats->dot11RTSSuccessCount = sc->stats.rts_ok;
  487. stats->dot11FCSErrorCount = sc->stats.fcs_error;
  488. return 0;
  489. }
  490. static int
  491. ath5k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  492. const struct ieee80211_tx_queue_params *params)
  493. {
  494. struct ath5k_softc *sc = hw->priv;
  495. struct ath5k_hw *ah = sc->ah;
  496. struct ath5k_txq_info qi;
  497. int ret = 0;
  498. if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
  499. return 0;
  500. mutex_lock(&sc->lock);
  501. ath5k_hw_get_tx_queueprops(ah, queue, &qi);
  502. qi.tqi_aifs = params->aifs;
  503. qi.tqi_cw_min = params->cw_min;
  504. qi.tqi_cw_max = params->cw_max;
  505. qi.tqi_burst_time = params->txop;
  506. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  507. "Configure tx [queue %d], "
  508. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  509. queue, params->aifs, params->cw_min,
  510. params->cw_max, params->txop);
  511. if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
  512. ATH5K_ERR(sc,
  513. "Unable to update hardware queue %u!\n", queue);
  514. ret = -EIO;
  515. } else
  516. ath5k_hw_reset_tx_queue(ah, queue);
  517. mutex_unlock(&sc->lock);
  518. return ret;
  519. }
  520. static u64
  521. ath5k_get_tsf(struct ieee80211_hw *hw)
  522. {
  523. struct ath5k_softc *sc = hw->priv;
  524. return ath5k_hw_get_tsf64(sc->ah);
  525. }
  526. static void
  527. ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  528. {
  529. struct ath5k_softc *sc = hw->priv;
  530. ath5k_hw_set_tsf64(sc->ah, tsf);
  531. }
  532. static void
  533. ath5k_reset_tsf(struct ieee80211_hw *hw)
  534. {
  535. struct ath5k_softc *sc = hw->priv;
  536. /*
  537. * in IBSS mode we need to update the beacon timers too.
  538. * this will also reset the TSF if we call it with 0
  539. */
  540. if (sc->opmode == NL80211_IFTYPE_ADHOC)
  541. ath5k_beacon_update_timers(sc, 0);
  542. else
  543. ath5k_hw_reset_tsf(sc->ah);
  544. }
  545. static int
  546. ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
  547. {
  548. struct ath5k_softc *sc = hw->priv;
  549. struct ieee80211_conf *conf = &hw->conf;
  550. struct ath_common *common = ath5k_hw_common(sc->ah);
  551. struct ath_cycle_counters *cc = &common->cc_survey;
  552. unsigned int div = common->clockrate * 1000;
  553. if (idx != 0)
  554. return -ENOENT;
  555. spin_lock_bh(&common->cc_lock);
  556. ath_hw_cycle_counters_update(common);
  557. if (cc->cycles > 0) {
  558. sc->survey.channel_time += cc->cycles / div;
  559. sc->survey.channel_time_busy += cc->rx_busy / div;
  560. sc->survey.channel_time_rx += cc->rx_frame / div;
  561. sc->survey.channel_time_tx += cc->tx_frame / div;
  562. }
  563. memset(cc, 0, sizeof(*cc));
  564. spin_unlock_bh(&common->cc_lock);
  565. memcpy(survey, &sc->survey, sizeof(*survey));
  566. survey->channel = conf->channel;
  567. survey->noise = sc->ah->ah_noise_floor;
  568. survey->filled = SURVEY_INFO_NOISE_DBM |
  569. SURVEY_INFO_CHANNEL_TIME |
  570. SURVEY_INFO_CHANNEL_TIME_BUSY |
  571. SURVEY_INFO_CHANNEL_TIME_RX |
  572. SURVEY_INFO_CHANNEL_TIME_TX;
  573. return 0;
  574. }
  575. /**
  576. * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
  577. *
  578. * @hw: struct ieee80211_hw pointer
  579. * @coverage_class: IEEE 802.11 coverage class number
  580. *
  581. * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
  582. * coverage class. The values are persistent, they are restored after device
  583. * reset.
  584. */
  585. static void
  586. ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  587. {
  588. struct ath5k_softc *sc = hw->priv;
  589. mutex_lock(&sc->lock);
  590. ath5k_hw_set_coverage_class(sc->ah, coverage_class);
  591. mutex_unlock(&sc->lock);
  592. }
  593. static int
  594. ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  595. {
  596. struct ath5k_softc *sc = hw->priv;
  597. if (tx_ant == 1 && rx_ant == 1)
  598. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
  599. else if (tx_ant == 2 && rx_ant == 2)
  600. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
  601. else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
  602. ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
  603. else
  604. return -EINVAL;
  605. return 0;
  606. }
  607. static int
  608. ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  609. {
  610. struct ath5k_softc *sc = hw->priv;
  611. switch (sc->ah->ah_ant_mode) {
  612. case AR5K_ANTMODE_FIXED_A:
  613. *tx_ant = 1; *rx_ant = 1; break;
  614. case AR5K_ANTMODE_FIXED_B:
  615. *tx_ant = 2; *rx_ant = 2; break;
  616. case AR5K_ANTMODE_DEFAULT:
  617. *tx_ant = 3; *rx_ant = 3; break;
  618. }
  619. return 0;
  620. }
  621. static void ath5k_get_ringparam(struct ieee80211_hw *hw,
  622. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  623. {
  624. struct ath5k_softc *sc = hw->priv;
  625. *tx = sc->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
  626. *tx_max = ATH5K_TXQ_LEN_MAX;
  627. *rx = *rx_max = ATH_RXBUF;
  628. }
  629. static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
  630. {
  631. struct ath5k_softc *sc = hw->priv;
  632. u16 qnum;
  633. /* only support setting tx ring size for now */
  634. if (rx != ATH_RXBUF)
  635. return -EINVAL;
  636. /* restrict tx ring size min/max */
  637. if (!tx || tx > ATH5K_TXQ_LEN_MAX)
  638. return -EINVAL;
  639. for (qnum = 0; qnum < ARRAY_SIZE(sc->txqs); qnum++) {
  640. if (!sc->txqs[qnum].setup)
  641. continue;
  642. if (sc->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
  643. sc->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
  644. continue;
  645. sc->txqs[qnum].txq_max = tx;
  646. if (sc->txqs[qnum].txq_len >= sc->txqs[qnum].txq_max)
  647. ieee80211_stop_queue(hw, sc->txqs[qnum].qnum);
  648. }
  649. return 0;
  650. }
  651. const struct ieee80211_ops ath5k_hw_ops = {
  652. .tx = ath5k_tx,
  653. .start = ath5k_start,
  654. .stop = ath5k_stop,
  655. .add_interface = ath5k_add_interface,
  656. /* .change_interface = not implemented */
  657. .remove_interface = ath5k_remove_interface,
  658. .config = ath5k_config,
  659. .bss_info_changed = ath5k_bss_info_changed,
  660. .prepare_multicast = ath5k_prepare_multicast,
  661. .configure_filter = ath5k_configure_filter,
  662. /* .set_tim = not implemented */
  663. .set_key = ath5k_set_key,
  664. /* .update_tkip_key = not implemented */
  665. /* .hw_scan = not implemented */
  666. .sw_scan_start = ath5k_sw_scan_start,
  667. .sw_scan_complete = ath5k_sw_scan_complete,
  668. .get_stats = ath5k_get_stats,
  669. /* .get_tkip_seq = not implemented */
  670. /* .set_frag_threshold = not implemented */
  671. /* .set_rts_threshold = not implemented */
  672. /* .sta_add = not implemented */
  673. /* .sta_remove = not implemented */
  674. /* .sta_notify = not implemented */
  675. .conf_tx = ath5k_conf_tx,
  676. .get_tsf = ath5k_get_tsf,
  677. .set_tsf = ath5k_set_tsf,
  678. .reset_tsf = ath5k_reset_tsf,
  679. /* .tx_last_beacon = not implemented */
  680. /* .ampdu_action = not needed */
  681. .get_survey = ath5k_get_survey,
  682. .set_coverage_class = ath5k_set_coverage_class,
  683. /* .rfkill_poll = not implemented */
  684. /* .flush = not implemented */
  685. /* .channel_switch = not implemented */
  686. /* .napi_poll = not implemented */
  687. .set_antenna = ath5k_set_antenna,
  688. .get_antenna = ath5k_get_antenna,
  689. .set_ringparam = ath5k_set_ringparam,
  690. .get_ringparam = ath5k_get_ringparam,
  691. };