rt2x00.h 25 KB

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