rt2x00dev.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. * Send frame to debugfs immediately, after this call is completed
  424. * we are going to overwrite the skb->cb array.
  425. */
  426. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb);
  427. /*
  428. * Update TX statistics.
  429. */
  430. rt2x00dev->link.qual.tx_success +=
  431. test_bit(TXDONE_SUCCESS, &txdesc->flags);
  432. rt2x00dev->link.qual.tx_failed +=
  433. test_bit(TXDONE_FAILURE, &txdesc->flags);
  434. /*
  435. * Initialize TX status
  436. */
  437. memset(&tx_info->status, 0, sizeof(tx_info->status));
  438. tx_info->status.ack_signal = 0;
  439. tx_info->status.excessive_retries =
  440. test_bit(TXDONE_EXCESSIVE_RETRY, &txdesc->flags);
  441. tx_info->status.retry_count = txdesc->retry;
  442. if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  443. if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
  444. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  445. else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
  446. rt2x00dev->low_level_stats.dot11ACKFailureCount++;
  447. }
  448. if (tx_info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
  449. if (test_bit(TXDONE_SUCCESS, &txdesc->flags))
  450. rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
  451. else if (test_bit(TXDONE_FAILURE, &txdesc->flags))
  452. rt2x00dev->low_level_stats.dot11RTSFailureCount++;
  453. }
  454. /*
  455. * Only send the status report to mac80211 when TX status was
  456. * requested by it. If this was a extra frame coming through
  457. * a mac80211 library call (RTS/CTS) then we should not send the
  458. * status report back.
  459. */
  460. if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
  461. ieee80211_tx_status_irqsafe(rt2x00dev->hw, entry->skb);
  462. else
  463. dev_kfree_skb_irq(entry->skb);
  464. /*
  465. * Make this entry available for reuse.
  466. */
  467. entry->skb = NULL;
  468. entry->flags = 0;
  469. rt2x00dev->ops->lib->init_txentry(rt2x00dev, entry);
  470. __clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
  471. rt2x00queue_index_inc(entry->queue, Q_INDEX_DONE);
  472. /*
  473. * If the data queue was below the threshold before the txdone
  474. * handler we must make sure the packet queue in the mac80211 stack
  475. * is reenabled when the txdone handler has finished.
  476. */
  477. if (!rt2x00queue_threshold(entry->queue))
  478. ieee80211_wake_queue(rt2x00dev->hw, qid);
  479. }
  480. EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
  481. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  482. struct queue_entry *entry)
  483. {
  484. struct rxdone_entry_desc rxdesc;
  485. struct sk_buff *skb;
  486. struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status;
  487. struct ieee80211_supported_band *sband;
  488. struct ieee80211_hdr *hdr;
  489. const struct rt2x00_rate *rate;
  490. unsigned int header_size;
  491. unsigned int align;
  492. unsigned int i;
  493. int idx = -1;
  494. /*
  495. * Allocate a new sk_buffer. If no new buffer available, drop the
  496. * received frame and reuse the existing buffer.
  497. */
  498. skb = rt2x00queue_alloc_rxskb(rt2x00dev, entry);
  499. if (!skb)
  500. return;
  501. /*
  502. * Unmap the skb.
  503. */
  504. rt2x00queue_unmap_skb(rt2x00dev, entry->skb);
  505. /*
  506. * Extract the RXD details.
  507. */
  508. memset(&rxdesc, 0, sizeof(rxdesc));
  509. rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
  510. /*
  511. * The data behind the ieee80211 header must be
  512. * aligned on a 4 byte boundary.
  513. */
  514. header_size = ieee80211_get_hdrlen_from_skb(entry->skb);
  515. align = ((unsigned long)(entry->skb->data + header_size)) & 3;
  516. if (align) {
  517. skb_push(entry->skb, align);
  518. /* Move entire frame in 1 command */
  519. memmove(entry->skb->data, entry->skb->data + align,
  520. rxdesc.size);
  521. }
  522. /* Update data pointers, trim buffer to correct size */
  523. skb_trim(entry->skb, rxdesc.size);
  524. /*
  525. * Update RX statistics.
  526. */
  527. sband = &rt2x00dev->bands[rt2x00dev->curr_band];
  528. for (i = 0; i < sband->n_bitrates; i++) {
  529. rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
  530. if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
  531. (rate->plcp == rxdesc.signal)) ||
  532. (!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
  533. (rate->bitrate == rxdesc.signal))) {
  534. idx = i;
  535. break;
  536. }
  537. }
  538. if (idx < 0) {
  539. WARNING(rt2x00dev, "Frame received with unrecognized signal,"
  540. "signal=0x%.2x, plcp=%d.\n", rxdesc.signal,
  541. !!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP));
  542. idx = 0;
  543. }
  544. /*
  545. * Only update link status if this is a beacon frame carrying our bssid.
  546. */
  547. hdr = (struct ieee80211_hdr *)entry->skb->data;
  548. if (ieee80211_is_beacon(hdr->frame_control) &&
  549. (rxdesc.dev_flags & RXDONE_MY_BSS))
  550. rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi);
  551. rt2x00dev->link.qual.rx_success++;
  552. rx_status->mactime = rxdesc.timestamp;
  553. rx_status->rate_idx = idx;
  554. rx_status->qual =
  555. rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc.rssi);
  556. rx_status->signal = rxdesc.rssi;
  557. rx_status->flag = rxdesc.flags;
  558. rx_status->antenna = rt2x00dev->link.ant.active.rx;
  559. /*
  560. * Send frame to mac80211 & debugfs.
  561. * mac80211 will clean up the skb structure.
  562. */
  563. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
  564. ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
  565. /*
  566. * Replace the skb with the freshly allocated one.
  567. */
  568. entry->skb = skb;
  569. entry->flags = 0;
  570. rt2x00dev->ops->lib->init_rxentry(rt2x00dev, entry);
  571. rt2x00queue_index_inc(entry->queue, Q_INDEX);
  572. }
  573. EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
  574. /*
  575. * Driver initialization handlers.
  576. */
  577. const struct rt2x00_rate rt2x00_supported_rates[12] = {
  578. {
  579. .flags = DEV_RATE_CCK | DEV_RATE_BASIC,
  580. .bitrate = 10,
  581. .ratemask = BIT(0),
  582. .plcp = 0x00,
  583. },
  584. {
  585. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  586. .bitrate = 20,
  587. .ratemask = BIT(1),
  588. .plcp = 0x01,
  589. },
  590. {
  591. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  592. .bitrate = 55,
  593. .ratemask = BIT(2),
  594. .plcp = 0x02,
  595. },
  596. {
  597. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE | DEV_RATE_BASIC,
  598. .bitrate = 110,
  599. .ratemask = BIT(3),
  600. .plcp = 0x03,
  601. },
  602. {
  603. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  604. .bitrate = 60,
  605. .ratemask = BIT(4),
  606. .plcp = 0x0b,
  607. },
  608. {
  609. .flags = DEV_RATE_OFDM,
  610. .bitrate = 90,
  611. .ratemask = BIT(5),
  612. .plcp = 0x0f,
  613. },
  614. {
  615. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  616. .bitrate = 120,
  617. .ratemask = BIT(6),
  618. .plcp = 0x0a,
  619. },
  620. {
  621. .flags = DEV_RATE_OFDM,
  622. .bitrate = 180,
  623. .ratemask = BIT(7),
  624. .plcp = 0x0e,
  625. },
  626. {
  627. .flags = DEV_RATE_OFDM | DEV_RATE_BASIC,
  628. .bitrate = 240,
  629. .ratemask = BIT(8),
  630. .plcp = 0x09,
  631. },
  632. {
  633. .flags = DEV_RATE_OFDM,
  634. .bitrate = 360,
  635. .ratemask = BIT(9),
  636. .plcp = 0x0d,
  637. },
  638. {
  639. .flags = DEV_RATE_OFDM,
  640. .bitrate = 480,
  641. .ratemask = BIT(10),
  642. .plcp = 0x08,
  643. },
  644. {
  645. .flags = DEV_RATE_OFDM,
  646. .bitrate = 540,
  647. .ratemask = BIT(11),
  648. .plcp = 0x0c,
  649. },
  650. };
  651. static void rt2x00lib_channel(struct ieee80211_channel *entry,
  652. const int channel, const int tx_power,
  653. const int value)
  654. {
  655. entry->center_freq = ieee80211_channel_to_frequency(channel);
  656. entry->hw_value = value;
  657. entry->max_power = tx_power;
  658. entry->max_antenna_gain = 0xff;
  659. }
  660. static void rt2x00lib_rate(struct ieee80211_rate *entry,
  661. const u16 index, const struct rt2x00_rate *rate)
  662. {
  663. entry->flags = 0;
  664. entry->bitrate = rate->bitrate;
  665. entry->hw_value = rt2x00_create_rate_hw_value(index, 0);
  666. entry->hw_value_short = entry->hw_value;
  667. if (rate->flags & DEV_RATE_SHORT_PREAMBLE) {
  668. entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
  669. entry->hw_value_short |= rt2x00_create_rate_hw_value(index, 1);
  670. }
  671. }
  672. static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
  673. struct hw_mode_spec *spec)
  674. {
  675. struct ieee80211_hw *hw = rt2x00dev->hw;
  676. struct ieee80211_channel *channels;
  677. struct ieee80211_rate *rates;
  678. unsigned int num_rates;
  679. unsigned int i;
  680. unsigned char tx_power;
  681. num_rates = 0;
  682. if (spec->supported_rates & SUPPORT_RATE_CCK)
  683. num_rates += 4;
  684. if (spec->supported_rates & SUPPORT_RATE_OFDM)
  685. num_rates += 8;
  686. channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
  687. if (!channels)
  688. return -ENOMEM;
  689. rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL);
  690. if (!rates)
  691. goto exit_free_channels;
  692. /*
  693. * Initialize Rate list.
  694. */
  695. for (i = 0; i < num_rates; i++)
  696. rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i));
  697. /*
  698. * Initialize Channel list.
  699. */
  700. for (i = 0; i < spec->num_channels; i++) {
  701. if (spec->channels[i].channel <= 14) {
  702. if (spec->tx_power_bg)
  703. tx_power = spec->tx_power_bg[i];
  704. else
  705. tx_power = spec->tx_power_default;
  706. } else {
  707. if (spec->tx_power_a)
  708. tx_power = spec->tx_power_a[i];
  709. else
  710. tx_power = spec->tx_power_default;
  711. }
  712. rt2x00lib_channel(&channels[i],
  713. spec->channels[i].channel, tx_power, i);
  714. }
  715. /*
  716. * Intitialize 802.11b, 802.11g
  717. * Rates: CCK, OFDM.
  718. * Channels: 2.4 GHz
  719. */
  720. if (spec->supported_bands & SUPPORT_BAND_2GHZ) {
  721. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_channels = 14;
  722. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_bitrates = num_rates;
  723. rt2x00dev->bands[IEEE80211_BAND_2GHZ].channels = channels;
  724. rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
  725. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  726. &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
  727. }
  728. /*
  729. * Intitialize 802.11a
  730. * Rates: OFDM.
  731. * Channels: OFDM, UNII, HiperLAN2.
  732. */
  733. if (spec->supported_bands & SUPPORT_BAND_5GHZ) {
  734. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_channels =
  735. spec->num_channels - 14;
  736. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_bitrates =
  737. num_rates - 4;
  738. rt2x00dev->bands[IEEE80211_BAND_5GHZ].channels = &channels[14];
  739. rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
  740. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  741. &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
  742. }
  743. return 0;
  744. exit_free_channels:
  745. kfree(channels);
  746. ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
  747. return -ENOMEM;
  748. }
  749. static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
  750. {
  751. if (test_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags))
  752. ieee80211_unregister_hw(rt2x00dev->hw);
  753. if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
  754. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
  755. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates);
  756. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  757. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  758. }
  759. }
  760. static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
  761. {
  762. struct hw_mode_spec *spec = &rt2x00dev->spec;
  763. int status;
  764. /*
  765. * Initialize HW modes.
  766. */
  767. status = rt2x00lib_probe_hw_modes(rt2x00dev, spec);
  768. if (status)
  769. return status;
  770. /*
  771. * Initialize HW fields.
  772. */
  773. rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues;
  774. /*
  775. * Register HW.
  776. */
  777. status = ieee80211_register_hw(rt2x00dev->hw);
  778. if (status) {
  779. rt2x00lib_remove_hw(rt2x00dev);
  780. return status;
  781. }
  782. __set_bit(DEVICE_REGISTERED_HW, &rt2x00dev->flags);
  783. return 0;
  784. }
  785. /*
  786. * Initialization/uninitialization handlers.
  787. */
  788. static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
  789. {
  790. if (!__test_and_clear_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
  791. return;
  792. /*
  793. * Unregister extra components.
  794. */
  795. rt2x00rfkill_unregister(rt2x00dev);
  796. /*
  797. * Allow the HW to uninitialize.
  798. */
  799. rt2x00dev->ops->lib->uninitialize(rt2x00dev);
  800. /*
  801. * Free allocated queue entries.
  802. */
  803. rt2x00queue_uninitialize(rt2x00dev);
  804. }
  805. static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
  806. {
  807. int status;
  808. if (test_bit(DEVICE_INITIALIZED, &rt2x00dev->flags))
  809. return 0;
  810. /*
  811. * Allocate all queue entries.
  812. */
  813. status = rt2x00queue_initialize(rt2x00dev);
  814. if (status)
  815. return status;
  816. /*
  817. * Initialize the device.
  818. */
  819. status = rt2x00dev->ops->lib->initialize(rt2x00dev);
  820. if (status) {
  821. rt2x00queue_uninitialize(rt2x00dev);
  822. return status;
  823. }
  824. __set_bit(DEVICE_INITIALIZED, &rt2x00dev->flags);
  825. /*
  826. * Register the extra components.
  827. */
  828. rt2x00rfkill_register(rt2x00dev);
  829. return 0;
  830. }
  831. int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
  832. {
  833. int retval;
  834. if (test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  835. return 0;
  836. /*
  837. * If this is the first interface which is added,
  838. * we should load the firmware now.
  839. */
  840. retval = rt2x00lib_load_firmware(rt2x00dev);
  841. if (retval)
  842. return retval;
  843. /*
  844. * Initialize the device.
  845. */
  846. retval = rt2x00lib_initialize(rt2x00dev);
  847. if (retval)
  848. return retval;
  849. /*
  850. * Enable radio.
  851. */
  852. retval = rt2x00lib_enable_radio(rt2x00dev);
  853. if (retval) {
  854. rt2x00lib_uninitialize(rt2x00dev);
  855. return retval;
  856. }
  857. rt2x00dev->intf_ap_count = 0;
  858. rt2x00dev->intf_sta_count = 0;
  859. rt2x00dev->intf_associated = 0;
  860. __set_bit(DEVICE_STARTED, &rt2x00dev->flags);
  861. __set_bit(DEVICE_DIRTY_CONFIG, &rt2x00dev->flags);
  862. return 0;
  863. }
  864. void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
  865. {
  866. if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  867. return;
  868. /*
  869. * Perhaps we can add something smarter here,
  870. * but for now just disabling the radio should do.
  871. */
  872. rt2x00lib_disable_radio(rt2x00dev);
  873. rt2x00dev->intf_ap_count = 0;
  874. rt2x00dev->intf_sta_count = 0;
  875. rt2x00dev->intf_associated = 0;
  876. __clear_bit(DEVICE_STARTED, &rt2x00dev->flags);
  877. }
  878. /*
  879. * driver allocation handlers.
  880. */
  881. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
  882. {
  883. int retval = -ENOMEM;
  884. /*
  885. * Make room for rt2x00_intf inside the per-interface
  886. * structure ieee80211_vif.
  887. */
  888. rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
  889. /*
  890. * Let the driver probe the device to detect the capabilities.
  891. */
  892. retval = rt2x00dev->ops->lib->probe_hw(rt2x00dev);
  893. if (retval) {
  894. ERROR(rt2x00dev, "Failed to allocate device.\n");
  895. goto exit;
  896. }
  897. /*
  898. * Initialize configuration work.
  899. */
  900. INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
  901. INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
  902. INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
  903. /*
  904. * Allocate queue array.
  905. */
  906. retval = rt2x00queue_allocate(rt2x00dev);
  907. if (retval)
  908. goto exit;
  909. /*
  910. * Initialize ieee80211 structure.
  911. */
  912. retval = rt2x00lib_probe_hw(rt2x00dev);
  913. if (retval) {
  914. ERROR(rt2x00dev, "Failed to initialize hw.\n");
  915. goto exit;
  916. }
  917. /*
  918. * Register extra components.
  919. */
  920. rt2x00leds_register(rt2x00dev);
  921. rt2x00rfkill_allocate(rt2x00dev);
  922. rt2x00debug_register(rt2x00dev);
  923. __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  924. return 0;
  925. exit:
  926. rt2x00lib_remove_dev(rt2x00dev);
  927. return retval;
  928. }
  929. EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
  930. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
  931. {
  932. __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  933. /*
  934. * Disable radio.
  935. */
  936. rt2x00lib_disable_radio(rt2x00dev);
  937. /*
  938. * Uninitialize device.
  939. */
  940. rt2x00lib_uninitialize(rt2x00dev);
  941. /*
  942. * Free extra components
  943. */
  944. rt2x00debug_deregister(rt2x00dev);
  945. rt2x00rfkill_free(rt2x00dev);
  946. rt2x00leds_unregister(rt2x00dev);
  947. /*
  948. * Free ieee80211_hw memory.
  949. */
  950. rt2x00lib_remove_hw(rt2x00dev);
  951. /*
  952. * Free firmware image.
  953. */
  954. rt2x00lib_free_firmware(rt2x00dev);
  955. /*
  956. * Free queue structures.
  957. */
  958. rt2x00queue_free(rt2x00dev);
  959. }
  960. EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
  961. /*
  962. * Device state handlers
  963. */
  964. #ifdef CONFIG_PM
  965. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
  966. {
  967. int retval;
  968. NOTICE(rt2x00dev, "Going to sleep.\n");
  969. __clear_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  970. /*
  971. * Only continue if mac80211 has open interfaces.
  972. */
  973. if (!test_bit(DEVICE_STARTED, &rt2x00dev->flags))
  974. goto exit;
  975. __set_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags);
  976. /*
  977. * Disable radio.
  978. */
  979. rt2x00lib_stop(rt2x00dev);
  980. rt2x00lib_uninitialize(rt2x00dev);
  981. /*
  982. * Suspend/disable extra components.
  983. */
  984. rt2x00leds_suspend(rt2x00dev);
  985. rt2x00debug_deregister(rt2x00dev);
  986. exit:
  987. /*
  988. * Set device mode to sleep for power management,
  989. * on some hardware this call seems to consistently fail.
  990. * From the specifications it is hard to tell why it fails,
  991. * and if this is a "bad thing".
  992. * Overall it is safe to just ignore the failure and
  993. * continue suspending. The only downside is that the
  994. * device will not be in optimal power save mode, but with
  995. * the radio and the other components already disabled the
  996. * device is as good as disabled.
  997. */
  998. retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
  999. if (retval)
  1000. WARNING(rt2x00dev, "Device failed to enter sleep state, "
  1001. "continue suspending.\n");
  1002. return 0;
  1003. }
  1004. EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
  1005. static void rt2x00lib_resume_intf(void *data, u8 *mac,
  1006. struct ieee80211_vif *vif)
  1007. {
  1008. struct rt2x00_dev *rt2x00dev = data;
  1009. struct rt2x00_intf *intf = vif_to_intf(vif);
  1010. spin_lock(&intf->lock);
  1011. rt2x00lib_config_intf(rt2x00dev, intf,
  1012. vif->type, intf->mac, intf->bssid);
  1013. /*
  1014. * Master or Ad-hoc mode require a new beacon update.
  1015. */
  1016. if (vif->type == IEEE80211_IF_TYPE_AP ||
  1017. vif->type == IEEE80211_IF_TYPE_IBSS)
  1018. intf->delayed_flags |= DELAYED_UPDATE_BEACON;
  1019. spin_unlock(&intf->lock);
  1020. }
  1021. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
  1022. {
  1023. int retval;
  1024. NOTICE(rt2x00dev, "Waking up.\n");
  1025. /*
  1026. * Restore/enable extra components.
  1027. */
  1028. rt2x00debug_register(rt2x00dev);
  1029. rt2x00leds_resume(rt2x00dev);
  1030. /*
  1031. * Only continue if mac80211 had open interfaces.
  1032. */
  1033. if (!__test_and_clear_bit(DEVICE_STARTED_SUSPEND, &rt2x00dev->flags))
  1034. return 0;
  1035. /*
  1036. * Reinitialize device and all active interfaces.
  1037. */
  1038. retval = rt2x00lib_start(rt2x00dev);
  1039. if (retval)
  1040. goto exit;
  1041. /*
  1042. * Reconfigure device.
  1043. */
  1044. retval = rt2x00mac_config(rt2x00dev->hw, &rt2x00dev->hw->conf);
  1045. if (retval)
  1046. goto exit;
  1047. /*
  1048. * Iterator over each active interface to
  1049. * reconfigure the hardware.
  1050. */
  1051. ieee80211_iterate_active_interfaces(rt2x00dev->hw,
  1052. rt2x00lib_resume_intf, rt2x00dev);
  1053. /*
  1054. * We are ready again to receive requests from mac80211.
  1055. */
  1056. __set_bit(DEVICE_PRESENT, &rt2x00dev->flags);
  1057. /*
  1058. * It is possible that during that mac80211 has attempted
  1059. * to send frames while we were suspending or resuming.
  1060. * In that case we have disabled the TX queue and should
  1061. * now enable it again
  1062. */
  1063. ieee80211_wake_queues(rt2x00dev->hw);
  1064. /*
  1065. * During interface iteration we might have changed the
  1066. * delayed_flags, time to handles the event by calling
  1067. * the work handler directly.
  1068. */
  1069. rt2x00lib_intf_scheduled(&rt2x00dev->intf_work);
  1070. return 0;
  1071. exit:
  1072. rt2x00lib_disable_radio(rt2x00dev);
  1073. rt2x00lib_uninitialize(rt2x00dev);
  1074. rt2x00debug_deregister(rt2x00dev);
  1075. return retval;
  1076. }
  1077. EXPORT_SYMBOL_GPL(rt2x00lib_resume);
  1078. #endif /* CONFIG_PM */
  1079. /*
  1080. * rt2x00lib module information.
  1081. */
  1082. MODULE_AUTHOR(DRV_PROJECT);
  1083. MODULE_VERSION(DRV_VERSION);
  1084. MODULE_DESCRIPTION("rt2x00 library");
  1085. MODULE_LICENSE("GPL");