rt2x00dev.c 32 KB

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