rt2x00.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. /*
  2. Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  3. Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
  4. Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  5. <http://rt2x00.serialmonkey.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. Module: rt2x00
  19. Abstract: rt2x00 global information.
  20. */
  21. #ifndef RT2X00_H
  22. #define RT2X00_H
  23. #include <linux/bitops.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/firmware.h>
  28. #include <linux/leds.h>
  29. #include <linux/mutex.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/input-polldev.h>
  32. #include <linux/kfifo.h>
  33. #include <linux/hrtimer.h>
  34. #include <linux/average.h>
  35. #include <linux/usb.h>
  36. #include <linux/clk.h>
  37. #include <net/mac80211.h>
  38. #include "rt2x00debug.h"
  39. #include "rt2x00dump.h"
  40. #include "rt2x00leds.h"
  41. #include "rt2x00reg.h"
  42. #include "rt2x00queue.h"
  43. /*
  44. * Module information.
  45. */
  46. #define DRV_VERSION "2.3.0"
  47. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  48. /* Debug definitions.
  49. * Debug output has to be enabled during compile time.
  50. */
  51. #ifdef CONFIG_RT2X00_DEBUG
  52. #define DEBUG
  53. #endif /* CONFIG_RT2X00_DEBUG */
  54. /* Utility printing macros
  55. * rt2x00_probe_err is for messages when rt2x00_dev is uninitialized
  56. */
  57. #define rt2x00_probe_err(fmt, ...) \
  58. printk(KERN_ERR KBUILD_MODNAME ": %s: Error - " fmt, \
  59. __func__, ##__VA_ARGS__)
  60. #define rt2x00_err(dev, fmt, ...) \
  61. wiphy_err((dev)->hw->wiphy, "%s: Error - " fmt, \
  62. __func__, ##__VA_ARGS__)
  63. #define rt2x00_warn(dev, fmt, ...) \
  64. wiphy_warn((dev)->hw->wiphy, "%s: Warning - " fmt, \
  65. __func__, ##__VA_ARGS__)
  66. #define rt2x00_info(dev, fmt, ...) \
  67. wiphy_info((dev)->hw->wiphy, "%s: Info - " fmt, \
  68. __func__, ##__VA_ARGS__)
  69. /* Various debug levels */
  70. #define rt2x00_dbg(dev, fmt, ...) \
  71. wiphy_dbg((dev)->hw->wiphy, "%s: Debug - " fmt, \
  72. __func__, ##__VA_ARGS__)
  73. #define rt2x00_eeprom_dbg(dev, fmt, ...) \
  74. wiphy_dbg((dev)->hw->wiphy, "%s: EEPROM recovery - " fmt, \
  75. __func__, ##__VA_ARGS__)
  76. /*
  77. * Duration calculations
  78. * The rate variable passed is: 100kbs.
  79. * To convert from bytes to bits we multiply size with 8,
  80. * then the size is multiplied with 10 to make the
  81. * real rate -> rate argument correction.
  82. */
  83. #define GET_DURATION(__size, __rate) (((__size) * 8 * 10) / (__rate))
  84. #define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
  85. /*
  86. * Determine the number of L2 padding bytes required between the header and
  87. * the payload.
  88. */
  89. #define L2PAD_SIZE(__hdrlen) (-(__hdrlen) & 3)
  90. /*
  91. * Determine the alignment requirement,
  92. * to make sure the 802.11 payload is padded to a 4-byte boundrary
  93. * we must determine the address of the payload and calculate the
  94. * amount of bytes needed to move the data.
  95. */
  96. #define ALIGN_SIZE(__skb, __header) \
  97. (((unsigned long)((__skb)->data + (__header))) & 3)
  98. /*
  99. * Constants for extra TX headroom for alignment purposes.
  100. */
  101. #define RT2X00_ALIGN_SIZE 4 /* Only whole frame needs alignment */
  102. #define RT2X00_L2PAD_SIZE 8 /* Both header & payload need alignment */
  103. /*
  104. * Standard timing and size defines.
  105. * These values should follow the ieee80211 specifications.
  106. */
  107. #define ACK_SIZE 14
  108. #define IEEE80211_HEADER 24
  109. #define PLCP 48
  110. #define BEACON 100
  111. #define PREAMBLE 144
  112. #define SHORT_PREAMBLE 72
  113. #define SLOT_TIME 20
  114. #define SHORT_SLOT_TIME 9
  115. #define SIFS 10
  116. #define PIFS (SIFS + SLOT_TIME)
  117. #define SHORT_PIFS (SIFS + SHORT_SLOT_TIME)
  118. #define DIFS (PIFS + SLOT_TIME)
  119. #define SHORT_DIFS (SHORT_PIFS + SHORT_SLOT_TIME)
  120. #define EIFS (SIFS + DIFS + \
  121. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
  122. #define SHORT_EIFS (SIFS + SHORT_DIFS + \
  123. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10))
  124. enum rt2x00_chip_intf {
  125. RT2X00_CHIP_INTF_PCI,
  126. RT2X00_CHIP_INTF_PCIE,
  127. RT2X00_CHIP_INTF_USB,
  128. RT2X00_CHIP_INTF_SOC,
  129. };
  130. /*
  131. * Chipset identification
  132. * The chipset on the device is composed of a RT and RF chip.
  133. * The chipset combination is important for determining device capabilities.
  134. */
  135. struct rt2x00_chip {
  136. u16 rt;
  137. #define RT2460 0x2460
  138. #define RT2560 0x2560
  139. #define RT2570 0x2570
  140. #define RT2661 0x2661
  141. #define RT2573 0x2573
  142. #define RT2860 0x2860 /* 2.4GHz */
  143. #define RT2872 0x2872 /* WSOC */
  144. #define RT2883 0x2883 /* WSOC */
  145. #define RT3070 0x3070
  146. #define RT3071 0x3071
  147. #define RT3090 0x3090 /* 2.4GHz PCIe */
  148. #define RT3290 0x3290
  149. #define RT3352 0x3352 /* WSOC */
  150. #define RT3390 0x3390
  151. #define RT3572 0x3572
  152. #define RT3593 0x3593
  153. #define RT3883 0x3883 /* WSOC */
  154. #define RT5350 0x5350 /* WSOC 2.4GHz */
  155. #define RT5390 0x5390 /* 2.4GHz */
  156. #define RT5392 0x5392 /* 2.4GHz */
  157. #define RT5592 0x5592
  158. #define RT6352 0x6352 /* WSOC 2.4GHz */
  159. u16 rf;
  160. u16 rev;
  161. enum rt2x00_chip_intf intf;
  162. };
  163. /*
  164. * RF register values that belong to a particular channel.
  165. */
  166. struct rf_channel {
  167. int channel;
  168. u32 rf1;
  169. u32 rf2;
  170. u32 rf3;
  171. u32 rf4;
  172. };
  173. /*
  174. * Channel information structure
  175. */
  176. struct channel_info {
  177. unsigned int flags;
  178. #define GEOGRAPHY_ALLOWED 0x00000001
  179. short max_power;
  180. short default_power1;
  181. short default_power2;
  182. short default_power3;
  183. };
  184. /*
  185. * Antenna setup values.
  186. */
  187. struct antenna_setup {
  188. enum antenna rx;
  189. enum antenna tx;
  190. u8 rx_chain_num;
  191. u8 tx_chain_num;
  192. };
  193. /*
  194. * Quality statistics about the currently active link.
  195. */
  196. struct link_qual {
  197. /*
  198. * Statistics required for Link tuning by driver
  199. * The rssi value is provided by rt2x00lib during the
  200. * link_tuner() callback function.
  201. * The false_cca field is filled during the link_stats()
  202. * callback function and could be used during the
  203. * link_tuner() callback function.
  204. */
  205. int rssi;
  206. int false_cca;
  207. /*
  208. * VGC levels
  209. * Hardware driver will tune the VGC level during each call
  210. * to the link_tuner() callback function. This vgc_level is
  211. * is determined based on the link quality statistics like
  212. * average RSSI and the false CCA count.
  213. *
  214. * In some cases the drivers need to differentiate between
  215. * the currently "desired" VGC level and the level configured
  216. * in the hardware. The latter is important to reduce the
  217. * number of BBP register reads to reduce register access
  218. * overhead. For this reason we store both values here.
  219. */
  220. u8 vgc_level;
  221. u8 vgc_level_reg;
  222. /*
  223. * Statistics required for Signal quality calculation.
  224. * These fields might be changed during the link_stats()
  225. * callback function.
  226. */
  227. int rx_success;
  228. int rx_failed;
  229. int tx_success;
  230. int tx_failed;
  231. };
  232. DECLARE_EWMA(rssi, 10, 8)
  233. /*
  234. * Antenna settings about the currently active link.
  235. */
  236. struct link_ant {
  237. /*
  238. * Antenna flags
  239. */
  240. unsigned int flags;
  241. #define ANTENNA_RX_DIVERSITY 0x00000001
  242. #define ANTENNA_TX_DIVERSITY 0x00000002
  243. #define ANTENNA_MODE_SAMPLE 0x00000004
  244. /*
  245. * Currently active TX/RX antenna setup.
  246. * When software diversity is used, this will indicate
  247. * which antenna is actually used at this time.
  248. */
  249. struct antenna_setup active;
  250. /*
  251. * RSSI history information for the antenna.
  252. * Used to determine when to switch antenna
  253. * when using software diversity.
  254. */
  255. int rssi_history;
  256. /*
  257. * Current RSSI average of the currently active antenna.
  258. * Similar to the avg_rssi in the link_qual structure
  259. * this value is updated by using the walking average.
  260. */
  261. struct ewma_rssi rssi_ant;
  262. };
  263. /*
  264. * To optimize the quality of the link we need to store
  265. * the quality of received frames and periodically
  266. * optimize the link.
  267. */
  268. struct link {
  269. /*
  270. * Link tuner counter
  271. * The number of times the link has been tuned
  272. * since the radio has been switched on.
  273. */
  274. u32 count;
  275. /*
  276. * Quality measurement values.
  277. */
  278. struct link_qual qual;
  279. /*
  280. * TX/RX antenna setup.
  281. */
  282. struct link_ant ant;
  283. /*
  284. * Currently active average RSSI value
  285. */
  286. struct ewma_rssi avg_rssi;
  287. /*
  288. * Work structure for scheduling periodic link tuning.
  289. */
  290. struct delayed_work work;
  291. /*
  292. * Work structure for scheduling periodic watchdog monitoring.
  293. * This work must be scheduled on the kernel workqueue, while
  294. * all other work structures must be queued on the mac80211
  295. * workqueue. This guarantees that the watchdog can schedule
  296. * other work structures and wait for their completion in order
  297. * to bring the device/driver back into the desired state.
  298. */
  299. struct delayed_work watchdog_work;
  300. /*
  301. * Work structure for scheduling periodic AGC adjustments.
  302. */
  303. struct delayed_work agc_work;
  304. /*
  305. * Work structure for scheduling periodic VCO calibration.
  306. */
  307. struct delayed_work vco_work;
  308. };
  309. enum rt2x00_delayed_flags {
  310. DELAYED_UPDATE_BEACON,
  311. };
  312. /*
  313. * Interface structure
  314. * Per interface configuration details, this structure
  315. * is allocated as the private data for ieee80211_vif.
  316. */
  317. struct rt2x00_intf {
  318. /*
  319. * beacon->skb must be protected with the mutex.
  320. */
  321. struct mutex beacon_skb_mutex;
  322. /*
  323. * Entry in the beacon queue which belongs to
  324. * this interface. Each interface has its own
  325. * dedicated beacon entry.
  326. */
  327. struct queue_entry *beacon;
  328. bool enable_beacon;
  329. /*
  330. * Actions that needed rescheduling.
  331. */
  332. unsigned long delayed_flags;
  333. /*
  334. * Software sequence counter, this is only required
  335. * for hardware which doesn't support hardware
  336. * sequence counting.
  337. */
  338. atomic_t seqno;
  339. };
  340. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  341. {
  342. return (struct rt2x00_intf *)vif->drv_priv;
  343. }
  344. /**
  345. * struct hw_mode_spec: Hardware specifications structure
  346. *
  347. * Details about the supported modes, rates and channels
  348. * of a particular chipset. This is used by rt2x00lib
  349. * to build the ieee80211_hw_mode array for mac80211.
  350. *
  351. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  352. * @supported_rates: Rate types which are supported (CCK, OFDM).
  353. * @num_channels: Number of supported channels. This is used as array size
  354. * for @tx_power_a, @tx_power_bg and @channels.
  355. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  356. * @channels_info: Additional information for channels (See &struct channel_info).
  357. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  358. */
  359. struct hw_mode_spec {
  360. unsigned int supported_bands;
  361. #define SUPPORT_BAND_2GHZ 0x00000001
  362. #define SUPPORT_BAND_5GHZ 0x00000002
  363. unsigned int supported_rates;
  364. #define SUPPORT_RATE_CCK 0x00000001
  365. #define SUPPORT_RATE_OFDM 0x00000002
  366. unsigned int num_channels;
  367. const struct rf_channel *channels;
  368. const struct channel_info *channels_info;
  369. struct ieee80211_sta_ht_cap ht;
  370. };
  371. /*
  372. * Configuration structure wrapper around the
  373. * mac80211 configuration structure.
  374. * When mac80211 configures the driver, rt2x00lib
  375. * can precalculate values which are equal for all
  376. * rt2x00 drivers. Those values can be stored in here.
  377. */
  378. struct rt2x00lib_conf {
  379. struct ieee80211_conf *conf;
  380. struct rf_channel rf;
  381. struct channel_info channel;
  382. };
  383. /*
  384. * Configuration structure for erp settings.
  385. */
  386. struct rt2x00lib_erp {
  387. int short_preamble;
  388. int cts_protection;
  389. u32 basic_rates;
  390. int slot_time;
  391. short sifs;
  392. short pifs;
  393. short difs;
  394. short eifs;
  395. u16 beacon_int;
  396. u16 ht_opmode;
  397. };
  398. /*
  399. * Configuration structure for hardware encryption.
  400. */
  401. struct rt2x00lib_crypto {
  402. enum cipher cipher;
  403. enum set_key_cmd cmd;
  404. const u8 *address;
  405. u32 bssidx;
  406. u8 key[16];
  407. u8 tx_mic[8];
  408. u8 rx_mic[8];
  409. int wcid;
  410. };
  411. /*
  412. * Configuration structure wrapper around the
  413. * rt2x00 interface configuration handler.
  414. */
  415. struct rt2x00intf_conf {
  416. /*
  417. * Interface type
  418. */
  419. enum nl80211_iftype type;
  420. /*
  421. * TSF sync value, this is dependent on the operation type.
  422. */
  423. enum tsf_sync sync;
  424. /*
  425. * The MAC and BSSID addresses are simple array of bytes,
  426. * these arrays are little endian, so when sending the addresses
  427. * to the drivers, copy the it into a endian-signed variable.
  428. *
  429. * Note that all devices (except rt2500usb) have 32 bits
  430. * register word sizes. This means that whatever variable we
  431. * pass _must_ be a multiple of 32 bits. Otherwise the device
  432. * might not accept what we are sending to it.
  433. * This will also make it easier for the driver to write
  434. * the data to the device.
  435. */
  436. __le32 mac[2];
  437. __le32 bssid[2];
  438. };
  439. /*
  440. * Private structure for storing STA details
  441. * wcid: Wireless Client ID
  442. */
  443. struct rt2x00_sta {
  444. int wcid;
  445. };
  446. static inline struct rt2x00_sta* sta_to_rt2x00_sta(struct ieee80211_sta *sta)
  447. {
  448. return (struct rt2x00_sta *)sta->drv_priv;
  449. }
  450. /*
  451. * rt2x00lib callback functions.
  452. */
  453. struct rt2x00lib_ops {
  454. /*
  455. * Interrupt handlers.
  456. */
  457. irq_handler_t irq_handler;
  458. /*
  459. * TX status tasklet handler.
  460. */
  461. void (*txstatus_tasklet) (unsigned long data);
  462. void (*pretbtt_tasklet) (unsigned long data);
  463. void (*tbtt_tasklet) (unsigned long data);
  464. void (*rxdone_tasklet) (unsigned long data);
  465. void (*autowake_tasklet) (unsigned long data);
  466. /*
  467. * Device init handlers.
  468. */
  469. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  470. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  471. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  472. const u8 *data, const size_t len);
  473. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  474. const u8 *data, const size_t len);
  475. /*
  476. * Device initialization/deinitialization handlers.
  477. */
  478. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  479. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  480. /*
  481. * queue initialization handlers
  482. */
  483. bool (*get_entry_state) (struct queue_entry *entry);
  484. void (*clear_entry) (struct queue_entry *entry);
  485. /*
  486. * Radio control handlers.
  487. */
  488. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  489. enum dev_state state);
  490. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  491. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  492. struct link_qual *qual);
  493. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  494. struct link_qual *qual);
  495. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  496. struct link_qual *qual, const u32 count);
  497. void (*gain_calibration) (struct rt2x00_dev *rt2x00dev);
  498. void (*vco_calibration) (struct rt2x00_dev *rt2x00dev);
  499. /*
  500. * Data queue handlers.
  501. */
  502. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  503. void (*start_queue) (struct data_queue *queue);
  504. void (*kick_queue) (struct data_queue *queue);
  505. void (*stop_queue) (struct data_queue *queue);
  506. void (*flush_queue) (struct data_queue *queue, bool drop);
  507. void (*tx_dma_done) (struct queue_entry *entry);
  508. /*
  509. * TX control handlers
  510. */
  511. void (*write_tx_desc) (struct queue_entry *entry,
  512. struct txentry_desc *txdesc);
  513. void (*write_tx_data) (struct queue_entry *entry,
  514. struct txentry_desc *txdesc);
  515. void (*write_beacon) (struct queue_entry *entry,
  516. struct txentry_desc *txdesc);
  517. void (*clear_beacon) (struct queue_entry *entry);
  518. int (*get_tx_data_len) (struct queue_entry *entry);
  519. /*
  520. * RX control handlers
  521. */
  522. void (*fill_rxdone) (struct queue_entry *entry,
  523. struct rxdone_entry_desc *rxdesc);
  524. /*
  525. * Configuration handlers.
  526. */
  527. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  528. struct rt2x00lib_crypto *crypto,
  529. struct ieee80211_key_conf *key);
  530. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  531. struct rt2x00lib_crypto *crypto,
  532. struct ieee80211_key_conf *key);
  533. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  534. const unsigned int filter_flags);
  535. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  536. struct rt2x00_intf *intf,
  537. struct rt2x00intf_conf *conf,
  538. const unsigned int flags);
  539. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  540. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  541. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  542. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  543. struct rt2x00lib_erp *erp,
  544. u32 changed);
  545. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  546. struct antenna_setup *ant);
  547. void (*config) (struct rt2x00_dev *rt2x00dev,
  548. struct rt2x00lib_conf *libconf,
  549. const unsigned int changed_flags);
  550. int (*sta_add) (struct rt2x00_dev *rt2x00dev,
  551. struct ieee80211_vif *vif,
  552. struct ieee80211_sta *sta);
  553. int (*sta_remove) (struct rt2x00_dev *rt2x00dev,
  554. struct ieee80211_sta *sta);
  555. };
  556. /*
  557. * rt2x00 driver callback operation structure.
  558. */
  559. struct rt2x00_ops {
  560. const char *name;
  561. const unsigned int drv_data_size;
  562. const unsigned int max_ap_intf;
  563. const unsigned int eeprom_size;
  564. const unsigned int rf_size;
  565. const unsigned int tx_queues;
  566. void (*queue_init)(struct data_queue *queue);
  567. const struct rt2x00lib_ops *lib;
  568. const void *drv;
  569. const struct ieee80211_ops *hw;
  570. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  571. const struct rt2x00debug *debugfs;
  572. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  573. };
  574. /*
  575. * rt2x00 state flags
  576. */
  577. enum rt2x00_state_flags {
  578. /*
  579. * Device flags
  580. */
  581. DEVICE_STATE_PRESENT,
  582. DEVICE_STATE_REGISTERED_HW,
  583. DEVICE_STATE_INITIALIZED,
  584. DEVICE_STATE_STARTED,
  585. DEVICE_STATE_ENABLED_RADIO,
  586. DEVICE_STATE_SCANNING,
  587. /*
  588. * Driver configuration
  589. */
  590. CONFIG_CHANNEL_HT40,
  591. CONFIG_POWERSAVING,
  592. CONFIG_HT_DISABLED,
  593. CONFIG_QOS_DISABLED,
  594. CONFIG_MONITORING,
  595. /*
  596. * Mark we currently are sequentially reading TX_STA_FIFO register
  597. * FIXME: this is for only rt2800usb, should go to private data
  598. */
  599. TX_STATUS_READING,
  600. };
  601. /*
  602. * rt2x00 capability flags
  603. */
  604. enum rt2x00_capability_flags {
  605. /*
  606. * Requirements
  607. */
  608. REQUIRE_FIRMWARE,
  609. REQUIRE_BEACON_GUARD,
  610. REQUIRE_ATIM_QUEUE,
  611. REQUIRE_DMA,
  612. REQUIRE_COPY_IV,
  613. REQUIRE_L2PAD,
  614. REQUIRE_TXSTATUS_FIFO,
  615. REQUIRE_TASKLET_CONTEXT,
  616. REQUIRE_SW_SEQNO,
  617. REQUIRE_HT_TX_DESC,
  618. REQUIRE_PS_AUTOWAKE,
  619. REQUIRE_DELAYED_RFKILL,
  620. /*
  621. * Capabilities
  622. */
  623. CAPABILITY_HW_BUTTON,
  624. CAPABILITY_HW_CRYPTO,
  625. CAPABILITY_POWER_LIMIT,
  626. CAPABILITY_CONTROL_FILTERS,
  627. CAPABILITY_CONTROL_FILTER_PSPOLL,
  628. CAPABILITY_PRE_TBTT_INTERRUPT,
  629. CAPABILITY_LINK_TUNING,
  630. CAPABILITY_FRAME_TYPE,
  631. CAPABILITY_RF_SEQUENCE,
  632. CAPABILITY_EXTERNAL_LNA_A,
  633. CAPABILITY_EXTERNAL_LNA_BG,
  634. CAPABILITY_DOUBLE_ANTENNA,
  635. CAPABILITY_BT_COEXIST,
  636. CAPABILITY_VCO_RECALIBRATION,
  637. CAPABILITY_EXTERNAL_PA_TX0,
  638. CAPABILITY_EXTERNAL_PA_TX1,
  639. };
  640. /*
  641. * Interface combinations
  642. */
  643. enum {
  644. IF_COMB_AP = 0,
  645. NUM_IF_COMB,
  646. };
  647. /*
  648. * rt2x00 device structure.
  649. */
  650. struct rt2x00_dev {
  651. /*
  652. * Device structure.
  653. * The structure stored in here depends on the
  654. * system bus (PCI or USB).
  655. * When accessing this variable, the rt2x00dev_{pci,usb}
  656. * macros should be used for correct typecasting.
  657. */
  658. struct device *dev;
  659. /*
  660. * Callback functions.
  661. */
  662. const struct rt2x00_ops *ops;
  663. /*
  664. * Driver data.
  665. */
  666. void *drv_data;
  667. /*
  668. * IEEE80211 control structure.
  669. */
  670. struct ieee80211_hw *hw;
  671. struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
  672. enum nl80211_band curr_band;
  673. int curr_freq;
  674. /*
  675. * If enabled, the debugfs interface structures
  676. * required for deregistration of debugfs.
  677. */
  678. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  679. struct rt2x00debug_intf *debugfs_intf;
  680. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  681. /*
  682. * LED structure for changing the LED status
  683. * by mac8011 or the kernel.
  684. */
  685. #ifdef CONFIG_RT2X00_LIB_LEDS
  686. struct rt2x00_led led_radio;
  687. struct rt2x00_led led_assoc;
  688. struct rt2x00_led led_qual;
  689. u16 led_mcu_reg;
  690. #endif /* CONFIG_RT2X00_LIB_LEDS */
  691. /*
  692. * Device state flags.
  693. * In these flags the current status is stored.
  694. * Access to these flags should occur atomically.
  695. */
  696. unsigned long flags;
  697. /*
  698. * Device capabiltiy flags.
  699. * In these flags the device/driver capabilities are stored.
  700. * Access to these flags should occur non-atomically.
  701. */
  702. unsigned long cap_flags;
  703. /*
  704. * Device information, Bus IRQ and name (PCI, SoC)
  705. */
  706. int irq;
  707. const char *name;
  708. /*
  709. * Chipset identification.
  710. */
  711. struct rt2x00_chip chip;
  712. /*
  713. * hw capability specifications.
  714. */
  715. struct hw_mode_spec spec;
  716. /*
  717. * This is the default TX/RX antenna setup as indicated
  718. * by the device's EEPROM.
  719. */
  720. struct antenna_setup default_ant;
  721. /*
  722. * Register pointers
  723. * csr.base: CSR base register address. (PCI)
  724. * csr.cache: CSR cache for usb_control_msg. (USB)
  725. */
  726. union csr {
  727. void __iomem *base;
  728. void *cache;
  729. } csr;
  730. /*
  731. * Mutex to protect register accesses.
  732. * For PCI and USB devices it protects against concurrent indirect
  733. * register access (BBP, RF, MCU) since accessing those
  734. * registers require multiple calls to the CSR registers.
  735. * For USB devices it also protects the csr_cache since that
  736. * field is used for normal CSR access and it cannot support
  737. * multiple callers simultaneously.
  738. */
  739. struct mutex csr_mutex;
  740. /*
  741. * Mutex to synchronize config and link tuner.
  742. */
  743. struct mutex conf_mutex;
  744. /*
  745. * Current packet filter configuration for the device.
  746. * This contains all currently active FIF_* flags send
  747. * to us by mac80211 during configure_filter().
  748. */
  749. unsigned int packet_filter;
  750. /*
  751. * Interface details:
  752. * - Open ap interface count.
  753. * - Open sta interface count.
  754. * - Association count.
  755. * - Beaconing enabled count.
  756. */
  757. unsigned int intf_ap_count;
  758. unsigned int intf_sta_count;
  759. unsigned int intf_associated;
  760. unsigned int intf_beaconing;
  761. /*
  762. * Interface combinations
  763. */
  764. struct ieee80211_iface_limit if_limits_ap;
  765. struct ieee80211_iface_combination if_combinations[NUM_IF_COMB];
  766. /*
  767. * Link quality
  768. */
  769. struct link link;
  770. /*
  771. * EEPROM data.
  772. */
  773. __le16 *eeprom;
  774. /*
  775. * Active RF register values.
  776. * These are stored here so we don't need
  777. * to read the rf registers and can directly
  778. * use this value instead.
  779. * This field should be accessed by using
  780. * rt2x00_rf_read() and rt2x00_rf_write().
  781. */
  782. u32 *rf;
  783. /*
  784. * LNA gain
  785. */
  786. short lna_gain;
  787. /*
  788. * Current TX power value.
  789. */
  790. u16 tx_power;
  791. /*
  792. * Current retry values.
  793. */
  794. u8 short_retry;
  795. u8 long_retry;
  796. /*
  797. * Rssi <-> Dbm offset
  798. */
  799. u8 rssi_offset;
  800. /*
  801. * Frequency offset.
  802. */
  803. u8 freq_offset;
  804. /*
  805. * Association id.
  806. */
  807. u16 aid;
  808. /*
  809. * Beacon interval.
  810. */
  811. u16 beacon_int;
  812. /**
  813. * Timestamp of last received beacon
  814. */
  815. unsigned long last_beacon;
  816. /*
  817. * Low level statistics which will have
  818. * to be kept up to date while device is running.
  819. */
  820. struct ieee80211_low_level_stats low_level_stats;
  821. /**
  822. * Work queue for all work which should not be placed
  823. * on the mac80211 workqueue (because of dependencies
  824. * between various work structures).
  825. */
  826. struct workqueue_struct *workqueue;
  827. /*
  828. * Scheduled work.
  829. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  830. * which means it cannot be placed on the hw->workqueue
  831. * due to RTNL locking requirements.
  832. */
  833. struct work_struct intf_work;
  834. /**
  835. * Scheduled work for TX/RX done handling (USB devices)
  836. */
  837. struct work_struct rxdone_work;
  838. struct work_struct txdone_work;
  839. /*
  840. * Powersaving work
  841. */
  842. struct delayed_work autowakeup_work;
  843. struct work_struct sleep_work;
  844. /*
  845. * Data queue arrays for RX, TX, Beacon and ATIM.
  846. */
  847. unsigned int data_queues;
  848. struct data_queue *rx;
  849. struct data_queue *tx;
  850. struct data_queue *bcn;
  851. struct data_queue *atim;
  852. /*
  853. * Firmware image.
  854. */
  855. const struct firmware *fw;
  856. /*
  857. * FIFO for storing tx status reports between isr and tasklet.
  858. */
  859. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  860. /*
  861. * Timer to ensure tx status reports are read (rt2800usb).
  862. */
  863. struct hrtimer txstatus_timer;
  864. /*
  865. * Tasklet for processing tx status reports (rt2800pci).
  866. */
  867. struct tasklet_struct txstatus_tasklet;
  868. struct tasklet_struct pretbtt_tasklet;
  869. struct tasklet_struct tbtt_tasklet;
  870. struct tasklet_struct rxdone_tasklet;
  871. struct tasklet_struct autowake_tasklet;
  872. /*
  873. * Used for VCO periodic calibration.
  874. */
  875. int rf_channel;
  876. /*
  877. * Protect the interrupt mask register.
  878. */
  879. spinlock_t irqmask_lock;
  880. /*
  881. * List of BlockAckReq TX entries that need driver BlockAck processing.
  882. */
  883. struct list_head bar_list;
  884. spinlock_t bar_list_lock;
  885. /* Extra TX headroom required for alignment purposes. */
  886. unsigned int extra_tx_headroom;
  887. struct usb_anchor *anchor;
  888. /* Clock for System On Chip devices. */
  889. struct clk *clk;
  890. };
  891. struct rt2x00_bar_list_entry {
  892. struct list_head list;
  893. struct rcu_head head;
  894. struct queue_entry *entry;
  895. int block_acked;
  896. /* Relevant parts of the IEEE80211 BAR header */
  897. __u8 ra[6];
  898. __u8 ta[6];
  899. __le16 control;
  900. __le16 start_seq_num;
  901. };
  902. /*
  903. * Register defines.
  904. * Some registers require multiple attempts before success,
  905. * in those cases REGISTER_BUSY_COUNT attempts should be
  906. * taken with a REGISTER_BUSY_DELAY interval. Due to USB
  907. * bus delays, we do not have to loop so many times to wait
  908. * for valid register value on that bus.
  909. */
  910. #define REGISTER_BUSY_COUNT 100
  911. #define REGISTER_USB_BUSY_COUNT 20
  912. #define REGISTER_BUSY_DELAY 100
  913. /*
  914. * Generic RF access.
  915. * The RF is being accessed by word index.
  916. */
  917. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  918. const unsigned int word, u32 *data)
  919. {
  920. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  921. *data = rt2x00dev->rf[word - 1];
  922. }
  923. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  924. const unsigned int word, u32 data)
  925. {
  926. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  927. rt2x00dev->rf[word - 1] = data;
  928. }
  929. /*
  930. * Generic EEPROM access. The EEPROM is being accessed by word or byte index.
  931. */
  932. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  933. const unsigned int word)
  934. {
  935. return (void *)&rt2x00dev->eeprom[word];
  936. }
  937. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  938. const unsigned int word, u16 *data)
  939. {
  940. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  941. }
  942. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  943. const unsigned int word, u16 data)
  944. {
  945. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  946. }
  947. static inline u8 rt2x00_eeprom_byte(struct rt2x00_dev *rt2x00dev,
  948. const unsigned int byte)
  949. {
  950. return *(((u8 *)rt2x00dev->eeprom) + byte);
  951. }
  952. /*
  953. * Chipset handlers
  954. */
  955. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  956. const u16 rt, const u16 rf, const u16 rev)
  957. {
  958. rt2x00dev->chip.rt = rt;
  959. rt2x00dev->chip.rf = rf;
  960. rt2x00dev->chip.rev = rev;
  961. rt2x00_info(rt2x00dev, "Chipset detected - rt: %04x, rf: %04x, rev: %04x\n",
  962. rt2x00dev->chip.rt, rt2x00dev->chip.rf,
  963. rt2x00dev->chip.rev);
  964. }
  965. static inline void rt2x00_set_rt(struct rt2x00_dev *rt2x00dev,
  966. const u16 rt, const u16 rev)
  967. {
  968. rt2x00dev->chip.rt = rt;
  969. rt2x00dev->chip.rev = rev;
  970. rt2x00_info(rt2x00dev, "RT chipset %04x, rev %04x detected\n",
  971. rt2x00dev->chip.rt, rt2x00dev->chip.rev);
  972. }
  973. static inline void rt2x00_set_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  974. {
  975. rt2x00dev->chip.rf = rf;
  976. rt2x00_info(rt2x00dev, "RF chipset %04x detected\n",
  977. rt2x00dev->chip.rf);
  978. }
  979. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  980. {
  981. return (rt2x00dev->chip.rt == rt);
  982. }
  983. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  984. {
  985. return (rt2x00dev->chip.rf == rf);
  986. }
  987. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  988. {
  989. return rt2x00dev->chip.rev;
  990. }
  991. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  992. const u16 rt, const u16 rev)
  993. {
  994. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  995. }
  996. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  997. const u16 rt, const u16 rev)
  998. {
  999. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  1000. }
  1001. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  1002. const u16 rt, const u16 rev)
  1003. {
  1004. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  1005. }
  1006. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  1007. enum rt2x00_chip_intf intf)
  1008. {
  1009. rt2x00dev->chip.intf = intf;
  1010. }
  1011. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  1012. enum rt2x00_chip_intf intf)
  1013. {
  1014. return (rt2x00dev->chip.intf == intf);
  1015. }
  1016. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  1017. {
  1018. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  1019. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  1020. }
  1021. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  1022. {
  1023. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  1024. }
  1025. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  1026. {
  1027. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  1028. }
  1029. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  1030. {
  1031. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  1032. }
  1033. /* Helpers for capability flags */
  1034. static inline bool
  1035. rt2x00_has_cap_flag(struct rt2x00_dev *rt2x00dev,
  1036. enum rt2x00_capability_flags cap_flag)
  1037. {
  1038. return test_bit(cap_flag, &rt2x00dev->cap_flags);
  1039. }
  1040. static inline bool
  1041. rt2x00_has_cap_hw_crypto(struct rt2x00_dev *rt2x00dev)
  1042. {
  1043. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_HW_CRYPTO);
  1044. }
  1045. static inline bool
  1046. rt2x00_has_cap_power_limit(struct rt2x00_dev *rt2x00dev)
  1047. {
  1048. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_POWER_LIMIT);
  1049. }
  1050. static inline bool
  1051. rt2x00_has_cap_control_filters(struct rt2x00_dev *rt2x00dev)
  1052. {
  1053. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTERS);
  1054. }
  1055. static inline bool
  1056. rt2x00_has_cap_control_filter_pspoll(struct rt2x00_dev *rt2x00dev)
  1057. {
  1058. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_CONTROL_FILTER_PSPOLL);
  1059. }
  1060. static inline bool
  1061. rt2x00_has_cap_pre_tbtt_interrupt(struct rt2x00_dev *rt2x00dev)
  1062. {
  1063. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_PRE_TBTT_INTERRUPT);
  1064. }
  1065. static inline bool
  1066. rt2x00_has_cap_link_tuning(struct rt2x00_dev *rt2x00dev)
  1067. {
  1068. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_LINK_TUNING);
  1069. }
  1070. static inline bool
  1071. rt2x00_has_cap_frame_type(struct rt2x00_dev *rt2x00dev)
  1072. {
  1073. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_FRAME_TYPE);
  1074. }
  1075. static inline bool
  1076. rt2x00_has_cap_rf_sequence(struct rt2x00_dev *rt2x00dev)
  1077. {
  1078. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_RF_SEQUENCE);
  1079. }
  1080. static inline bool
  1081. rt2x00_has_cap_external_lna_a(struct rt2x00_dev *rt2x00dev)
  1082. {
  1083. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_A);
  1084. }
  1085. static inline bool
  1086. rt2x00_has_cap_external_lna_bg(struct rt2x00_dev *rt2x00dev)
  1087. {
  1088. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_EXTERNAL_LNA_BG);
  1089. }
  1090. static inline bool
  1091. rt2x00_has_cap_double_antenna(struct rt2x00_dev *rt2x00dev)
  1092. {
  1093. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_DOUBLE_ANTENNA);
  1094. }
  1095. static inline bool
  1096. rt2x00_has_cap_bt_coexist(struct rt2x00_dev *rt2x00dev)
  1097. {
  1098. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_BT_COEXIST);
  1099. }
  1100. static inline bool
  1101. rt2x00_has_cap_vco_recalibration(struct rt2x00_dev *rt2x00dev)
  1102. {
  1103. return rt2x00_has_cap_flag(rt2x00dev, CAPABILITY_VCO_RECALIBRATION);
  1104. }
  1105. /**
  1106. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  1107. * @entry: Pointer to &struct queue_entry
  1108. *
  1109. * Returns -ENOMEM if mapping fail, 0 otherwise.
  1110. */
  1111. int rt2x00queue_map_txskb(struct queue_entry *entry);
  1112. /**
  1113. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  1114. * @entry: Pointer to &struct queue_entry
  1115. */
  1116. void rt2x00queue_unmap_skb(struct queue_entry *entry);
  1117. /**
  1118. * rt2x00queue_get_tx_queue - Convert tx queue index to queue pointer
  1119. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1120. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  1121. *
  1122. * Returns NULL for non tx queues.
  1123. */
  1124. static inline struct data_queue *
  1125. rt2x00queue_get_tx_queue(struct rt2x00_dev *rt2x00dev,
  1126. const enum data_queue_qid queue)
  1127. {
  1128. if (queue < rt2x00dev->ops->tx_queues && rt2x00dev->tx)
  1129. return &rt2x00dev->tx[queue];
  1130. if (queue == QID_ATIM)
  1131. return rt2x00dev->atim;
  1132. return NULL;
  1133. }
  1134. /**
  1135. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  1136. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  1137. * @index: Index identifier for obtaining the correct index.
  1138. */
  1139. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  1140. enum queue_index index);
  1141. /**
  1142. * rt2x00queue_pause_queue - Pause a data queue
  1143. * @queue: Pointer to &struct data_queue.
  1144. *
  1145. * This function will pause the data queue locally, preventing
  1146. * new frames to be added to the queue (while the hardware is
  1147. * still allowed to run).
  1148. */
  1149. void rt2x00queue_pause_queue(struct data_queue *queue);
  1150. /**
  1151. * rt2x00queue_unpause_queue - unpause a data queue
  1152. * @queue: Pointer to &struct data_queue.
  1153. *
  1154. * This function will unpause the data queue locally, allowing
  1155. * new frames to be added to the queue again.
  1156. */
  1157. void rt2x00queue_unpause_queue(struct data_queue *queue);
  1158. /**
  1159. * rt2x00queue_start_queue - Start a data queue
  1160. * @queue: Pointer to &struct data_queue.
  1161. *
  1162. * This function will start handling all pending frames in the queue.
  1163. */
  1164. void rt2x00queue_start_queue(struct data_queue *queue);
  1165. /**
  1166. * rt2x00queue_stop_queue - Halt a data queue
  1167. * @queue: Pointer to &struct data_queue.
  1168. *
  1169. * This function will stop all pending frames in the queue.
  1170. */
  1171. void rt2x00queue_stop_queue(struct data_queue *queue);
  1172. /**
  1173. * rt2x00queue_flush_queue - Flush a data queue
  1174. * @queue: Pointer to &struct data_queue.
  1175. * @drop: True to drop all pending frames.
  1176. *
  1177. * This function will flush the queue. After this call
  1178. * the queue is guaranteed to be empty.
  1179. */
  1180. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
  1181. /**
  1182. * rt2x00queue_start_queues - Start all data queues
  1183. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1184. *
  1185. * This function will loop through all available queues to start them
  1186. */
  1187. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
  1188. /**
  1189. * rt2x00queue_stop_queues - Halt all data queues
  1190. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1191. *
  1192. * This function will loop through all available queues to stop
  1193. * any pending frames.
  1194. */
  1195. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  1196. /**
  1197. * rt2x00queue_flush_queues - Flush all data queues
  1198. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1199. * @drop: True to drop all pending frames.
  1200. *
  1201. * This function will loop through all available queues to flush
  1202. * any pending frames.
  1203. */
  1204. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
  1205. /*
  1206. * Debugfs handlers.
  1207. */
  1208. /**
  1209. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  1210. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1211. * @type: The type of frame that is being dumped.
  1212. * @entry: The queue entry containing the frame to be dumped.
  1213. */
  1214. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1215. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1216. enum rt2x00_dump_type type, struct queue_entry *entry);
  1217. #else
  1218. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1219. enum rt2x00_dump_type type,
  1220. struct queue_entry *entry)
  1221. {
  1222. }
  1223. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1224. /*
  1225. * Utility functions.
  1226. */
  1227. u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,
  1228. struct ieee80211_vif *vif);
  1229. void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr);
  1230. /*
  1231. * Interrupt context handlers.
  1232. */
  1233. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  1234. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  1235. void rt2x00lib_dmastart(struct queue_entry *entry);
  1236. void rt2x00lib_dmadone(struct queue_entry *entry);
  1237. void rt2x00lib_txdone(struct queue_entry *entry,
  1238. struct txdone_entry_desc *txdesc);
  1239. void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
  1240. struct txdone_entry_desc *txdesc);
  1241. void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
  1242. void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp);
  1243. /*
  1244. * mac80211 handlers.
  1245. */
  1246. void rt2x00mac_tx(struct ieee80211_hw *hw,
  1247. struct ieee80211_tx_control *control,
  1248. struct sk_buff *skb);
  1249. int rt2x00mac_start(struct ieee80211_hw *hw);
  1250. void rt2x00mac_stop(struct ieee80211_hw *hw);
  1251. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  1252. struct ieee80211_vif *vif);
  1253. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  1254. struct ieee80211_vif *vif);
  1255. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  1256. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  1257. unsigned int changed_flags,
  1258. unsigned int *total_flags,
  1259. u64 multicast);
  1260. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  1261. bool set);
  1262. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  1263. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1264. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1265. struct ieee80211_key_conf *key);
  1266. #else
  1267. #define rt2x00mac_set_key NULL
  1268. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  1269. int rt2x00mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1270. struct ieee80211_sta *sta);
  1271. int rt2x00mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1272. struct ieee80211_sta *sta);
  1273. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw,
  1274. struct ieee80211_vif *vif,
  1275. const u8 *mac_addr);
  1276. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw,
  1277. struct ieee80211_vif *vif);
  1278. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  1279. struct ieee80211_low_level_stats *stats);
  1280. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  1281. struct ieee80211_vif *vif,
  1282. struct ieee80211_bss_conf *bss_conf,
  1283. u32 changes);
  1284. int rt2x00mac_conf_tx(struct ieee80211_hw *hw,
  1285. struct ieee80211_vif *vif, u16 queue,
  1286. const struct ieee80211_tx_queue_params *params);
  1287. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  1288. void rt2x00mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1289. u32 queues, bool drop);
  1290. int rt2x00mac_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
  1291. int rt2x00mac_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
  1292. void rt2x00mac_get_ringparam(struct ieee80211_hw *hw,
  1293. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max);
  1294. bool rt2x00mac_tx_frames_pending(struct ieee80211_hw *hw);
  1295. /*
  1296. * Driver allocation handlers.
  1297. */
  1298. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  1299. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  1300. #ifdef CONFIG_PM
  1301. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  1302. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  1303. #endif /* CONFIG_PM */
  1304. #endif /* RT2X00_H */