rt2x00dev.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00lib
  19. Abstract: rt2x00 generic device routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. /*
  26. * Link tuning handlers
  27. */
  28. void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
  29. {
  30. if (!test_bit(DEVICE_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.flags & RX_FLAG_IV_STRIPPED)) {
  533. rt2x00crypto_rx_insert_iv(entry->skb, align,
  534. header_length, &rxdesc);
  535. } else if (align) {
  536. skb_push(entry->skb, align);
  537. /* Move entire frame in 1 command */
  538. memmove(entry->skb->data, entry->skb->data + align,
  539. rxdesc.size);
  540. }
  541. /* Update data pointers, trim buffer to correct size */
  542. skb_trim(entry->skb, rxdesc.size);
  543. /*
  544. * Update RX statistics.
  545. */
  546. sband = &rt2x00dev->bands[rt2x00dev->curr_band];
  547. for (i = 0; i < sband->n_bitrates; i++) {
  548. rate = rt2x00_get_rate(sband->bitrates[i].hw_value);
  549. if (((rxdesc.dev_flags & RXDONE_SIGNAL_PLCP) &&
  550. (rate->plcp == rxdesc.signal)) ||
  551. ((rxdesc.dev_flags & RXDONE_SIGNAL_BITRATE) &&
  552. (rate->bitrate == rxdesc.signal))) {
  553. idx = i;
  554. break;
  555. }
  556. }
  557. if (idx < 0) {
  558. WARNING(rt2x00dev, "Frame received with unrecognized signal,"
  559. "signal=0x%.2x, plcp=%d.\n", rxdesc.signal,
  560. !!(rxdesc.dev_flags & RXDONE_SIGNAL_PLCP));
  561. idx = 0;
  562. }
  563. /*
  564. * Only update link status if this is a beacon frame carrying our bssid.
  565. */
  566. hdr = (struct ieee80211_hdr *)entry->skb->data;
  567. if (ieee80211_is_beacon(hdr->frame_control) &&
  568. (rxdesc.dev_flags & RXDONE_MY_BSS))
  569. rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi);
  570. rt2x00debug_update_crypto(rt2x00dev,
  571. rxdesc.cipher,
  572. rxdesc.cipher_status);
  573. rt2x00dev->link.qual.rx_success++;
  574. rx_status->mactime = rxdesc.timestamp;
  575. rx_status->rate_idx = idx;
  576. rx_status->qual =
  577. rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc.rssi);
  578. rx_status->signal = rxdesc.rssi;
  579. rx_status->flag = rxdesc.flags;
  580. rx_status->antenna = rt2x00dev->link.ant.active.rx;
  581. /*
  582. * Send frame to mac80211 & debugfs.
  583. * mac80211 will clean up the skb structure.
  584. */
  585. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
  586. ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status);
  587. /*
  588. * Replace the skb with the freshly allocated one.
  589. */
  590. entry->skb = skb;
  591. entry->flags = 0;
  592. rt2x00dev->ops->lib->clear_entry(entry);
  593. rt2x00queue_index_inc(entry->queue, Q_INDEX);
  594. }
  595. EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
  596. /*
  597. * Driver initialization handlers.
  598. */
  599. const struct rt2x00_rate rt2x00_supported_rates[12] = {
  600. {
  601. .flags = DEV_RATE_CCK,
  602. .bitrate = 10,
  603. .ratemask = BIT(0),
  604. .plcp = 0x00,
  605. },
  606. {
  607. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
  608. .bitrate = 20,
  609. .ratemask = BIT(1),
  610. .plcp = 0x01,
  611. },
  612. {
  613. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
  614. .bitrate = 55,
  615. .ratemask = BIT(2),
  616. .plcp = 0x02,
  617. },
  618. {
  619. .flags = DEV_RATE_CCK | DEV_RATE_SHORT_PREAMBLE,
  620. .bitrate = 110,
  621. .ratemask = BIT(3),
  622. .plcp = 0x03,
  623. },
  624. {
  625. .flags = DEV_RATE_OFDM,
  626. .bitrate = 60,
  627. .ratemask = BIT(4),
  628. .plcp = 0x0b,
  629. },
  630. {
  631. .flags = DEV_RATE_OFDM,
  632. .bitrate = 90,
  633. .ratemask = BIT(5),
  634. .plcp = 0x0f,
  635. },
  636. {
  637. .flags = DEV_RATE_OFDM,
  638. .bitrate = 120,
  639. .ratemask = BIT(6),
  640. .plcp = 0x0a,
  641. },
  642. {
  643. .flags = DEV_RATE_OFDM,
  644. .bitrate = 180,
  645. .ratemask = BIT(7),
  646. .plcp = 0x0e,
  647. },
  648. {
  649. .flags = DEV_RATE_OFDM,
  650. .bitrate = 240,
  651. .ratemask = BIT(8),
  652. .plcp = 0x09,
  653. },
  654. {
  655. .flags = DEV_RATE_OFDM,
  656. .bitrate = 360,
  657. .ratemask = BIT(9),
  658. .plcp = 0x0d,
  659. },
  660. {
  661. .flags = DEV_RATE_OFDM,
  662. .bitrate = 480,
  663. .ratemask = BIT(10),
  664. .plcp = 0x08,
  665. },
  666. {
  667. .flags = DEV_RATE_OFDM,
  668. .bitrate = 540,
  669. .ratemask = BIT(11),
  670. .plcp = 0x0c,
  671. },
  672. };
  673. static void rt2x00lib_channel(struct ieee80211_channel *entry,
  674. const int channel, const int tx_power,
  675. const int value)
  676. {
  677. entry->center_freq = ieee80211_channel_to_frequency(channel);
  678. entry->hw_value = value;
  679. entry->max_power = tx_power;
  680. entry->max_antenna_gain = 0xff;
  681. }
  682. static void rt2x00lib_rate(struct ieee80211_rate *entry,
  683. const u16 index, const struct rt2x00_rate *rate)
  684. {
  685. entry->flags = 0;
  686. entry->bitrate = rate->bitrate;
  687. entry->hw_value = rt2x00_create_rate_hw_value(index, 0);
  688. entry->hw_value_short = entry->hw_value;
  689. if (rate->flags & DEV_RATE_SHORT_PREAMBLE) {
  690. entry->flags |= IEEE80211_RATE_SHORT_PREAMBLE;
  691. entry->hw_value_short |= rt2x00_create_rate_hw_value(index, 1);
  692. }
  693. }
  694. static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
  695. struct hw_mode_spec *spec)
  696. {
  697. struct ieee80211_hw *hw = rt2x00dev->hw;
  698. struct ieee80211_channel *channels;
  699. struct ieee80211_rate *rates;
  700. unsigned int num_rates;
  701. unsigned int i;
  702. num_rates = 0;
  703. if (spec->supported_rates & SUPPORT_RATE_CCK)
  704. num_rates += 4;
  705. if (spec->supported_rates & SUPPORT_RATE_OFDM)
  706. num_rates += 8;
  707. channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL);
  708. if (!channels)
  709. return -ENOMEM;
  710. rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL);
  711. if (!rates)
  712. goto exit_free_channels;
  713. /*
  714. * Initialize Rate list.
  715. */
  716. for (i = 0; i < num_rates; i++)
  717. rt2x00lib_rate(&rates[i], i, rt2x00_get_rate(i));
  718. /*
  719. * Initialize Channel list.
  720. */
  721. for (i = 0; i < spec->num_channels; i++) {
  722. rt2x00lib_channel(&channels[i],
  723. spec->channels[i].channel,
  724. spec->channels_info[i].tx_power1, i);
  725. }
  726. /*
  727. * Intitialize 802.11b, 802.11g
  728. * Rates: CCK, OFDM.
  729. * Channels: 2.4 GHz
  730. */
  731. if (spec->supported_bands & SUPPORT_BAND_2GHZ) {
  732. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_channels = 14;
  733. rt2x00dev->bands[IEEE80211_BAND_2GHZ].n_bitrates = num_rates;
  734. rt2x00dev->bands[IEEE80211_BAND_2GHZ].channels = channels;
  735. rt2x00dev->bands[IEEE80211_BAND_2GHZ].bitrates = rates;
  736. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  737. &rt2x00dev->bands[IEEE80211_BAND_2GHZ];
  738. }
  739. /*
  740. * Intitialize 802.11a
  741. * Rates: OFDM.
  742. * Channels: OFDM, UNII, HiperLAN2.
  743. */
  744. if (spec->supported_bands & SUPPORT_BAND_5GHZ) {
  745. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_channels =
  746. spec->num_channels - 14;
  747. rt2x00dev->bands[IEEE80211_BAND_5GHZ].n_bitrates =
  748. num_rates - 4;
  749. rt2x00dev->bands[IEEE80211_BAND_5GHZ].channels = &channels[14];
  750. rt2x00dev->bands[IEEE80211_BAND_5GHZ].bitrates = &rates[4];
  751. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  752. &rt2x00dev->bands[IEEE80211_BAND_5GHZ];
  753. }
  754. return 0;
  755. exit_free_channels:
  756. kfree(channels);
  757. ERROR(rt2x00dev, "Allocation ieee80211 modes failed.\n");
  758. return -ENOMEM;
  759. }
  760. static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev)
  761. {
  762. if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
  763. ieee80211_unregister_hw(rt2x00dev->hw);
  764. if (likely(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ])) {
  765. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
  766. kfree(rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->bitrates);
  767. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  768. rt2x00dev->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  769. }
  770. kfree(rt2x00dev->spec.channels_info);
  771. }
  772. static int rt2x00lib_probe_hw(struct rt2x00_dev *rt2x00dev)
  773. {
  774. struct hw_mode_spec *spec = &rt2x00dev->spec;
  775. int status;
  776. if (test_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags))
  777. return 0;
  778. /*
  779. * Initialize HW modes.
  780. */
  781. status = rt2x00lib_probe_hw_modes(rt2x00dev, spec);
  782. if (status)
  783. return status;
  784. /*
  785. * Initialize HW fields.
  786. */
  787. rt2x00dev->hw->queues = rt2x00dev->ops->tx_queues;
  788. /*
  789. * Register HW.
  790. */
  791. status = ieee80211_register_hw(rt2x00dev->hw);
  792. if (status) {
  793. rt2x00lib_remove_hw(rt2x00dev);
  794. return status;
  795. }
  796. set_bit(DEVICE_STATE_REGISTERED_HW, &rt2x00dev->flags);
  797. return 0;
  798. }
  799. /*
  800. * Initialization/uninitialization handlers.
  801. */
  802. static void rt2x00lib_uninitialize(struct rt2x00_dev *rt2x00dev)
  803. {
  804. if (!test_and_clear_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
  805. return;
  806. /*
  807. * Unregister extra components.
  808. */
  809. rt2x00rfkill_unregister(rt2x00dev);
  810. /*
  811. * Allow the HW to uninitialize.
  812. */
  813. rt2x00dev->ops->lib->uninitialize(rt2x00dev);
  814. /*
  815. * Free allocated queue entries.
  816. */
  817. rt2x00queue_uninitialize(rt2x00dev);
  818. }
  819. static int rt2x00lib_initialize(struct rt2x00_dev *rt2x00dev)
  820. {
  821. int status;
  822. if (test_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags))
  823. return 0;
  824. /*
  825. * Allocate all queue entries.
  826. */
  827. status = rt2x00queue_initialize(rt2x00dev);
  828. if (status)
  829. return status;
  830. /*
  831. * Initialize the device.
  832. */
  833. status = rt2x00dev->ops->lib->initialize(rt2x00dev);
  834. if (status) {
  835. rt2x00queue_uninitialize(rt2x00dev);
  836. return status;
  837. }
  838. set_bit(DEVICE_STATE_INITIALIZED, &rt2x00dev->flags);
  839. /*
  840. * Register the extra components.
  841. */
  842. rt2x00rfkill_register(rt2x00dev);
  843. return 0;
  844. }
  845. int rt2x00lib_start(struct rt2x00_dev *rt2x00dev)
  846. {
  847. int retval;
  848. if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
  849. return 0;
  850. /*
  851. * If this is the first interface which is added,
  852. * we should load the firmware now.
  853. */
  854. retval = rt2x00lib_load_firmware(rt2x00dev);
  855. if (retval)
  856. return retval;
  857. /*
  858. * Initialize the device.
  859. */
  860. retval = rt2x00lib_initialize(rt2x00dev);
  861. if (retval)
  862. return retval;
  863. rt2x00dev->intf_ap_count = 0;
  864. rt2x00dev->intf_sta_count = 0;
  865. rt2x00dev->intf_associated = 0;
  866. set_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags);
  867. return 0;
  868. }
  869. void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev)
  870. {
  871. if (!test_and_clear_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
  872. return;
  873. /*
  874. * Perhaps we can add something smarter here,
  875. * but for now just disabling the radio should do.
  876. */
  877. rt2x00lib_disable_radio(rt2x00dev);
  878. rt2x00dev->intf_ap_count = 0;
  879. rt2x00dev->intf_sta_count = 0;
  880. rt2x00dev->intf_associated = 0;
  881. }
  882. /*
  883. * driver allocation handlers.
  884. */
  885. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
  886. {
  887. int retval = -ENOMEM;
  888. mutex_init(&rt2x00dev->csr_mutex);
  889. /*
  890. * Make room for rt2x00_intf inside the per-interface
  891. * structure ieee80211_vif.
  892. */
  893. rt2x00dev->hw->vif_data_size = sizeof(struct rt2x00_intf);
  894. /*
  895. * Determine which operating modes are supported, all modes
  896. * which require beaconing, depend on the availability of
  897. * beacon entries.
  898. */
  899. rt2x00dev->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  900. if (rt2x00dev->ops->bcn->entry_num > 0)
  901. rt2x00dev->hw->wiphy->interface_modes |=
  902. BIT(NL80211_IFTYPE_ADHOC) |
  903. BIT(NL80211_IFTYPE_AP);
  904. /*
  905. * Let the driver probe the device to detect the capabilities.
  906. */
  907. retval = rt2x00dev->ops->lib->probe_hw(rt2x00dev);
  908. if (retval) {
  909. ERROR(rt2x00dev, "Failed to allocate device.\n");
  910. goto exit;
  911. }
  912. /*
  913. * Initialize configuration work.
  914. */
  915. INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
  916. INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
  917. INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
  918. /*
  919. * Allocate queue array.
  920. */
  921. retval = rt2x00queue_allocate(rt2x00dev);
  922. if (retval)
  923. goto exit;
  924. /*
  925. * Initialize ieee80211 structure.
  926. */
  927. retval = rt2x00lib_probe_hw(rt2x00dev);
  928. if (retval) {
  929. ERROR(rt2x00dev, "Failed to initialize hw.\n");
  930. goto exit;
  931. }
  932. /*
  933. * Register extra components.
  934. */
  935. rt2x00leds_register(rt2x00dev);
  936. rt2x00rfkill_allocate(rt2x00dev);
  937. rt2x00debug_register(rt2x00dev);
  938. set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  939. return 0;
  940. exit:
  941. rt2x00lib_remove_dev(rt2x00dev);
  942. return retval;
  943. }
  944. EXPORT_SYMBOL_GPL(rt2x00lib_probe_dev);
  945. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
  946. {
  947. clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  948. /*
  949. * Disable radio.
  950. */
  951. rt2x00lib_disable_radio(rt2x00dev);
  952. /*
  953. * Uninitialize device.
  954. */
  955. rt2x00lib_uninitialize(rt2x00dev);
  956. /*
  957. * Free extra components
  958. */
  959. rt2x00debug_deregister(rt2x00dev);
  960. rt2x00rfkill_free(rt2x00dev);
  961. rt2x00leds_unregister(rt2x00dev);
  962. /*
  963. * Free ieee80211_hw memory.
  964. */
  965. rt2x00lib_remove_hw(rt2x00dev);
  966. /*
  967. * Free firmware image.
  968. */
  969. rt2x00lib_free_firmware(rt2x00dev);
  970. /*
  971. * Free queue structures.
  972. */
  973. rt2x00queue_free(rt2x00dev);
  974. }
  975. EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
  976. /*
  977. * Device state handlers
  978. */
  979. #ifdef CONFIG_PM
  980. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
  981. {
  982. int retval;
  983. NOTICE(rt2x00dev, "Going to sleep.\n");
  984. /*
  985. * Only continue if mac80211 has open interfaces.
  986. */
  987. if (!test_and_clear_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
  988. !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
  989. goto exit;
  990. set_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags);
  991. /*
  992. * Disable radio.
  993. */
  994. rt2x00lib_stop(rt2x00dev);
  995. rt2x00lib_uninitialize(rt2x00dev);
  996. /*
  997. * Suspend/disable extra components.
  998. */
  999. rt2x00leds_suspend(rt2x00dev);
  1000. rt2x00debug_deregister(rt2x00dev);
  1001. exit:
  1002. /*
  1003. * Set device mode to sleep for power management,
  1004. * on some hardware this call seems to consistently fail.
  1005. * From the specifications it is hard to tell why it fails,
  1006. * and if this is a "bad thing".
  1007. * Overall it is safe to just ignore the failure and
  1008. * continue suspending. The only downside is that the
  1009. * device will not be in optimal power save mode, but with
  1010. * the radio and the other components already disabled the
  1011. * device is as good as disabled.
  1012. */
  1013. retval = rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_SLEEP);
  1014. if (retval)
  1015. WARNING(rt2x00dev, "Device failed to enter sleep state, "
  1016. "continue suspending.\n");
  1017. return 0;
  1018. }
  1019. EXPORT_SYMBOL_GPL(rt2x00lib_suspend);
  1020. static void rt2x00lib_resume_intf(void *data, u8 *mac,
  1021. struct ieee80211_vif *vif)
  1022. {
  1023. struct rt2x00_dev *rt2x00dev = data;
  1024. struct rt2x00_intf *intf = vif_to_intf(vif);
  1025. spin_lock(&intf->lock);
  1026. rt2x00lib_config_intf(rt2x00dev, intf,
  1027. vif->type, intf->mac, intf->bssid);
  1028. /*
  1029. * Master or Ad-hoc mode require a new beacon update.
  1030. */
  1031. if (vif->type == NL80211_IFTYPE_AP ||
  1032. vif->type == NL80211_IFTYPE_ADHOC)
  1033. intf->delayed_flags |= DELAYED_UPDATE_BEACON;
  1034. spin_unlock(&intf->lock);
  1035. }
  1036. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
  1037. {
  1038. int retval;
  1039. NOTICE(rt2x00dev, "Waking up.\n");
  1040. /*
  1041. * Restore/enable extra components.
  1042. */
  1043. rt2x00debug_register(rt2x00dev);
  1044. rt2x00leds_resume(rt2x00dev);
  1045. /*
  1046. * Only continue if mac80211 had open interfaces.
  1047. */
  1048. if (!test_and_clear_bit(DEVICE_STATE_STARTED_SUSPEND, &rt2x00dev->flags))
  1049. return 0;
  1050. /*
  1051. * Reinitialize device and all active interfaces.
  1052. */
  1053. retval = rt2x00lib_start(rt2x00dev);
  1054. if (retval)
  1055. goto exit;
  1056. /*
  1057. * Reconfigure device.
  1058. */
  1059. retval = rt2x00mac_config(rt2x00dev->hw, ~0);
  1060. if (retval)
  1061. goto exit;
  1062. /*
  1063. * Iterator over each active interface to
  1064. * reconfigure the hardware.
  1065. */
  1066. ieee80211_iterate_active_interfaces(rt2x00dev->hw,
  1067. rt2x00lib_resume_intf, rt2x00dev);
  1068. /*
  1069. * We are ready again to receive requests from mac80211.
  1070. */
  1071. set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
  1072. /*
  1073. * It is possible that during that mac80211 has attempted
  1074. * to send frames while we were suspending or resuming.
  1075. * In that case we have disabled the TX queue and should
  1076. * now enable it again
  1077. */
  1078. ieee80211_wake_queues(rt2x00dev->hw);
  1079. /*
  1080. * During interface iteration we might have changed the
  1081. * delayed_flags, time to handles the event by calling
  1082. * the work handler directly.
  1083. */
  1084. rt2x00lib_intf_scheduled(&rt2x00dev->intf_work);
  1085. return 0;
  1086. exit:
  1087. rt2x00lib_stop(rt2x00dev);
  1088. rt2x00lib_uninitialize(rt2x00dev);
  1089. rt2x00debug_deregister(rt2x00dev);
  1090. return retval;
  1091. }
  1092. EXPORT_SYMBOL_GPL(rt2x00lib_resume);
  1093. #endif /* CONFIG_PM */
  1094. /*
  1095. * rt2x00lib module information.
  1096. */
  1097. MODULE_AUTHOR(DRV_PROJECT);
  1098. MODULE_VERSION(DRV_VERSION);
  1099. MODULE_DESCRIPTION("rt2x00 library");
  1100. MODULE_LICENSE("GPL");