rt2x00dev.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  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: rt2x00lib
  19. Abstract: rt2x00 generic device routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. /*
  26. * Link tuning handlers
  27. */
  28. void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
  29. {
  30. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  31. return;
  32. /*
  33. * Reset link information.
  34. * Both the currently active vgc level as well as
  35. * the link tuner counter should be reset. Resetting
  36. * the counter is important for devices where the
  37. * device should only perform link tuning during the
  38. * first minute after being enabled.
  39. */
  40. rt2x00dev->link.count = 0;
  41. rt2x00dev->link.vgc_level = 0;
  42. /*
  43. * Reset the link tuner.
  44. */
  45. rt2x00dev->ops->lib->reset_tuner(rt2x00dev);
  46. }
  47. static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
  48. {
  49. /*
  50. * Clear all (possibly) pre-existing quality statistics.
  51. */
  52. memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual));
  53. /*
  54. * The RX and TX percentage should start at 50%
  55. * this will assure we will get at least get some
  56. * decent value when the link tuner starts.
  57. * The value will be dropped and overwritten with
  58. * the correct (measured )value anyway during the
  59. * first run of the link tuner.
  60. */
  61. rt2x00dev->link.qual.rx_percentage = 50;
  62. rt2x00dev->link.qual.tx_percentage = 50;
  63. rt2x00lib_reset_link_tuner(rt2x00dev);
  64. queue_delayed_work(rt2x00dev->hw->workqueue,
  65. &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
  66. }
  67. static void rt2x00lib_stop_link_tuner(struct rt2x00_dev *rt2x00dev)
  68. {
  69. cancel_delayed_work_sync(&rt2x00dev->link.work);
  70. }
  71. /*
  72. * Radio control handlers.
  73. */
  74. int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
  75. {
  76. int status;
  77. /*
  78. * Don't enable the radio twice.
  79. * And check if the hardware button has been disabled.
  80. */
  81. if (test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
  82. test_bit(DEVICE_DISABLED_RADIO_HW, &rt2x00dev->flags))
  83. return 0;
  84. /*
  85. * Initialize all data queues.
  86. */
  87. rt2x00queue_init_rx(rt2x00dev);
  88. rt2x00queue_init_tx(rt2x00dev);
  89. /*
  90. * Enable radio.
  91. */
  92. status =
  93. rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_ON);
  94. if (status)
  95. return status;
  96. rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON);
  97. rt2x00leds_led_radio(rt2x00dev, true);
  98. rt2x00led_led_activity(rt2x00dev, true);
  99. __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
  100. /*
  101. * Enable RX.
  102. */
  103. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
  104. /*
  105. * Start the TX queues.
  106. */
  107. ieee80211_wake_queues(rt2x00dev->hw);
  108. return 0;
  109. }
  110. void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
  111. {
  112. if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  113. return;
  114. /*
  115. * Stop the TX queues.
  116. */
  117. ieee80211_stop_queues(rt2x00dev->hw);
  118. /*
  119. * Disable RX.
  120. */
  121. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
  122. /*
  123. * Disable radio.
  124. */
  125. rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
  126. rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);
  127. rt2x00led_led_activity(rt2x00dev, false);
  128. rt2x00leds_led_radio(rt2x00dev, false);
  129. }
  130. void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  131. {
  132. /*
  133. * When we are disabling the RX, we should also stop the link tuner.
  134. */
  135. if (state == STATE_RADIO_RX_OFF)
  136. rt2x00lib_stop_link_tuner(rt2x00dev);
  137. rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  138. /*
  139. * When we are enabling the RX, we should also start the link tuner.
  140. */
  141. if (state == STATE_RADIO_RX_ON &&
  142. (rt2x00dev->intf_ap_count || rt2x00dev->intf_sta_count))
  143. rt2x00lib_start_link_tuner(rt2x00dev);
  144. }
  145. static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev *rt2x00dev)
  146. {
  147. enum antenna rx = rt2x00dev->link.ant.active.rx;
  148. enum antenna tx = rt2x00dev->link.ant.active.tx;
  149. int sample_a =
  150. rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_A);
  151. int sample_b =
  152. rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_B);
  153. /*
  154. * We are done sampling. Now we should evaluate the results.
  155. */
  156. rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE;
  157. /*
  158. * During the last period we have sampled the RSSI
  159. * from both antenna's. It now is time to determine
  160. * which antenna demonstrated the best performance.
  161. * When we are already on the antenna with the best
  162. * performance, then there really is nothing for us
  163. * left to do.
  164. */
  165. if (sample_a == sample_b)
  166. return;
  167. if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
  168. rx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
  169. if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
  170. tx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
  171. rt2x00lib_config_antenna(rt2x00dev, rx, tx);
  172. }
  173. static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev *rt2x00dev)
  174. {
  175. enum antenna rx = rt2x00dev->link.ant.active.rx;
  176. enum antenna tx = rt2x00dev->link.ant.active.tx;
  177. int rssi_curr = rt2x00_get_link_ant_rssi(&rt2x00dev->link);
  178. int rssi_old = rt2x00_update_ant_rssi(&rt2x00dev->link, rssi_curr);
  179. /*
  180. * Legacy driver indicates that we should swap antenna's
  181. * when the difference in RSSI is greater that 5. This
  182. * also should be done when the RSSI was actually better
  183. * then the previous sample.
  184. * When the difference exceeds the threshold we should
  185. * sample the rssi from the other antenna to make a valid
  186. * comparison between the 2 antennas.
  187. */
  188. if (abs(rssi_curr - rssi_old) < 5)
  189. return;
  190. rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE;
  191. if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
  192. rx = (rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
  193. if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
  194. tx = (tx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A;
  195. rt2x00lib_config_antenna(rt2x00dev, rx, tx);
  196. }
  197. static void rt2x00lib_evaluate_antenna(struct rt2x00_dev *rt2x00dev)
  198. {
  199. /*
  200. * Determine if software diversity is enabled for
  201. * either the TX or RX antenna (or both).
  202. * Always perform this check since within the link
  203. * tuner interval the configuration might have changed.
  204. */
  205. rt2x00dev->link.ant.flags &= ~ANTENNA_RX_DIVERSITY;
  206. rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY;
  207. if (rt2x00dev->hw->conf.antenna_sel_rx == 0 &&
  208. rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
  209. rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY;
  210. if (rt2x00dev->hw->conf.antenna_sel_tx == 0 &&
  211. rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
  212. rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY;
  213. if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) &&
  214. !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) {
  215. rt2x00dev->link.ant.flags = 0;
  216. return;
  217. }
  218. /*
  219. * If we have only sampled the data over the last period
  220. * we should now harvest the data. Otherwise just evaluate
  221. * the data. The latter should only be performed once
  222. * every 2 seconds.
  223. */
  224. if (rt2x00dev->link.ant.flags & ANTENNA_MODE_SAMPLE)
  225. rt2x00lib_evaluate_antenna_sample(rt2x00dev);
  226. else if (rt2x00dev->link.count & 1)
  227. rt2x00lib_evaluate_antenna_eval(rt2x00dev);
  228. }
  229. static void rt2x00lib_update_link_stats(struct link *link, int rssi)
  230. {
  231. int avg_rssi = rssi;
  232. /*
  233. * Update global RSSI
  234. */
  235. if (link->qual.avg_rssi)
  236. avg_rssi = MOVING_AVERAGE(link->qual.avg_rssi, rssi, 8);
  237. link->qual.avg_rssi = avg_rssi;
  238. /*
  239. * Update antenna RSSI
  240. */
  241. if (link->ant.rssi_ant)
  242. rssi = MOVING_AVERAGE(link->ant.rssi_ant, rssi, 8);
  243. link->ant.rssi_ant = rssi;
  244. }
  245. static void rt2x00lib_precalculate_link_signal(struct link_qual *qual)
  246. {
  247. if (qual->rx_failed || qual->rx_success)
  248. qual->rx_percentage =
  249. (qual->rx_success * 100) /
  250. (qual->rx_failed + qual->rx_success);
  251. else
  252. qual->rx_percentage = 50;
  253. if (qual->tx_failed || qual->tx_success)
  254. qual->tx_percentage =
  255. (qual->tx_success * 100) /
  256. (qual->tx_failed + qual->tx_success);
  257. else
  258. qual->tx_percentage = 50;
  259. qual->rx_success = 0;
  260. qual->rx_failed = 0;
  261. qual->tx_success = 0;
  262. qual->tx_failed = 0;
  263. }
  264. static int rt2x00lib_calculate_link_signal(struct rt2x00_dev *rt2x00dev,
  265. int rssi)
  266. {
  267. int rssi_percentage = 0;
  268. int signal;
  269. /*
  270. * We need a positive value for the RSSI.
  271. */
  272. if (rssi < 0)
  273. rssi += rt2x00dev->rssi_offset;
  274. /*
  275. * Calculate the different percentages,
  276. * which will be used for the signal.
  277. */
  278. if (rt2x00dev->rssi_offset)
  279. rssi_percentage = (rssi * 100) / rt2x00dev->rssi_offset;
  280. /*
  281. * Add the individual percentages and use the WEIGHT
  282. * defines to calculate the current link signal.
  283. */
  284. signal = ((WEIGHT_RSSI * rssi_percentage) +
  285. (WEIGHT_TX * rt2x00dev->link.qual.tx_percentage) +
  286. (WEIGHT_RX * rt2x00dev->link.qual.rx_percentage)) / 100;
  287. return (signal > 100) ? 100 : signal;
  288. }
  289. static void rt2x00lib_link_tuner(struct work_struct *work)
  290. {
  291. struct rt2x00_dev *rt2x00dev =
  292. container_of(work, struct rt2x00_dev, link.work.work);
  293. /*
  294. * When the radio is shutting down we should
  295. * immediately cease all link tuning.
  296. */
  297. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  298. return;
  299. /*
  300. * Update statistics.
  301. */
  302. rt2x00dev->ops->lib->link_stats(rt2x00dev, &rt2x00dev->link.qual);
  303. rt2x00dev->low_level_stats.dot11FCSErrorCount +=
  304. rt2x00dev->link.qual.rx_failed;
  305. /*
  306. * Only perform the link tuning when Link tuning
  307. * has been enabled (This could have been disabled from the EEPROM).
  308. */
  309. if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
  310. rt2x00dev->ops->lib->link_tuner(rt2x00dev);
  311. /*
  312. * Precalculate a portion of the link signal which is
  313. * in based on the tx/rx success/failure counters.
  314. */
  315. rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual);
  316. /*
  317. * Send a signal to the led to update the led signal strength.
  318. */
  319. rt2x00leds_led_quality(rt2x00dev, rt2x00dev->link.qual.avg_rssi);
  320. /*
  321. * Evaluate antenna setup, make this the last step since this could
  322. * possibly reset some statistics.
  323. */
  324. rt2x00lib_evaluate_antenna(rt2x00dev);
  325. /*
  326. * Increase tuner counter, and reschedule the next link tuner run.
  327. */
  328. rt2x00dev->link.count++;
  329. queue_delayed_work(rt2x00dev->hw->workqueue,
  330. &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
  331. }
  332. static void rt2x00lib_packetfilter_scheduled(struct work_struct *work)
  333. {
  334. struct rt2x00_dev *rt2x00dev =
  335. container_of(work, struct rt2x00_dev, filter_work);
  336. rt2x00dev->ops->lib->config_filter(rt2x00dev, rt2x00dev->packet_filter);
  337. }
  338. static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
  339. struct ieee80211_vif *vif)
  340. {
  341. struct rt2x00_dev *rt2x00dev = data;
  342. struct rt2x00_intf *intf = vif_to_intf(vif);
  343. struct ieee80211_bss_conf conf;
  344. int delayed_flags;
  345. /*
  346. * Copy all data we need during this action under the protection
  347. * of a spinlock. Otherwise race conditions might occur which results
  348. * into an invalid configuration.
  349. */
  350. spin_lock(&intf->lock);
  351. memcpy(&conf, &intf->conf, sizeof(conf));
  352. delayed_flags = intf->delayed_flags;
  353. intf->delayed_flags = 0;
  354. spin_unlock(&intf->lock);
  355. /*
  356. * It is possible the radio was disabled while the work had been
  357. * scheduled. If that happens we should return here immediately,
  358. * note that in the spinlock protected area above the delayed_flags
  359. * have been cleared correctly.
  360. */
  361. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  362. return;
  363. if (delayed_flags & DELAYED_UPDATE_BEACON)
  364. rt2x00queue_update_beacon(rt2x00dev, vif);
  365. if (delayed_flags & DELAYED_CONFIG_ERP)
  366. rt2x00lib_config_erp(rt2x00dev, intf, &conf);
  367. if (delayed_flags & DELAYED_LED_ASSOC)
  368. rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
  369. }
  370. static void rt2x00lib_intf_scheduled(struct work_struct *work)
  371. {
  372. struct rt2x00_dev *rt2x00dev =
  373. container_of(work, struct rt2x00_dev, intf_work);
  374. /*
  375. * Iterate over each interface and perform the
  376. * requested configurations.
  377. */
  378. ieee80211_iterate_active_interfaces(rt2x00dev->hw,
  379. rt2x00lib_intf_scheduled_iter,
  380. rt2x00dev);
  381. }
  382. /*
  383. * Interrupt context handlers.
  384. */
  385. static void rt2x00lib_beacondone_iter(void *data, u8 *mac,
  386. struct ieee80211_vif *vif)
  387. {
  388. struct rt2x00_dev *rt2x00dev = data;
  389. struct rt2x00_intf *intf = vif_to_intf(vif);
  390. if (vif->type != IEEE80211_IF_TYPE_AP &&
  391. vif->type != IEEE80211_IF_TYPE_IBSS)
  392. return;
  393. /*
  394. * Clean up the beacon skb.
  395. */
  396. rt2x00queue_free_skb(rt2x00dev, intf->beacon->skb);
  397. intf->beacon->skb = NULL;
  398. spin_lock(&intf->lock);
  399. intf->delayed_flags |= DELAYED_UPDATE_BEACON;
  400. spin_unlock(&intf->lock);
  401. }
  402. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
  403. {
  404. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  405. return;
  406. ieee80211_iterate_active_interfaces_atomic(rt2x00dev->hw,
  407. rt2x00lib_beacondone_iter,
  408. rt2x00dev);
  409. schedule_work(&rt2x00dev->intf_work);
  410. }
  411. EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);
  412. void rt2x00lib_txdone(struct queue_entry *entry,
  413. struct txdone_entry_desc *txdesc)
  414. {
  415. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  416. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
  417. enum data_queue_qid qid = skb_get_queue_mapping(entry->skb);
  418. /*
  419. * Unmap the skb.
  420. */
  421. rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
  422. /*
  423. * If the IV/EIV data was stripped from the frame before it was
  424. * passed to the hardware, we should now reinsert it again because
  425. * mac80211 will expect the the same data to be present it the
  426. * frame as it was passed to us.
  427. */
  428. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
  429. rt2x00crypto_tx_insert_iv(entry->skb);
  430. /*
  431. * Send frame to debugfs immediately, after this call is completed
  432. * we are going to overwrite the skb->cb array.
  433. */
  434. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
  435. /*
  436. * Update TX statistics.
  437. */
  438. rt2x00dev->link.qual.tx_success +=
  439. test_bit(TXDONE_SUCCESS, &txdesc->flags);
  440. rt2x00dev->link.qual.tx_failed +=
  441. test_bit(TXDONE_FAILURE, &txdesc->flags);
  442. /*
  443. * Initialize TX status
  444. */
  445. memset(&tx_info->status, 0, sizeof(tx_info->status));
  446. tx_info->status.ack_signal = 0;
  447. tx_info->status.excessive_retries =
  448. test_bit(TXDONE_EXCESSIVE_RETRY, &txdesc->flags);
  449. tx_info->status.retry_count = txdesc->retry;
  450. if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  451. if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
  452. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  453. else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
  454. rt2x00dev->low_level_stats.dot11ACKFailureCount++;
  455. }
  456. if (tx_info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
  457. if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
  458. rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
  459. else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
  460. rt2x00dev->low_level_stats.dot11RTSFailureCount++;
  461. }
  462. /*
  463. * Only send the status report to mac80211 when TX status was
  464. * requested by it. If this was a extra frame coming through
  465. * a mac80211 library call (RTS/CTS) then we should not send the
  466. * status report back.
  467. */
  468. if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
  469. ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb);
  470. else
  471. dev_kfree_skb_irq(entry->skb);
  472. /*
  473. * Make this entry available for reuse.
  474. */
  475. entry->skb = NULL;
  476. entry->flags = 0;
  477. rt2x00dev->ops->lib->init_txentry(rt2x00dev, entry);
  478. __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
  479. rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
  480. /*
  481. * If the data queue was below the threshold before the txdone
  482. * handler we must make sure the packet queue in the mac80211 stack
  483. * is reenabled when the txdone handler has finished.
  484. */
  485. if (!rt2x00queue_threshold(entry->queue))
  486. ieee80211_wake_queue(rt2x00dev->hw, qid);
  487. }
  488. EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
  489. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  490. struct queue_entry *entry)
  491. {
  492. struct rxdone_entry_desc rxdesc;
  493. struct sk_buff *skb;
  494. struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
  495. struct ieee80211_supported_band *sband;
  496. struct ieee80211_hdr *hdr;
  497. const struct rt2x00_rate *rate;
  498. unsigned int header_length;
  499. unsigned int align;
  500. unsigned int i;
  501. int idx = -1;
  502. /*
  503. * Allocate a new sk_buffer. If no new buffer available, drop the
  504. * received frame and reuse the existing buffer.
  505. */
  506. skb = rt2x00queue_alloc_rxskb(rt2x00dev, entry);
  507. if (!skb)
  508. return;
  509. /*
  510. * Unmap the skb.
  511. */
  512. rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
  513. /*
  514. * Extract the RXD details.
  515. */
  516. memset(&rxdesc, 0, sizeof(rxdesc));
  517. rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
  518. /*
  519. * The data behind the ieee80211 header must be
  520. * aligned on a 4 byte boundary.
  521. */
  522. header_length = ieee80211_get_hdrlen_from_skb(entry->skb);
  523. align = ((unsigned long)(entry->skb->data + header_length)) & 3;
  524. /*
  525. * Hardware might have stripped the IV/EIV/ICV data,
  526. * in that case it is possible that the data was
  527. * provided seperately (through hardware descriptor)
  528. * in which case we should reinsert the data into the frame.
  529. */
  530. if ((rxdesc.flags & RX_FLAG_IV_STRIPPED)) {
  531. rt2x00crypto_rx_insert_iv(entry->skb, align,
  532. header_length, &rxdesc);
  533. } else if (align) {
  534. skb_push(entry->skb, align);
  535. /* Move entire frame in 1 command */
  536. memmove(entry->skb->data, entry->skb->data + align,
  537. rxdesc.size);
  538. }
  539. /* Update data pointers, trim buffer to correct size */
  540. skb_trim(entry->skb, rxdesc.size);
  541. /*
  542. * Update RX statistics.
  543. */
  544. sband = &rt2x00dev->bands[rt2x00dev->curr_band];
  545. for (i = 0; i < sband->n_bitrates; i++) {
  546. rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
  547. if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
  548. (rate->plcp == rxdesc.signal)) ||
  549. (!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
  550. (rate->bitrate == rxdesc.signal))) {
  551. idx = i;
  552. break;
  553. }
  554. }
  555. if (idx < 0) {
  556. WARNING(rt2x00dev, "Frame received with unrecognized signal,"
  557. "signal=0x%.2x, plcp=%d.\n", rxdesc.signal,
  558. !!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP));
  559. idx = 0;
  560. }
  561. /*
  562. * Only update link status if this is a beacon frame carrying our bssid.
  563. */
  564. hdr = (struct ieee80211_hdr *)entry->skb->data;
  565. if (ieee80211_is_beacon(hdr->frame_control) &&
  566. (rxdesc.dev_flags & RXDONE_MY_BSS))
  567. rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi);
  568. rt2x00debug_update_crypto(rt2x00dev,
  569. rxdesc.cipher,
  570. rxdesc.cipher_status);
  571. rt2x00dev->link.qual.rx_success++;
  572. rx_status->mactime = rxdesc.timestamp;
  573. rx_status->rate_idx = idx;
  574. rx_status->qual =
  575. rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc.rssi);
  576. rx_status->signal = rxdesc.rssi;
  577. rx_status->flag = rxdesc.flags;
  578. rx_status->antenna = rt2x00dev->link.ant.active.rx;
  579. /*
  580. * Send frame to mac80211 & debugfs.
  581. * mac80211 will clean up the skb structure.
  582. */
  583. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
  584. ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
  585. /*
  586. * Replace the skb with the freshly allocated one.
  587. */
  588. entry->skb = skb;
  589. entry->flags = 0;
  590. rt2x00dev->ops->lib->init_rxentry(rt2x00dev, entry);
  591. rt2x00queue_index_inc(entry->queue, Q_INDEX);
  592. }
  593. EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
  594. /*
  595. * Driver initialization handlers.
  596. */
  597. const struct rt2x00_rate rt2x00_supported_rates[12] = {
  598. {
  599. .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
  600. .bitrate = 10,
  601. .ratemask = BIT(0),
  602. .plcp = 0x00,
  603. },
  604. {
  605. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  606. .bitrate = 20,
  607. .ratemask = BIT(1),
  608. .plcp = 0x01,
  609. },
  610. {
  611. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  612. .bitrate = 55,
  613. .ratemask = BIT(2),
  614. .plcp = 0x02,
  615. },
  616. {
  617. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  618. .bitrate = 110,
  619. .ratemask = BIT(3),
  620. .plcp = 0x03,
  621. },
  622. {
  623. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  624. .bitrate = 60,
  625. .ratemask = BIT(4),
  626. .plcp = 0x0b,
  627. },
  628. {
  629. .flags = DEV_RATE_OFDM,
  630. .bitrate = 90,
  631. .ratemask = BIT(5),
  632. .plcp = 0x0f,
  633. },
  634. {
  635. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  636. .bitrate = 120,
  637. .ratemask = BIT(6),
  638. .plcp = 0x0a,
  639. },
  640. {
  641. .flags = DEV_RATE_OFDM,
  642. .bitrate = 180,
  643. .ratemask = BIT(7),
  644. .plcp = 0x0e,
  645. },
  646. {
  647. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  648. .bitrate = 240,
  649. .ratemask = BIT(8),
  650. .plcp = 0x09,
  651. },
  652. {
  653. .flags = DEV_RATE_OFDM,
  654. .bitrate = 360,
  655. .ratemask = BIT(9),
  656. .plcp = 0x0d,
  657. },
  658. {
  659. .flags = DEV_RATE_OFDM,
  660. .bitrate = 480,
  661. .ratemask = BIT(10),
  662. .plcp = 0x08,
  663. },
  664. {
  665. .flags = DEV_RATE_OFDM,
  666. .bitrate = 540,
  667. .ratemask = BIT(11),
  668. .plcp = 0x0c,
  669. },
  670. };
  671. static void rt2x00lib_channel(struct ieee80211_channel *entry,
  672. const int channel, const int tx_power,
  673. const int value)
  674. {
  675. entry->center_freq = ieee80211_channel_to_frequency(channel);
  676. entry->hw_value = value;
  677. entry->max_power = tx_power;
  678. entry->max_antenna_gain = 0xff;
  679. }
  680. static void rt2x00lib_rate(struct ieee80211_rate *entry,
  681. const u16 index, const struct rt2x00_rate *rate)
  682. {
  683. entry->flags = 0;
  684. entry->bitrate = rate->bitrate;
  685. entry->hw_value = rt2x00_create_rate_hw_value(index, 0);
  686. entry->hw_value_short = entry->hw_value;
  687. if (rate->flags & DEV_RATE_SHORT_PREAMBLE) {
  688. entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
  689. entry->hw_value_short |= rt2x00_create_rate_hw_value(index, 1);
  690. }
  691. }
  692. static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
  693. struct hw_mode_spec *spec)
  694. {
  695. struct ieee80211_hw *hw = rt2x00dev->hw;
  696. struct ieee80211_channel *channels;
  697. struct ieee80211_rate *rates;
  698. unsigned int num_rates;
  699. unsigned int i;
  700. unsigned char tx_power;
  701. num_rates = 0;
  702. if (spec->supported_rates & SUPPORT_RATE_CCK)
  703. num_rates += 4;
  704. if (spec->supported_rates & SUPPORT_RATE_OFDM)
  705. num_rates += 8;
  706. channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
  707. if (!channels)
  708. return -ENOMEM;
  709. rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL);
  710. if (!rates)
  711. goto exit_free_channels;
  712. /*
  713. * Initialize Rate list.
  714. */
  715. for (i = 0; i < num_rates; i++)
  716. rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i));
  717. /*
  718. * Initialize Channel list.
  719. */
  720. for (i = 0; i < spec->num_channels; i++) {
  721. if (spec->channels[i].channel <= 14) {
  722. if (spec->tx_power_bg)
  723. tx_power = spec->tx_power_bg[i];
  724. else
  725. tx_power = spec->tx_power_default;
  726. } else {
  727. if (spec->tx_power_a)
  728. tx_power = spec->tx_power_a[i];
  729. else
  730. tx_power = spec->tx_power_default;
  731. }
  732. rt2x00lib_channel(&channels[i],
  733. spec->channels[i].channel, tx_power, i);
  734. }
  735. /*
  736. * Intitialize 802.11b, 802.11g
  737. * Rates: CCK, OFDM.
  738. * Channels: 2.4 GHz
  739. */
  740. if (spec->supported_bands & SUPPORT_BAND_2GHZ) {
  741. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_channels = 14;
  742. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_bitrates = num_rates;
  743. rt2x00dev->bands[IEEE80211_BAND_2GHZ].channels = channels;
  744. rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
  745. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  746. &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
  747. }
  748. /*
  749. * Intitialize 802.11a
  750. * Rates: OFDM.
  751. * Channels: OFDM, UNII, HiperLAN2.
  752. */
  753. if (spec->supported_bands & SUPPORT_BAND_5GHZ) {
  754. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_channels =
  755. spec->num_channels - 14;
  756. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_bitrates =
  757. num_rates - 4;
  758. rt2x00dev->bands[IEEE80211_BAND_5GHZ].channels = &channels[14];
  759. rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
  760. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  761. &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
  762. }
  763. return 0;
  764. exit_free_channels:
  765. kfree(channels);
  766. ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
  767. return -ENOMEM;
  768. }
  769. static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
  770. {
  771. if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
  772. ieee80211_unregister_hw(rt2x00dev->hw);
  773. if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
  774. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
  775. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates);
  776. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  777. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  778. }
  779. }
  780. static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
  781. {
  782. struct hw_mode_spec *spec = &rt2x00dev->spec;
  783. int status;
  784. /*
  785. * Initialize HW modes.
  786. */
  787. status = rt2x00lib_probe_hw_modes(rt2x00dev, spec);
  788. if (status)
  789. return status;
  790. /*
  791. * Initialize HW fields.
  792. */
  793. rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues;
  794. /*
  795. * Register HW.
  796. */
  797. status = ieee80211_register_hw(rt2x00dev->hw);
  798. if (status) {
  799. rt2x00lib_remove_hw(rt2x00dev);
  800. return status;
  801. }
  802. __set_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags);
  803. return 0;
  804. }
  805. /*
  806. * Initialization/uninitialization handlers.
  807. */
  808. static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
  809. {
  810. if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
  811. return;
  812. /*
  813. * Unregister extra components.
  814. */
  815. rt2x00rfkill_unregister(rt2x00dev);
  816. /*
  817. * Allow the HW to uninitialize.
  818. */
  819. rt2x00dev->ops->lib->uninitialize(rt2x00dev);
  820. /*
  821. * Free allocated queue entries.
  822. */
  823. rt2x00queue_uninitialize(rt2x00dev);
  824. }
  825. static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
  826. {
  827. int status;
  828. if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
  829. return 0;
  830. /*
  831. * Allocate all queue entries.
  832. */
  833. status = rt2x00queue_initialize(rt2x00dev);
  834. if (status)
  835. return status;
  836. /*
  837. * Initialize the device.
  838. */
  839. status = rt2x00dev->ops->lib->initialize(rt2x00dev);
  840. if (status) {
  841. rt2x00queue_uninitialize(rt2x00dev);
  842. return status;
  843. }
  844. __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
  845. /*
  846. * Register the extra components.
  847. */
  848. rt2x00rfkill_register(rt2x00dev);
  849. return 0;
  850. }
  851. int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
  852. {
  853. int retval;
  854. if (test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  855. return 0;
  856. /*
  857. * If this is the first interface which is added,
  858. * we should load the firmware now.
  859. */
  860. retval = rt2x00lib_load_firmware(rt2x00dev);
  861. if (retval)
  862. return retval;
  863. /*
  864. * Initialize the device.
  865. */
  866. retval = rt2x00lib_initialize(rt2x00dev);
  867. if (retval)
  868. return retval;
  869. /*
  870. * Enable radio.
  871. */
  872. retval = rt2x00lib_enable_radio(rt2x00dev);
  873. if (retval) {
  874. rt2x00lib_uninitialize(rt2x00dev);
  875. return retval;
  876. }
  877. rt2x00dev->intf_ap_count = 0;
  878. rt2x00dev->intf_sta_count = 0;
  879. rt2x00dev->intf_associated = 0;
  880. __set_bit(DEVICE_STARTED, &rt2x00dev->flags);
  881. __set_bit(DEVICE_DIRTY_CONFIG, &rt2x00dev->flags);
  882. return 0;
  883. }
  884. void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
  885. {
  886. if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  887. return;
  888. /*
  889. * Perhaps we can add something smarter here,
  890. * but for now just disabling the radio should do.
  891. */
  892. rt2x00lib_disable_radio(rt2x00dev);
  893. rt2x00dev->intf_ap_count = 0;
  894. rt2x00dev->intf_sta_count = 0;
  895. rt2x00dev->intf_associated = 0;
  896. __clear_bit(DEVICE_STARTED, &rt2x00dev->flags);
  897. }
  898. /*
  899. * driver allocation handlers.
  900. */
  901. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
  902. {
  903. int retval = -ENOMEM;
  904. /*
  905. * Make room for rt2x00_intf inside the per-interface
  906. * structure ieee80211_vif.
  907. */
  908. rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
  909. /*
  910. * Let the driver probe the device to detect the capabilities.
  911. */
  912. retval = rt2x00dev->ops->lib->probe_hw(rt2x00dev);
  913. if (retval) {
  914. ERROR(rt2x00dev, "Failed to allocate device.\n");
  915. goto exit;
  916. }
  917. /*
  918. * Initialize configuration work.
  919. */
  920. INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
  921. INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
  922. INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
  923. /*
  924. * Allocate queue array.
  925. */
  926. retval = rt2x00queue_allocate(rt2x00dev);
  927. if (retval)
  928. goto exit;
  929. /*
  930. * Initialize ieee80211 structure.
  931. */
  932. retval = rt2x00lib_probe_hw(rt2x00dev);
  933. if (retval) {
  934. ERROR(rt2x00dev, "Failed to initialize hw.\n");
  935. goto exit;
  936. }
  937. /*
  938. * Register extra components.
  939. */
  940. rt2x00leds_register(rt2x00dev);
  941. rt2x00rfkill_allocate(rt2x00dev);
  942. rt2x00debug_register(rt2x00dev);
  943. __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  944. return 0;
  945. exit:
  946. rt2x00lib_remove_dev(rt2x00dev);
  947. return retval;
  948. }
  949. EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
  950. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
  951. {
  952. __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  953. /*
  954. * Disable radio.
  955. */
  956. rt2x00lib_disable_radio(rt2x00dev);
  957. /*
  958. * Uninitialize device.
  959. */
  960. rt2x00lib_uninitialize(rt2x00dev);
  961. /*
  962. * Free extra components
  963. */
  964. rt2x00debug_deregister(rt2x00dev);
  965. rt2x00rfkill_free(rt2x00dev);
  966. rt2x00leds_unregister(rt2x00dev);
  967. /*
  968. * Free ieee80211_hw memory.
  969. */
  970. rt2x00lib_remove_hw(rt2x00dev);
  971. /*
  972. * Free firmware image.
  973. */
  974. rt2x00lib_free_firmware(rt2x00dev);
  975. /*
  976. * Free queue structures.
  977. */
  978. rt2x00queue_free(rt2x00dev);
  979. }
  980. EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
  981. /*
  982. * Device state handlers
  983. */
  984. #ifdef CONFIG_PM
  985. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
  986. {
  987. int retval;
  988. NOTICE(rt2x00dev, "Going to sleep.\n");
  989. __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  990. /*
  991. * Only continue if mac80211 has open interfaces.
  992. */
  993. if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  994. goto exit;
  995. __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
  996. /*
  997. * Disable radio.
  998. */
  999. rt2x00lib_stop(rt2x00dev);
  1000. rt2x00lib_uninitialize(rt2x00dev);
  1001. /*
  1002. * Suspend/disable extra components.
  1003. */
  1004. rt2x00leds_suspend(rt2x00dev);
  1005. rt2x00debug_deregister(rt2x00dev);
  1006. exit:
  1007. /*
  1008. * Set device mode to sleep for power management,
  1009. * on some hardware this call seems to consistently fail.
  1010. * From the specifications it is hard to tell why it fails,
  1011. * and if this is a "bad thing".
  1012. * Overall it is safe to just ignore the failure and
  1013. * continue suspending. The only downside is that the
  1014. * device will not be in optimal power save mode, but with
  1015. * the radio and the other components already disabled the
  1016. * device is as good as disabled.
  1017. */
  1018. retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
  1019. if (retval)
  1020. WARNING(rt2x00dev, "Device failed to enter sleep state, "
  1021. "continue suspending.\n");
  1022. return 0;
  1023. }
  1024. EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
  1025. static void rt2x00lib_resume_intf(void *data, u8 *mac,
  1026. struct ieee80211_vif *vif)
  1027. {
  1028. struct rt2x00_dev *rt2x00dev = data;
  1029. struct rt2x00_intf *intf = vif_to_intf(vif);
  1030. spin_lock(&intf->lock);
  1031. rt2x00lib_config_intf(rt2x00dev, intf,
  1032. vif->type, intf->mac, intf->bssid);
  1033. /*
  1034. * Master or Ad-hoc mode require a new beacon update.
  1035. */
  1036. if (vif->type == IEEE80211_IF_TYPE_AP ||
  1037. vif->type == IEEE80211_IF_TYPE_IBSS)
  1038. intf->delayed_flags |= DELAYED_UPDATE_BEACON;
  1039. spin_unlock(&intf->lock);
  1040. }
  1041. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
  1042. {
  1043. int retval;
  1044. NOTICE(rt2x00dev, "Waking up.\n");
  1045. /*
  1046. * Restore/enable extra components.
  1047. */
  1048. rt2x00debug_register(rt2x00dev);
  1049. rt2x00leds_resume(rt2x00dev);
  1050. /*
  1051. * Only continue if mac80211 had open interfaces.
  1052. */
  1053. if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags))
  1054. return 0;
  1055. /*
  1056. * Reinitialize device and all active interfaces.
  1057. */
  1058. retval = rt2x00lib_start(rt2x00dev);
  1059. if (retval)
  1060. goto exit;
  1061. /*
  1062. * Reconfigure device.
  1063. */
  1064. retval = rt2x00mac_config(rt2x00dev->hw, &rt2x00dev->hw->conf);
  1065. if (retval)
  1066. goto exit;
  1067. /*
  1068. * Iterator over each active interface to
  1069. * reconfigure the hardware.
  1070. */
  1071. ieee80211_iterate_active_interfaces(rt2x00dev->hw,
  1072. rt2x00lib_resume_intf, rt2x00dev);
  1073. /*
  1074. * We are ready again to receive requests from mac80211.
  1075. */
  1076. __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  1077. /*
  1078. * It is possible that during that mac80211 has attempted
  1079. * to send frames while we were suspending or resuming.
  1080. * In that case we have disabled the TX queue and should
  1081. * now enable it again
  1082. */
  1083. ieee80211_wake_queues(rt2x00dev->hw);
  1084. /*
  1085. * During interface iteration we might have changed the
  1086. * delayed_flags, time to handles the event by calling
  1087. * the work handler directly.
  1088. */
  1089. rt2x00lib_intf_scheduled(&rt2x00dev->intf_work);
  1090. return 0;
  1091. exit:
  1092. rt2x00lib_disable_radio(rt2x00dev);
  1093. rt2x00lib_uninitialize(rt2x00dev);
  1094. rt2x00debug_deregister(rt2x00dev);
  1095. return retval;
  1096. }
  1097. EXPORT_SYMBOL_GPL(rt2x00lib_resume);
  1098. #endif /* CONFIG_PM */
  1099. /*
  1100. * rt2x00lib module information.
  1101. */
  1102. MODULE_AUTHOR(DRV_PROJECT);
  1103. MODULE_VERSION(DRV_VERSION);
  1104. MODULE_DESCRIPTION("rt2x00 library");
  1105. MODULE_LICENSE("GPL");