rt2x00.h 37 KB

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