mac80211-ops.c 22 KB

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