rt2x00.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00
  19. Abstract: rt2x00 global information.
  20. */
  21. #ifndef RT2X00_H
  22. #define RT2X00_H
  23. #include <linux/bitops.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/firmware.h>
  27. #include <linux/leds.h>
  28. #include <linux/mutex.h>
  29. #include <linux/etherdevice.h>
  30. #include <net/mac80211.h>
  31. #include "rt2x00debug.h"
  32. #include "rt2x00leds.h"
  33. #include "rt2x00reg.h"
  34. #include "rt2x00queue.h"
  35. /*
  36. * Module information.
  37. */
  38. #define DRV_VERSION "2.1.8"
  39. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  40. /*
  41. * Debug definitions.
  42. * Debug output has to be enabled during compile time.
  43. */
  44. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  45. printk(__kernlvl "%s -> %s: %s - " __msg, \
  46. wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
  47. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  48. printk(__kernlvl "%s -> %s: %s - " __msg, \
  49. KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args)
  50. #ifdef CONFIG_RT2X00_DEBUG
  51. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  52. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
  53. #else
  54. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  55. do { } while (0)
  56. #endif /* CONFIG_RT2X00_DEBUG */
  57. /*
  58. * Various debug levels.
  59. * The debug levels PANIC and ERROR both indicate serious problems,
  60. * for this reason they should never be ignored.
  61. * The special ERROR_PROBE message is for messages that are generated
  62. * when the rt2x00_dev is not yet initialized.
  63. */
  64. #define PANIC(__dev, __msg, __args...) \
  65. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  66. #define ERROR(__dev, __msg, __args...) \
  67. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  68. #define ERROR_PROBE(__msg, __args...) \
  69. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  70. #define WARNING(__dev, __msg, __args...) \
  71. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  72. #define NOTICE(__dev, __msg, __args...) \
  73. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  74. #define INFO(__dev, __msg, __args...) \
  75. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  76. #define DEBUG(__dev, __msg, __args...) \
  77. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  78. #define EEPROM(__dev, __msg, __args...) \
  79. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  80. /*
  81. * Standard timing and size defines.
  82. * These values should follow the ieee80211 specifications.
  83. */
  84. #define ACK_SIZE 14
  85. #define IEEE80211_HEADER 24
  86. #define PLCP 48
  87. #define BEACON 100
  88. #define PREAMBLE 144
  89. #define SHORT_PREAMBLE 72
  90. #define SLOT_TIME 20
  91. #define SHORT_SLOT_TIME 9
  92. #define SIFS 10
  93. #define PIFS ( SIFS + SLOT_TIME )
  94. #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
  95. #define DIFS ( PIFS + SLOT_TIME )
  96. #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
  97. #define EIFS ( SIFS + DIFS + \
  98. (8 * (IEEE80211_HEADER + ACK_SIZE)) )
  99. #define SHORT_EIFS ( SIFS + SHORT_DIFS + \
  100. (8 * (IEEE80211_HEADER + ACK_SIZE)) )
  101. /*
  102. * Chipset identification
  103. * The chipset on the device is composed of a RT and RF chip.
  104. * The chipset combination is important for determining device capabilities.
  105. */
  106. struct rt2x00_chip {
  107. u16 rt;
  108. #define RT2460 0x0101
  109. #define RT2560 0x0201
  110. #define RT2570 0x1201
  111. #define RT2561s 0x0301 /* Turbo */
  112. #define RT2561 0x0302
  113. #define RT2661 0x0401
  114. #define RT2571 0x1300
  115. u16 rf;
  116. u32 rev;
  117. };
  118. /*
  119. * RF register values that belong to a particular channel.
  120. */
  121. struct rf_channel {
  122. int channel;
  123. u32 rf1;
  124. u32 rf2;
  125. u32 rf3;
  126. u32 rf4;
  127. };
  128. /*
  129. * Antenna setup values.
  130. */
  131. struct antenna_setup {
  132. enum antenna rx;
  133. enum antenna tx;
  134. };
  135. /*
  136. * Quality statistics about the currently active link.
  137. */
  138. struct link_qual {
  139. /*
  140. * Statistics required for Link tuning.
  141. * For the average RSSI value we use the "Walking average" approach.
  142. * When adding RSSI to the average value the following calculation
  143. * is needed:
  144. *
  145. * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
  146. *
  147. * The advantage of this approach is that we only need 1 variable
  148. * to store the average in (No need for a count and a total).
  149. * But more importantly, normal average values will over time
  150. * move less and less towards newly added values this results
  151. * that with link tuning, the device can have a very good RSSI
  152. * for a few minutes but when the device is moved away from the AP
  153. * the average will not decrease fast enough to compensate.
  154. * The walking average compensates this and will move towards
  155. * the new values correctly allowing a effective link tuning.
  156. */
  157. int avg_rssi;
  158. int false_cca;
  159. /*
  160. * Statistics required for Signal quality calculation.
  161. * For calculating the Signal quality we have to determine
  162. * the total number of success and failed RX and TX frames.
  163. * After that we also use the average RSSI value to help
  164. * determining the signal quality.
  165. * For the calculation we will use the following algorithm:
  166. *
  167. * rssi_percentage = (avg_rssi * 100) / rssi_offset
  168. * rx_percentage = (rx_success * 100) / rx_total
  169. * tx_percentage = (tx_success * 100) / tx_total
  170. * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
  171. * (WEIGHT_TX * tx_percentage) +
  172. * (WEIGHT_RX * rx_percentage)) / 100
  173. *
  174. * This value should then be checked to not be greated then 100.
  175. */
  176. int rx_percentage;
  177. int rx_success;
  178. int rx_failed;
  179. int tx_percentage;
  180. int tx_success;
  181. int tx_failed;
  182. #define WEIGHT_RSSI 20
  183. #define WEIGHT_RX 40
  184. #define WEIGHT_TX 40
  185. };
  186. /*
  187. * Antenna settings about the currently active link.
  188. */
  189. struct link_ant {
  190. /*
  191. * Antenna flags
  192. */
  193. unsigned int flags;
  194. #define ANTENNA_RX_DIVERSITY 0x00000001
  195. #define ANTENNA_TX_DIVERSITY 0x00000002
  196. #define ANTENNA_MODE_SAMPLE 0x00000004
  197. /*
  198. * Currently active TX/RX antenna setup.
  199. * When software diversity is used, this will indicate
  200. * which antenna is actually used at this time.
  201. */
  202. struct antenna_setup active;
  203. /*
  204. * RSSI information for the different antenna's.
  205. * These statistics are used to determine when
  206. * to switch antenna when using software diversity.
  207. *
  208. * rssi[0] -> Antenna A RSSI
  209. * rssi[1] -> Antenna B RSSI
  210. */
  211. int rssi_history[2];
  212. /*
  213. * Current RSSI average of the currently active antenna.
  214. * Similar to the avg_rssi in the link_qual structure
  215. * this value is updated by using the walking average.
  216. */
  217. int rssi_ant;
  218. };
  219. /*
  220. * To optimize the quality of the link we need to store
  221. * the quality of received frames and periodically
  222. * optimize the link.
  223. */
  224. struct link {
  225. /*
  226. * Link tuner counter
  227. * The number of times the link has been tuned
  228. * since the radio has been switched on.
  229. */
  230. u32 count;
  231. /*
  232. * Quality measurement values.
  233. */
  234. struct link_qual qual;
  235. /*
  236. * TX/RX antenna setup.
  237. */
  238. struct link_ant ant;
  239. /*
  240. * Active VGC level
  241. */
  242. int vgc_level;
  243. /*
  244. * Work structure for scheduling periodic link tuning.
  245. */
  246. struct delayed_work work;
  247. };
  248. /*
  249. * Small helper macro to work with moving/walking averages.
  250. */
  251. #define MOVING_AVERAGE(__avg, __val, __samples) \
  252. ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
  253. /*
  254. * When we lack RSSI information return something less then -80 to
  255. * tell the driver to tune the device to maximum sensitivity.
  256. */
  257. #define DEFAULT_RSSI ( -128 )
  258. /*
  259. * Link quality access functions.
  260. */
  261. static inline int rt2x00_get_link_rssi(struct link *link)
  262. {
  263. if (link->qual.avg_rssi && link->qual.rx_success)
  264. return link->qual.avg_rssi;
  265. return DEFAULT_RSSI;
  266. }
  267. static inline int rt2x00_get_link_ant_rssi(struct link *link)
  268. {
  269. if (link->ant.rssi_ant && link->qual.rx_success)
  270. return link->ant.rssi_ant;
  271. return DEFAULT_RSSI;
  272. }
  273. static inline void rt2x00_reset_link_ant_rssi(struct link *link)
  274. {
  275. link->ant.rssi_ant = 0;
  276. }
  277. static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
  278. enum antenna ant)
  279. {
  280. if (link->ant.rssi_history[ant - ANTENNA_A])
  281. return link->ant.rssi_history[ant - ANTENNA_A];
  282. return DEFAULT_RSSI;
  283. }
  284. static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
  285. {
  286. int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
  287. link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
  288. return old_rssi;
  289. }
  290. /*
  291. * Interface structure
  292. * Per interface configuration details, this structure
  293. * is allocated as the private data for ieee80211_vif.
  294. */
  295. struct rt2x00_intf {
  296. /*
  297. * All fields within the rt2x00_intf structure
  298. * must be protected with a spinlock.
  299. */
  300. spinlock_t lock;
  301. /*
  302. * BSS configuration. Copied from the structure
  303. * passed to us through the bss_info_changed()
  304. * callback funtion.
  305. */
  306. struct ieee80211_bss_conf conf;
  307. /*
  308. * MAC of the device.
  309. */
  310. u8 mac[ETH_ALEN];
  311. /*
  312. * BBSID of the AP to associate with.
  313. */
  314. u8 bssid[ETH_ALEN];
  315. /*
  316. * Entry in the beacon queue which belongs to
  317. * this interface. Each interface has its own
  318. * dedicated beacon entry.
  319. */
  320. struct queue_entry *beacon;
  321. /*
  322. * Actions that needed rescheduling.
  323. */
  324. unsigned int delayed_flags;
  325. #define DELAYED_UPDATE_BEACON 0x00000001
  326. #define DELAYED_CONFIG_ERP 0x00000002
  327. #define DELAYED_LED_ASSOC 0x00000004
  328. /*
  329. * Software sequence counter, this is only required
  330. * for hardware which doesn't support hardware
  331. * sequence counting.
  332. */
  333. spinlock_t seqlock;
  334. u16 seqno;
  335. };
  336. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  337. {
  338. return (struct rt2x00_intf *)vif->drv_priv;
  339. }
  340. /**
  341. * struct hw_mode_spec: Hardware specifications structure
  342. *
  343. * Details about the supported modes, rates and channels
  344. * of a particular chipset. This is used by rt2x00lib
  345. * to build the ieee80211_hw_mode array for mac80211.
  346. *
  347. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  348. * @supported_rates: Rate types which are supported (CCK, OFDM).
  349. * @num_channels: Number of supported channels. This is used as array size
  350. * for @tx_power_a, @tx_power_bg and @channels.
  351. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  352. * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
  353. * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
  354. * @tx_power_default: Default TX power value to use when either
  355. * @tx_power_a or @tx_power_bg is missing.
  356. */
  357. struct hw_mode_spec {
  358. unsigned int supported_bands;
  359. #define SUPPORT_BAND_2GHZ 0x00000001
  360. #define SUPPORT_BAND_5GHZ 0x00000002
  361. unsigned int supported_rates;
  362. #define SUPPORT_RATE_CCK 0x00000001
  363. #define SUPPORT_RATE_OFDM 0x00000002
  364. unsigned int num_channels;
  365. const struct rf_channel *channels;
  366. const u8 *tx_power_a;
  367. const u8 *tx_power_bg;
  368. u8 tx_power_default;
  369. };
  370. /*
  371. * Configuration structure wrapper around the
  372. * mac80211 configuration structure.
  373. * When mac80211 configures the driver, rt2x00lib
  374. * can precalculate values which are equal for all
  375. * rt2x00 drivers. Those values can be stored in here.
  376. */
  377. struct rt2x00lib_conf {
  378. struct ieee80211_conf *conf;
  379. struct rf_channel rf;
  380. struct antenna_setup ant;
  381. enum ieee80211_band band;
  382. u32 basic_rates;
  383. u32 slot_time;
  384. short sifs;
  385. short pifs;
  386. short difs;
  387. short eifs;
  388. };
  389. /*
  390. * Configuration structure for erp settings.
  391. */
  392. struct rt2x00lib_erp {
  393. int short_preamble;
  394. int cts_protection;
  395. int ack_timeout;
  396. int ack_consume_time;
  397. };
  398. /*
  399. * Configuration structure wrapper around the
  400. * rt2x00 interface configuration handler.
  401. */
  402. struct rt2x00intf_conf {
  403. /*
  404. * Interface type
  405. */
  406. enum ieee80211_if_types type;
  407. /*
  408. * TSF sync value, this is dependant on the operation type.
  409. */
  410. enum tsf_sync sync;
  411. /*
  412. * The MAC and BSSID addressess are simple array of bytes,
  413. * these arrays are little endian, so when sending the addressess
  414. * to the drivers, copy the it into a endian-signed variable.
  415. *
  416. * Note that all devices (except rt2500usb) have 32 bits
  417. * register word sizes. This means that whatever variable we
  418. * pass _must_ be a multiple of 32 bits. Otherwise the device
  419. * might not accept what we are sending to it.
  420. * This will also make it easier for the driver to write
  421. * the data to the device.
  422. */
  423. __le32 mac[2];
  424. __le32 bssid[2];
  425. };
  426. /*
  427. * rt2x00lib callback functions.
  428. */
  429. struct rt2x00lib_ops {
  430. /*
  431. * Interrupt handlers.
  432. */
  433. irq_handler_t irq_handler;
  434. /*
  435. * Device init handlers.
  436. */
  437. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  438. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  439. u16 (*get_firmware_crc) (const void *data, const size_t len);
  440. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const void *data,
  441. const size_t len);
  442. /*
  443. * Device initialization/deinitialization handlers.
  444. */
  445. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  446. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  447. /*
  448. * queue initialization handlers
  449. */
  450. void (*init_rxentry) (struct rt2x00_dev *rt2x00dev,
  451. struct queue_entry *entry);
  452. void (*init_txentry) (struct rt2x00_dev *rt2x00dev,
  453. struct queue_entry *entry);
  454. /*
  455. * Radio control handlers.
  456. */
  457. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  458. enum dev_state state);
  459. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  460. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  461. struct link_qual *qual);
  462. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
  463. void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
  464. /*
  465. * TX control handlers
  466. */
  467. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  468. struct sk_buff *skb,
  469. struct txentry_desc *txdesc);
  470. int (*write_tx_data) (struct queue_entry *entry);
  471. void (*write_beacon) (struct queue_entry *entry);
  472. int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
  473. struct sk_buff *skb);
  474. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  475. const enum data_queue_qid queue);
  476. /*
  477. * RX control handlers
  478. */
  479. void (*fill_rxdone) (struct queue_entry *entry,
  480. struct rxdone_entry_desc *rxdesc);
  481. /*
  482. * Configuration handlers.
  483. */
  484. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  485. const unsigned int filter_flags);
  486. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  487. struct rt2x00_intf *intf,
  488. struct rt2x00intf_conf *conf,
  489. const unsigned int flags);
  490. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  491. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  492. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  493. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  494. struct rt2x00lib_erp *erp);
  495. void (*config) (struct rt2x00_dev *rt2x00dev,
  496. struct rt2x00lib_conf *libconf,
  497. const unsigned int flags);
  498. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  499. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  500. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  501. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  502. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  503. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  504. #define CONFIG_UPDATE_ALL 0xffff
  505. };
  506. /*
  507. * rt2x00 driver callback operation structure.
  508. */
  509. struct rt2x00_ops {
  510. const char *name;
  511. const unsigned int max_sta_intf;
  512. const unsigned int max_ap_intf;
  513. const unsigned int eeprom_size;
  514. const unsigned int rf_size;
  515. const unsigned int tx_queues;
  516. const struct data_queue_desc *rx;
  517. const struct data_queue_desc *tx;
  518. const struct data_queue_desc *bcn;
  519. const struct data_queue_desc *atim;
  520. const struct rt2x00lib_ops *lib;
  521. const struct ieee80211_ops *hw;
  522. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  523. const struct rt2x00debug *debugfs;
  524. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  525. };
  526. /*
  527. * rt2x00 device flags
  528. */
  529. enum rt2x00_flags {
  530. /*
  531. * Device state flags
  532. */
  533. DEVICE_PRESENT,
  534. DEVICE_REGISTERED_HW,
  535. DEVICE_INITIALIZED,
  536. DEVICE_STARTED,
  537. DEVICE_STARTED_SUSPEND,
  538. DEVICE_ENABLED_RADIO,
  539. DEVICE_DISABLED_RADIO_HW,
  540. DEVICE_DIRTY_CONFIG,
  541. /*
  542. * Driver features
  543. */
  544. DRIVER_REQUIRE_FIRMWARE,
  545. DRIVER_REQUIRE_BEACON_GUARD,
  546. DRIVER_REQUIRE_ATIM_QUEUE,
  547. DRIVER_REQUIRE_SCHEDULED,
  548. DRIVER_REQUIRE_DMA,
  549. /*
  550. * Driver configuration
  551. */
  552. CONFIG_SUPPORT_HW_BUTTON,
  553. CONFIG_FRAME_TYPE,
  554. CONFIG_RF_SEQUENCE,
  555. CONFIG_EXTERNAL_LNA_A,
  556. CONFIG_EXTERNAL_LNA_BG,
  557. CONFIG_DOUBLE_ANTENNA,
  558. CONFIG_DISABLE_LINK_TUNING,
  559. };
  560. /*
  561. * rt2x00 device structure.
  562. */
  563. struct rt2x00_dev {
  564. /*
  565. * Device structure.
  566. * The structure stored in here depends on the
  567. * system bus (PCI or USB).
  568. * When accessing this variable, the rt2x00dev_{pci,usb}
  569. * macro's should be used for correct typecasting.
  570. */
  571. struct device *dev;
  572. /*
  573. * Callback functions.
  574. */
  575. const struct rt2x00_ops *ops;
  576. /*
  577. * IEEE80211 control structure.
  578. */
  579. struct ieee80211_hw *hw;
  580. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  581. enum ieee80211_band curr_band;
  582. /*
  583. * rfkill structure for RF state switching support.
  584. * This will only be compiled in when required.
  585. */
  586. #ifdef CONFIG_RT2X00_LIB_RFKILL
  587. unsigned long rfkill_state;
  588. #define RFKILL_STATE_ALLOCATED 1
  589. #define RFKILL_STATE_REGISTERED 2
  590. struct rfkill *rfkill;
  591. struct delayed_work rfkill_work;
  592. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  593. /*
  594. * If enabled, the debugfs interface structures
  595. * required for deregistration of debugfs.
  596. */
  597. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  598. struct rt2x00debug_intf *debugfs_intf;
  599. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  600. /*
  601. * LED structure for changing the LED status
  602. * by mac8011 or the kernel.
  603. */
  604. #ifdef CONFIG_RT2X00_LIB_LEDS
  605. struct rt2x00_led led_radio;
  606. struct rt2x00_led led_assoc;
  607. struct rt2x00_led led_qual;
  608. u16 led_mcu_reg;
  609. #endif /* CONFIG_RT2X00_LIB_LEDS */
  610. /*
  611. * Device flags.
  612. * In these flags the current status and some
  613. * of the device capabilities are stored.
  614. */
  615. unsigned long flags;
  616. /*
  617. * Chipset identification.
  618. */
  619. struct rt2x00_chip chip;
  620. /*
  621. * hw capability specifications.
  622. */
  623. struct hw_mode_spec spec;
  624. /*
  625. * This is the default TX/RX antenna setup as indicated
  626. * by the device's EEPROM. When mac80211 sets its
  627. * antenna value to 0 we should be using these values.
  628. */
  629. struct antenna_setup default_ant;
  630. /*
  631. * Register pointers
  632. * csr.base: CSR base register address. (PCI)
  633. * csr.cache: CSR cache for usb_control_msg. (USB)
  634. */
  635. union csr {
  636. void __iomem *base;
  637. void *cache;
  638. } csr;
  639. /*
  640. * Mutex to protect register accesses on USB devices.
  641. * There are 2 reasons this is needed, one is to ensure
  642. * use of the csr_cache (for USB devices) by one thread
  643. * isn't corrupted by another thread trying to access it.
  644. * The other is that access to BBP and RF registers
  645. * require multiple BUS transactions and if another thread
  646. * attempted to access one of those registers at the same
  647. * time one of the writes could silently fail.
  648. */
  649. struct mutex usb_cache_mutex;
  650. /*
  651. * Current packet filter configuration for the device.
  652. * This contains all currently active FIF_* flags send
  653. * to us by mac80211 during configure_filter().
  654. */
  655. unsigned int packet_filter;
  656. /*
  657. * Interface details:
  658. * - Open ap interface count.
  659. * - Open sta interface count.
  660. * - Association count.
  661. */
  662. unsigned int intf_ap_count;
  663. unsigned int intf_sta_count;
  664. unsigned int intf_associated;
  665. /*
  666. * Link quality
  667. */
  668. struct link link;
  669. /*
  670. * EEPROM data.
  671. */
  672. __le16 *eeprom;
  673. /*
  674. * Active RF register values.
  675. * These are stored here so we don't need
  676. * to read the rf registers and can directly
  677. * use this value instead.
  678. * This field should be accessed by using
  679. * rt2x00_rf_read() and rt2x00_rf_write().
  680. */
  681. u32 *rf;
  682. /*
  683. * USB Max frame size (for rt2500usb & rt73usb).
  684. */
  685. u16 usb_maxpacket;
  686. /*
  687. * Current TX power value.
  688. */
  689. u16 tx_power;
  690. /*
  691. * Rssi <-> Dbm offset
  692. */
  693. u8 rssi_offset;
  694. /*
  695. * Frequency offset (for rt61pci & rt73usb).
  696. */
  697. u8 freq_offset;
  698. /*
  699. * Low level statistics which will have
  700. * to be kept up to date while device is running.
  701. */
  702. struct ieee80211_low_level_stats low_level_stats;
  703. /*
  704. * RX configuration information.
  705. */
  706. struct ieee80211_rx_status rx_status;
  707. /*
  708. * Scheduled work.
  709. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  710. * which means it cannot be placed on the hw->workqueue
  711. * due to RTNL locking requirements.
  712. */
  713. struct work_struct intf_work;
  714. struct work_struct filter_work;
  715. /*
  716. * Data queue arrays for RX, TX and Beacon.
  717. * The Beacon array also contains the Atim queue
  718. * if that is supported by the device.
  719. */
  720. unsigned int data_queues;
  721. struct data_queue *rx;
  722. struct data_queue *tx;
  723. struct data_queue *bcn;
  724. /*
  725. * Firmware image.
  726. */
  727. const struct firmware *fw;
  728. };
  729. /*
  730. * Generic RF access.
  731. * The RF is being accessed by word index.
  732. */
  733. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  734. const unsigned int word, u32 *data)
  735. {
  736. *data = rt2x00dev->rf[word];
  737. }
  738. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  739. const unsigned int word, u32 data)
  740. {
  741. rt2x00dev->rf[word] = data;
  742. }
  743. /*
  744. * Generic EEPROM access.
  745. * The EEPROM is being accessed by word index.
  746. */
  747. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  748. const unsigned int word)
  749. {
  750. return (void *)&rt2x00dev->eeprom[word];
  751. }
  752. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  753. const unsigned int word, u16 *data)
  754. {
  755. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  756. }
  757. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  758. const unsigned int word, u16 data)
  759. {
  760. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  761. }
  762. /*
  763. * Chipset handlers
  764. */
  765. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  766. const u16 rt, const u16 rf, const u32 rev)
  767. {
  768. INFO(rt2x00dev,
  769. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  770. rt, rf, rev);
  771. rt2x00dev->chip.rt = rt;
  772. rt2x00dev->chip.rf = rf;
  773. rt2x00dev->chip.rev = rev;
  774. }
  775. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  776. {
  777. return (chipset->rt == chip);
  778. }
  779. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  780. {
  781. return (chipset->rf == chip);
  782. }
  783. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  784. {
  785. return chipset->rev;
  786. }
  787. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  788. const u32 rev)
  789. {
  790. return (((chipset->rev & 0xffff0) == rev) &&
  791. !!(chipset->rev & 0x0000f));
  792. }
  793. /*
  794. * Duration calculations
  795. * The rate variable passed is: 100kbs.
  796. * To convert from bytes to bits we multiply size with 8,
  797. * then the size is multiplied with 10 to make the
  798. * real rate -> rate argument correction.
  799. */
  800. static inline u16 get_duration(const unsigned int size, const u8 rate)
  801. {
  802. return ((size * 8 * 10) / rate);
  803. }
  804. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  805. {
  806. return ((size * 8 * 10) % rate);
  807. }
  808. /**
  809. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  810. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  811. * @skb: The skb to map.
  812. */
  813. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  814. /**
  815. * rt2x00queue_get_queue - Convert queue index to queue pointer
  816. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  817. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  818. */
  819. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  820. const enum data_queue_qid queue);
  821. /**
  822. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  823. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  824. * @index: Index identifier for obtaining the correct index.
  825. */
  826. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  827. enum queue_index index);
  828. /*
  829. * Interrupt context handlers.
  830. */
  831. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  832. void rt2x00lib_txdone(struct queue_entry *entry,
  833. struct txdone_entry_desc *txdesc);
  834. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  835. struct queue_entry *entry);
  836. /*
  837. * mac80211 handlers.
  838. */
  839. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  840. int rt2x00mac_start(struct ieee80211_hw *hw);
  841. void rt2x00mac_stop(struct ieee80211_hw *hw);
  842. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  843. struct ieee80211_if_init_conf *conf);
  844. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  845. struct ieee80211_if_init_conf *conf);
  846. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  847. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  848. struct ieee80211_vif *vif,
  849. struct ieee80211_if_conf *conf);
  850. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  851. unsigned int changed_flags,
  852. unsigned int *total_flags,
  853. int mc_count, struct dev_addr_list *mc_list);
  854. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  855. struct ieee80211_low_level_stats *stats);
  856. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  857. struct ieee80211_tx_queue_stats *stats);
  858. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  859. struct ieee80211_vif *vif,
  860. struct ieee80211_bss_conf *bss_conf,
  861. u32 changes);
  862. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  863. const struct ieee80211_tx_queue_params *params);
  864. /*
  865. * Driver allocation handlers.
  866. */
  867. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  868. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  869. #ifdef CONFIG_PM
  870. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  871. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  872. #endif /* CONFIG_PM */
  873. #endif /* RT2X00_H */