rt2x00mac.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00mac
  19. Abstract: rt2x00 generic mac80211 routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
  26. struct data_queue *queue,
  27. struct sk_buff *frag_skb)
  28. {
  29. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(frag_skb);
  30. struct ieee80211_tx_info *rts_info;
  31. struct sk_buff *skb;
  32. unsigned int data_length;
  33. int retval = 0;
  34. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  35. data_length = sizeof(struct ieee80211_cts);
  36. else
  37. data_length = sizeof(struct ieee80211_rts);
  38. skb = dev_alloc_skb(data_length + rt2x00dev->hw->extra_tx_headroom);
  39. if (unlikely(!skb)) {
  40. WARNING(rt2x00dev, "Failed to create RTS/CTS frame.\n");
  41. return -ENOMEM;
  42. }
  43. skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom);
  44. skb_put(skb, data_length);
  45. /*
  46. * Copy TX information over from original frame to
  47. * RTS/CTS frame. Note that we set the no encryption flag
  48. * since we don't want this frame to be encrypted.
  49. * RTS frames should be acked, while CTS-to-self frames
  50. * should not. The ready for TX flag is cleared to prevent
  51. * it being automatically send when the descriptor is
  52. * written to the hardware.
  53. */
  54. memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb));
  55. rts_info = IEEE80211_SKB_CB(skb);
  56. rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_RTS_CTS;
  57. rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_CTS_PROTECT;
  58. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  59. rts_info->flags |= IEEE80211_TX_CTL_NO_ACK;
  60. else
  61. rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
  62. /* Disable hardware encryption */
  63. rts_info->control.hw_key = NULL;
  64. /*
  65. * RTS/CTS frame should use the length of the frame plus any
  66. * encryption overhead that will be added by the hardware.
  67. */
  68. data_length += rt2x00crypto_tx_overhead(rt2x00dev, skb);
  69. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  70. ieee80211_ctstoself_get(rt2x00dev->hw, tx_info->control.vif,
  71. frag_skb->data, data_length, tx_info,
  72. (struct ieee80211_cts *)(skb->data));
  73. else
  74. ieee80211_rts_get(rt2x00dev->hw, tx_info->control.vif,
  75. frag_skb->data, data_length, tx_info,
  76. (struct ieee80211_rts *)(skb->data));
  77. retval = rt2x00queue_write_tx_frame(queue, skb, true);
  78. if (retval) {
  79. dev_kfree_skb_any(skb);
  80. WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n");
  81. }
  82. return retval;
  83. }
  84. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  85. {
  86. struct rt2x00_dev *rt2x00dev = hw->priv;
  87. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  88. enum data_queue_qid qid = skb_get_queue_mapping(skb);
  89. struct data_queue *queue;
  90. /*
  91. * Mac80211 might be calling this function while we are trying
  92. * to remove the device or perhaps suspending it.
  93. * Note that we can only stop the TX queues inside the TX path
  94. * due to possible race conditions in mac80211.
  95. */
  96. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  97. goto exit_fail;
  98. /*
  99. * Determine which queue to put packet on.
  100. */
  101. if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM &&
  102. test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags))
  103. queue = rt2x00queue_get_queue(rt2x00dev, QID_ATIM);
  104. else
  105. queue = rt2x00queue_get_queue(rt2x00dev, qid);
  106. if (unlikely(!queue)) {
  107. ERROR(rt2x00dev,
  108. "Attempt to send packet over invalid queue %d.\n"
  109. "Please file bug report to %s.\n", qid, DRV_PROJECT);
  110. goto exit_fail;
  111. }
  112. /*
  113. * If CTS/RTS is required. create and queue that frame first.
  114. * Make sure we have at least enough entries available to send
  115. * this CTS/RTS frame as well as the data frame.
  116. * Note that when the driver has set the set_rts_threshold()
  117. * callback function it doesn't need software generation of
  118. * either RTS or CTS-to-self frame and handles everything
  119. * inside the hardware.
  120. */
  121. if ((tx_info->control.rates[0].flags & (IEEE80211_TX_RC_USE_RTS_CTS |
  122. IEEE80211_TX_RC_USE_CTS_PROTECT)) &&
  123. !rt2x00dev->ops->hw->set_rts_threshold) {
  124. if (rt2x00queue_available(queue) <= 1)
  125. goto exit_fail;
  126. if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb))
  127. goto exit_fail;
  128. }
  129. if (rt2x00queue_write_tx_frame(queue, skb, false))
  130. goto exit_fail;
  131. if (rt2x00queue_threshold(queue))
  132. ieee80211_stop_queue(rt2x00dev->hw, qid);
  133. return NETDEV_TX_OK;
  134. exit_fail:
  135. ieee80211_stop_queue(rt2x00dev->hw, qid);
  136. dev_kfree_skb_any(skb);
  137. return NETDEV_TX_OK;
  138. }
  139. EXPORT_SYMBOL_GPL(rt2x00mac_tx);
  140. int rt2x00mac_start(struct ieee80211_hw *hw)
  141. {
  142. struct rt2x00_dev *rt2x00dev = hw->priv;
  143. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  144. return 0;
  145. return rt2x00lib_start(rt2x00dev);
  146. }
  147. EXPORT_SYMBOL_GPL(rt2x00mac_start);
  148. void rt2x00mac_stop(struct ieee80211_hw *hw)
  149. {
  150. struct rt2x00_dev *rt2x00dev = hw->priv;
  151. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  152. return;
  153. rt2x00lib_stop(rt2x00dev);
  154. }
  155. EXPORT_SYMBOL_GPL(rt2x00mac_stop);
  156. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  157. struct ieee80211_if_init_conf *conf)
  158. {
  159. struct rt2x00_dev *rt2x00dev = hw->priv;
  160. struct rt2x00_intf *intf = vif_to_intf(conf->vif);
  161. struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, QID_BEACON);
  162. struct queue_entry *entry = NULL;
  163. unsigned int i;
  164. /*
  165. * Don't allow interfaces to be added
  166. * the device has disappeared.
  167. */
  168. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
  169. !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
  170. return -ENODEV;
  171. switch (conf->type) {
  172. case NL80211_IFTYPE_AP:
  173. /*
  174. * We don't support mixed combinations of
  175. * sta and ap interfaces.
  176. */
  177. if (rt2x00dev->intf_sta_count)
  178. return -ENOBUFS;
  179. /*
  180. * Check if we exceeded the maximum amount
  181. * of supported interfaces.
  182. */
  183. if (rt2x00dev->intf_ap_count >= rt2x00dev->ops->max_ap_intf)
  184. return -ENOBUFS;
  185. break;
  186. case NL80211_IFTYPE_STATION:
  187. case NL80211_IFTYPE_ADHOC:
  188. case NL80211_IFTYPE_MESH_POINT:
  189. case NL80211_IFTYPE_WDS:
  190. /*
  191. * We don't support mixed combinations of
  192. * sta and ap interfaces.
  193. */
  194. if (rt2x00dev->intf_ap_count)
  195. return -ENOBUFS;
  196. /*
  197. * Check if we exceeded the maximum amount
  198. * of supported interfaces.
  199. */
  200. if (rt2x00dev->intf_sta_count >= rt2x00dev->ops->max_sta_intf)
  201. return -ENOBUFS;
  202. break;
  203. default:
  204. return -EINVAL;
  205. }
  206. /*
  207. * Loop through all beacon queues to find a free
  208. * entry. Since there are as much beacon entries
  209. * as the maximum interfaces, this search shouldn't
  210. * fail.
  211. */
  212. for (i = 0; i < queue->limit; i++) {
  213. entry = &queue->entries[i];
  214. if (!test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags))
  215. break;
  216. }
  217. if (unlikely(i == queue->limit))
  218. return -ENOBUFS;
  219. /*
  220. * We are now absolutely sure the interface can be created,
  221. * increase interface count and start initialization.
  222. */
  223. if (conf->type == NL80211_IFTYPE_AP)
  224. rt2x00dev->intf_ap_count++;
  225. else
  226. rt2x00dev->intf_sta_count++;
  227. spin_lock_init(&intf->lock);
  228. spin_lock_init(&intf->seqlock);
  229. mutex_init(&intf->beacon_skb_mutex);
  230. intf->beacon = entry;
  231. if (conf->type == NL80211_IFTYPE_AP)
  232. memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN);
  233. memcpy(&intf->mac, conf->mac_addr, ETH_ALEN);
  234. /*
  235. * The MAC adddress must be configured after the device
  236. * has been initialized. Otherwise the device can reset
  237. * the MAC registers.
  238. */
  239. rt2x00lib_config_intf(rt2x00dev, intf, conf->type, intf->mac, NULL);
  240. /*
  241. * Some filters depend on the current working mode. We can force
  242. * an update during the next configure_filter() run by mac80211 by
  243. * resetting the current packet_filter state.
  244. */
  245. rt2x00dev->packet_filter = 0;
  246. return 0;
  247. }
  248. EXPORT_SYMBOL_GPL(rt2x00mac_add_interface);
  249. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  250. struct ieee80211_if_init_conf *conf)
  251. {
  252. struct rt2x00_dev *rt2x00dev = hw->priv;
  253. struct rt2x00_intf *intf = vif_to_intf(conf->vif);
  254. /*
  255. * Don't allow interfaces to be remove while
  256. * either the device has disappeared or when
  257. * no interface is present.
  258. */
  259. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
  260. (conf->type == NL80211_IFTYPE_AP && !rt2x00dev->intf_ap_count) ||
  261. (conf->type != NL80211_IFTYPE_AP && !rt2x00dev->intf_sta_count))
  262. return;
  263. if (conf->type == NL80211_IFTYPE_AP)
  264. rt2x00dev->intf_ap_count--;
  265. else
  266. rt2x00dev->intf_sta_count--;
  267. /*
  268. * Release beacon entry so it is available for
  269. * new interfaces again.
  270. */
  271. clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags);
  272. /*
  273. * Make sure the bssid and mac address registers
  274. * are cleared to prevent false ACKing of frames.
  275. */
  276. rt2x00lib_config_intf(rt2x00dev, intf,
  277. NL80211_IFTYPE_UNSPECIFIED, NULL, NULL);
  278. }
  279. EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface);
  280. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
  281. {
  282. struct rt2x00_dev *rt2x00dev = hw->priv;
  283. struct ieee80211_conf *conf = &hw->conf;
  284. /*
  285. * mac80211 might be calling this function while we are trying
  286. * to remove the device or perhaps suspending it.
  287. */
  288. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  289. return 0;
  290. /*
  291. * Some configuration parameters (e.g. channel and antenna values) can
  292. * only be set when the radio is enabled, but do require the RX to
  293. * be off.
  294. */
  295. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
  296. /*
  297. * When we've just turned on the radio, we want to reprogram
  298. * everything to ensure a consistent state
  299. */
  300. rt2x00lib_config(rt2x00dev, conf, changed);
  301. /*
  302. * After the radio has been enabled we need to configure
  303. * the antenna to the default settings. rt2x00lib_config_antenna()
  304. * should determine if any action should be taken based on
  305. * checking if diversity has been enabled or no antenna changes
  306. * have been made since the last configuration change.
  307. */
  308. rt2x00lib_config_antenna(rt2x00dev, rt2x00dev->default_ant);
  309. /* Turn RX back on */
  310. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
  311. return 0;
  312. }
  313. EXPORT_SYMBOL_GPL(rt2x00mac_config);
  314. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  315. unsigned int changed_flags,
  316. unsigned int *total_flags,
  317. u64 multicast)
  318. {
  319. struct rt2x00_dev *rt2x00dev = hw->priv;
  320. /*
  321. * Mask off any flags we are going to ignore
  322. * from the total_flags field.
  323. */
  324. *total_flags &=
  325. FIF_ALLMULTI |
  326. FIF_FCSFAIL |
  327. FIF_PLCPFAIL |
  328. FIF_CONTROL |
  329. FIF_PSPOLL |
  330. FIF_OTHER_BSS |
  331. FIF_PROMISC_IN_BSS;
  332. /*
  333. * Apply some rules to the filters:
  334. * - Some filters imply different filters to be set.
  335. * - Some things we can't filter out at all.
  336. * - Multicast filter seems to kill broadcast traffic so never use it.
  337. */
  338. *total_flags |= FIF_ALLMULTI;
  339. if (*total_flags & FIF_OTHER_BSS ||
  340. *total_flags & FIF_PROMISC_IN_BSS)
  341. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  342. /*
  343. * If the device has a single filter for all control frames,
  344. * FIF_CONTROL and FIF_PSPOLL flags imply each other.
  345. * And if the device has more than one filter for control frames
  346. * of different types, but has no a separate filter for PS Poll frames,
  347. * FIF_CONTROL flag implies FIF_PSPOLL.
  348. */
  349. if (!test_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags)) {
  350. if (*total_flags & FIF_CONTROL || *total_flags & FIF_PSPOLL)
  351. *total_flags |= FIF_CONTROL | FIF_PSPOLL;
  352. }
  353. if (!test_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags)) {
  354. if (*total_flags & FIF_CONTROL)
  355. *total_flags |= FIF_PSPOLL;
  356. }
  357. /*
  358. * Check if there is any work left for us.
  359. */
  360. if (rt2x00dev->packet_filter == *total_flags)
  361. return;
  362. rt2x00dev->packet_filter = *total_flags;
  363. rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags);
  364. }
  365. EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter);
  366. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  367. bool set)
  368. {
  369. struct rt2x00_dev *rt2x00dev = hw->priv;
  370. rt2x00lib_beacondone(rt2x00dev);
  371. return 0;
  372. }
  373. EXPORT_SYMBOL_GPL(rt2x00mac_set_tim);
  374. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  375. static void memcpy_tkip(struct rt2x00lib_crypto *crypto, u8 *key, u8 key_len)
  376. {
  377. if (key_len > NL80211_TKIP_DATA_OFFSET_ENCR_KEY)
  378. memcpy(&crypto->key,
  379. &key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY],
  380. sizeof(crypto->key));
  381. if (key_len > NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY)
  382. memcpy(&crypto->tx_mic,
  383. &key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
  384. sizeof(crypto->tx_mic));
  385. if (key_len > NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY)
  386. memcpy(&crypto->rx_mic,
  387. &key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
  388. sizeof(crypto->rx_mic));
  389. }
  390. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  391. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  392. struct ieee80211_key_conf *key)
  393. {
  394. struct rt2x00_dev *rt2x00dev = hw->priv;
  395. struct rt2x00_intf *intf = vif_to_intf(vif);
  396. int (*set_key) (struct rt2x00_dev *rt2x00dev,
  397. struct rt2x00lib_crypto *crypto,
  398. struct ieee80211_key_conf *key);
  399. struct rt2x00lib_crypto crypto;
  400. static const u8 bcast_addr[ETH_ALEN] =
  401. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
  402. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  403. return 0;
  404. else if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
  405. return -EOPNOTSUPP;
  406. else if (key->keylen > 32)
  407. return -ENOSPC;
  408. memset(&crypto, 0, sizeof(crypto));
  409. /*
  410. * When in STA mode, bssidx is always 0 otherwise local_address[5]
  411. * contains the bss number, see BSS_ID_MASK comments for details.
  412. */
  413. if (rt2x00dev->intf_sta_count)
  414. crypto.bssidx = 0;
  415. else
  416. crypto.bssidx = intf->mac[5] & (rt2x00dev->ops->max_ap_intf - 1);
  417. crypto.cipher = rt2x00crypto_key_to_cipher(key);
  418. if (crypto.cipher == CIPHER_NONE)
  419. return -EOPNOTSUPP;
  420. crypto.cmd = cmd;
  421. if (sta) {
  422. /* some drivers need the AID */
  423. crypto.aid = sta->aid;
  424. crypto.address = sta->addr;
  425. } else
  426. crypto.address = bcast_addr;
  427. if (crypto.cipher == CIPHER_TKIP)
  428. memcpy_tkip(&crypto, &key->key[0], key->keylen);
  429. else
  430. memcpy(&crypto.key, &key->key[0], key->keylen);
  431. /*
  432. * Each BSS has a maximum of 4 shared keys.
  433. * Shared key index values:
  434. * 0) BSS0 key0
  435. * 1) BSS0 key1
  436. * ...
  437. * 4) BSS1 key0
  438. * ...
  439. * 8) BSS2 key0
  440. * ...
  441. * Both pairwise as shared key indeces are determined by
  442. * driver. This is required because the hardware requires
  443. * keys to be assigned in correct order (When key 1 is
  444. * provided but key 0 is not, then the key is not found
  445. * by the hardware during RX).
  446. */
  447. if (cmd == SET_KEY)
  448. key->hw_key_idx = 0;
  449. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  450. set_key = rt2x00dev->ops->lib->config_pairwise_key;
  451. else
  452. set_key = rt2x00dev->ops->lib->config_shared_key;
  453. if (!set_key)
  454. return -EOPNOTSUPP;
  455. return set_key(rt2x00dev, &crypto, key);
  456. }
  457. EXPORT_SYMBOL_GPL(rt2x00mac_set_key);
  458. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  459. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  460. struct ieee80211_low_level_stats *stats)
  461. {
  462. struct rt2x00_dev *rt2x00dev = hw->priv;
  463. /*
  464. * The dot11ACKFailureCount, dot11RTSFailureCount and
  465. * dot11RTSSuccessCount are updated in interrupt time.
  466. * dot11FCSErrorCount is updated in the link tuner.
  467. */
  468. memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats));
  469. return 0;
  470. }
  471. EXPORT_SYMBOL_GPL(rt2x00mac_get_stats);
  472. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  473. struct ieee80211_tx_queue_stats *stats)
  474. {
  475. struct rt2x00_dev *rt2x00dev = hw->priv;
  476. unsigned int i;
  477. for (i = 0; i < rt2x00dev->ops->tx_queues; i++) {
  478. stats[i].len = rt2x00dev->tx[i].length;
  479. stats[i].limit = rt2x00dev->tx[i].limit;
  480. stats[i].count = rt2x00dev->tx[i].count;
  481. }
  482. return 0;
  483. }
  484. EXPORT_SYMBOL_GPL(rt2x00mac_get_tx_stats);
  485. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  486. struct ieee80211_vif *vif,
  487. struct ieee80211_bss_conf *bss_conf,
  488. u32 changes)
  489. {
  490. struct rt2x00_dev *rt2x00dev = hw->priv;
  491. struct rt2x00_intf *intf = vif_to_intf(vif);
  492. int update_bssid = 0;
  493. /*
  494. * mac80211 might be calling this function while we are trying
  495. * to remove the device or perhaps suspending it.
  496. */
  497. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  498. return;
  499. spin_lock(&intf->lock);
  500. /*
  501. * conf->bssid can be NULL if coming from the internal
  502. * beacon update routine.
  503. */
  504. if (changes & BSS_CHANGED_BSSID) {
  505. update_bssid = 1;
  506. memcpy(&intf->bssid, bss_conf->bssid, ETH_ALEN);
  507. }
  508. spin_unlock(&intf->lock);
  509. /*
  510. * Call rt2x00_config_intf() outside of the spinlock context since
  511. * the call will sleep for USB drivers. By using the ieee80211_if_conf
  512. * values as arguments we make keep access to rt2x00_intf thread safe
  513. * even without the lock.
  514. */
  515. if (changes & BSS_CHANGED_BSSID)
  516. rt2x00lib_config_intf(rt2x00dev, intf, vif->type, NULL,
  517. update_bssid ? bss_conf->bssid : NULL);
  518. /*
  519. * Update the beacon.
  520. */
  521. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED))
  522. rt2x00queue_update_beacon(rt2x00dev, vif,
  523. bss_conf->enable_beacon);
  524. /*
  525. * When the association status has changed we must reset the link
  526. * tuner counter. This is because some drivers determine if they
  527. * should perform link tuning based on the number of seconds
  528. * while associated or not associated.
  529. */
  530. if (changes & BSS_CHANGED_ASSOC) {
  531. rt2x00dev->link.count = 0;
  532. if (bss_conf->assoc)
  533. rt2x00dev->intf_associated++;
  534. else
  535. rt2x00dev->intf_associated--;
  536. rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
  537. }
  538. /*
  539. * When the erp information has changed, we should perform
  540. * additional configuration steps. For all other changes we are done.
  541. */
  542. if (changes & ~(BSS_CHANGED_ASSOC | BSS_CHANGED_HT))
  543. rt2x00lib_config_erp(rt2x00dev, intf, bss_conf);
  544. }
  545. EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed);
  546. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  547. const struct ieee80211_tx_queue_params *params)
  548. {
  549. struct rt2x00_dev *rt2x00dev = hw->priv;
  550. struct data_queue *queue;
  551. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  552. if (unlikely(!queue))
  553. return -EINVAL;
  554. /*
  555. * The passed variables are stored as real value ((2^n)-1).
  556. * Ralink registers require to know the bit number 'n'.
  557. */
  558. if (params->cw_min > 0)
  559. queue->cw_min = fls(params->cw_min);
  560. else
  561. queue->cw_min = 5; /* cw_min: 2^5 = 32. */
  562. if (params->cw_max > 0)
  563. queue->cw_max = fls(params->cw_max);
  564. else
  565. queue->cw_max = 10; /* cw_min: 2^10 = 1024. */
  566. queue->aifs = params->aifs;
  567. queue->txop = params->txop;
  568. INFO(rt2x00dev,
  569. "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d, TXop: %d.\n",
  570. queue_idx, queue->cw_min, queue->cw_max, queue->aifs, queue->txop);
  571. return 0;
  572. }
  573. EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx);
  574. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw)
  575. {
  576. struct rt2x00_dev *rt2x00dev = hw->priv;
  577. bool active = !!rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
  578. wiphy_rfkill_set_hw_state(hw->wiphy, !active);
  579. }
  580. EXPORT_SYMBOL_GPL(rt2x00mac_rfkill_poll);