mac80211-ops.c 21 KB

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