rt2x00dev.c 32 KB

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