rt2x00dev.c 31 KB

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