rt2x00.h 27 KB

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