rt2x00.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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. u16 seqno;
  326. };
  327. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  328. {
  329. return (struct rt2x00_intf *)vif->drv_priv;
  330. }
  331. /**
  332. * struct hw_mode_spec: Hardware specifications structure
  333. *
  334. * Details about the supported modes, rates and channels
  335. * of a particular chipset. This is used by rt2x00lib
  336. * to build the ieee80211_hw_mode array for mac80211.
  337. *
  338. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  339. * @supported_rates: Rate types which are supported (CCK, OFDM).
  340. * @num_channels: Number of supported channels. This is used as array size
  341. * for @tx_power_a, @tx_power_bg and @channels.
  342. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  343. * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
  344. * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
  345. * @tx_power_default: Default TX power value to use when either
  346. * @tx_power_a or @tx_power_bg is missing.
  347. */
  348. struct hw_mode_spec {
  349. unsigned int supported_bands;
  350. #define SUPPORT_BAND_2GHZ 0x00000001
  351. #define SUPPORT_BAND_5GHZ 0x00000002
  352. unsigned int supported_rates;
  353. #define SUPPORT_RATE_CCK 0x00000001
  354. #define SUPPORT_RATE_OFDM 0x00000002
  355. unsigned int num_channels;
  356. const struct rf_channel *channels;
  357. const u8 *tx_power_a;
  358. const u8 *tx_power_bg;
  359. u8 tx_power_default;
  360. };
  361. /*
  362. * Configuration structure wrapper around the
  363. * mac80211 configuration structure.
  364. * When mac80211 configures the driver, rt2x00lib
  365. * can precalculate values which are equal for all
  366. * rt2x00 drivers. Those values can be stored in here.
  367. */
  368. struct rt2x00lib_conf {
  369. struct ieee80211_conf *conf;
  370. struct rf_channel rf;
  371. struct antenna_setup ant;
  372. enum ieee80211_band band;
  373. u32 basic_rates;
  374. u32 slot_time;
  375. short sifs;
  376. short pifs;
  377. short difs;
  378. short eifs;
  379. };
  380. /*
  381. * Configuration structure for erp settings.
  382. */
  383. struct rt2x00lib_erp {
  384. int short_preamble;
  385. int cts_protection;
  386. int ack_timeout;
  387. int ack_consume_time;
  388. };
  389. /*
  390. * Configuration structure wrapper around the
  391. * rt2x00 interface configuration handler.
  392. */
  393. struct rt2x00intf_conf {
  394. /*
  395. * Interface type
  396. */
  397. enum ieee80211_if_types type;
  398. /*
  399. * TSF sync value, this is dependant on the operation type.
  400. */
  401. enum tsf_sync sync;
  402. /*
  403. * The MAC and BSSID addressess are simple array of bytes,
  404. * these arrays are little endian, so when sending the addressess
  405. * to the drivers, copy the it into a endian-signed variable.
  406. *
  407. * Note that all devices (except rt2500usb) have 32 bits
  408. * register word sizes. This means that whatever variable we
  409. * pass _must_ be a multiple of 32 bits. Otherwise the device
  410. * might not accept what we are sending to it.
  411. * This will also make it easier for the driver to write
  412. * the data to the device.
  413. */
  414. __le32 mac[2];
  415. __le32 bssid[2];
  416. };
  417. /*
  418. * rt2x00lib callback functions.
  419. */
  420. struct rt2x00lib_ops {
  421. /*
  422. * Interrupt handlers.
  423. */
  424. irq_handler_t irq_handler;
  425. /*
  426. * Device init handlers.
  427. */
  428. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  429. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  430. u16 (*get_firmware_crc) (const void *data, const size_t len);
  431. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const 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. /*
  456. * TX control handlers
  457. */
  458. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  459. struct sk_buff *skb,
  460. struct txentry_desc *txdesc);
  461. int (*write_tx_data) (struct queue_entry *entry);
  462. void (*write_beacon) (struct queue_entry *entry);
  463. int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
  464. struct sk_buff *skb);
  465. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  466. const enum data_queue_qid queue);
  467. /*
  468. * RX control handlers
  469. */
  470. void (*fill_rxdone) (struct queue_entry *entry,
  471. struct rxdone_entry_desc *rxdesc);
  472. /*
  473. * Configuration handlers.
  474. */
  475. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  476. const unsigned int filter_flags);
  477. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  478. struct rt2x00_intf *intf,
  479. struct rt2x00intf_conf *conf,
  480. const unsigned int flags);
  481. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  482. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  483. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  484. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  485. struct rt2x00lib_erp *erp);
  486. void (*config) (struct rt2x00_dev *rt2x00dev,
  487. struct rt2x00lib_conf *libconf,
  488. const unsigned int flags);
  489. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  490. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  491. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  492. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  493. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  494. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  495. #define CONFIG_UPDATE_ALL 0xffff
  496. };
  497. /*
  498. * rt2x00 driver callback operation structure.
  499. */
  500. struct rt2x00_ops {
  501. const char *name;
  502. const unsigned int max_sta_intf;
  503. const unsigned int max_ap_intf;
  504. const unsigned int eeprom_size;
  505. const unsigned int rf_size;
  506. const unsigned int tx_queues;
  507. const struct data_queue_desc *rx;
  508. const struct data_queue_desc *tx;
  509. const struct data_queue_desc *bcn;
  510. const struct data_queue_desc *atim;
  511. const struct rt2x00lib_ops *lib;
  512. const struct ieee80211_ops *hw;
  513. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  514. const struct rt2x00debug *debugfs;
  515. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  516. };
  517. /*
  518. * rt2x00 device flags
  519. */
  520. enum rt2x00_flags {
  521. /*
  522. * Device state flags
  523. */
  524. DEVICE_PRESENT,
  525. DEVICE_REGISTERED_HW,
  526. DEVICE_INITIALIZED,
  527. DEVICE_STARTED,
  528. DEVICE_STARTED_SUSPEND,
  529. DEVICE_ENABLED_RADIO,
  530. DEVICE_DISABLED_RADIO_HW,
  531. /*
  532. * Driver features
  533. */
  534. DRIVER_REQUIRE_FIRMWARE,
  535. DRIVER_REQUIRE_BEACON_GUARD,
  536. DRIVER_REQUIRE_ATIM_QUEUE,
  537. DRIVER_REQUIRE_SCHEDULED,
  538. DRIVER_REQUIRE_DMA,
  539. /*
  540. * Driver configuration
  541. */
  542. CONFIG_SUPPORT_HW_BUTTON,
  543. CONFIG_FRAME_TYPE,
  544. CONFIG_RF_SEQUENCE,
  545. CONFIG_EXTERNAL_LNA_A,
  546. CONFIG_EXTERNAL_LNA_BG,
  547. CONFIG_DOUBLE_ANTENNA,
  548. CONFIG_DISABLE_LINK_TUNING,
  549. };
  550. /*
  551. * rt2x00 device structure.
  552. */
  553. struct rt2x00_dev {
  554. /*
  555. * Device structure.
  556. * The structure stored in here depends on the
  557. * system bus (PCI or USB).
  558. * When accessing this variable, the rt2x00dev_{pci,usb}
  559. * macro's should be used for correct typecasting.
  560. */
  561. struct device *dev;
  562. /*
  563. * Callback functions.
  564. */
  565. const struct rt2x00_ops *ops;
  566. /*
  567. * IEEE80211 control structure.
  568. */
  569. struct ieee80211_hw *hw;
  570. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  571. enum ieee80211_band curr_band;
  572. /*
  573. * rfkill structure for RF state switching support.
  574. * This will only be compiled in when required.
  575. */
  576. #ifdef CONFIG_RT2X00_LIB_RFKILL
  577. unsigned long rfkill_state;
  578. #define RFKILL_STATE_ALLOCATED 1
  579. #define RFKILL_STATE_REGISTERED 2
  580. struct rfkill *rfkill;
  581. struct delayed_work rfkill_work;
  582. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  583. /*
  584. * If enabled, the debugfs interface structures
  585. * required for deregistration of debugfs.
  586. */
  587. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  588. struct rt2x00debug_intf *debugfs_intf;
  589. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  590. /*
  591. * LED structure for changing the LED status
  592. * by mac8011 or the kernel.
  593. */
  594. #ifdef CONFIG_RT2X00_LIB_LEDS
  595. struct rt2x00_led led_radio;
  596. struct rt2x00_led led_assoc;
  597. struct rt2x00_led led_qual;
  598. u16 led_mcu_reg;
  599. #endif /* CONFIG_RT2X00_LIB_LEDS */
  600. /*
  601. * Device flags.
  602. * In these flags the current status and some
  603. * of the device capabilities are stored.
  604. */
  605. unsigned long flags;
  606. /*
  607. * Chipset identification.
  608. */
  609. struct rt2x00_chip chip;
  610. /*
  611. * hw capability specifications.
  612. */
  613. struct hw_mode_spec spec;
  614. /*
  615. * This is the default TX/RX antenna setup as indicated
  616. * by the device's EEPROM. When mac80211 sets its
  617. * antenna value to 0 we should be using these values.
  618. */
  619. struct antenna_setup default_ant;
  620. /*
  621. * Register pointers
  622. * csr.base: CSR base register address. (PCI)
  623. * csr.cache: CSR cache for usb_control_msg. (USB)
  624. */
  625. union csr {
  626. void __iomem *base;
  627. void *cache;
  628. } csr;
  629. /*
  630. * Mutex to protect register accesses on USB devices.
  631. * There are 2 reasons this is needed, one is to ensure
  632. * use of the csr_cache (for USB devices) by one thread
  633. * isn't corrupted by another thread trying to access it.
  634. * The other is that access to BBP and RF registers
  635. * require multiple BUS transactions and if another thread
  636. * attempted to access one of those registers at the same
  637. * time one of the writes could silently fail.
  638. */
  639. struct mutex usb_cache_mutex;
  640. /*
  641. * Current packet filter configuration for the device.
  642. * This contains all currently active FIF_* flags send
  643. * to us by mac80211 during configure_filter().
  644. */
  645. unsigned int packet_filter;
  646. /*
  647. * Interface details:
  648. * - Open ap interface count.
  649. * - Open sta interface count.
  650. * - Association count.
  651. */
  652. unsigned int intf_ap_count;
  653. unsigned int intf_sta_count;
  654. unsigned int intf_associated;
  655. /*
  656. * Link quality
  657. */
  658. struct link link;
  659. /*
  660. * EEPROM data.
  661. */
  662. __le16 *eeprom;
  663. /*
  664. * Active RF register values.
  665. * These are stored here so we don't need
  666. * to read the rf registers and can directly
  667. * use this value instead.
  668. * This field should be accessed by using
  669. * rt2x00_rf_read() and rt2x00_rf_write().
  670. */
  671. u32 *rf;
  672. /*
  673. * USB Max frame size (for rt2500usb & rt73usb).
  674. */
  675. u16 usb_maxpacket;
  676. /*
  677. * Current TX power value.
  678. */
  679. u16 tx_power;
  680. /*
  681. * Rssi <-> Dbm offset
  682. */
  683. u8 rssi_offset;
  684. /*
  685. * Frequency offset (for rt61pci & rt73usb).
  686. */
  687. u8 freq_offset;
  688. /*
  689. * Low level statistics which will have
  690. * to be kept up to date while device is running.
  691. */
  692. struct ieee80211_low_level_stats low_level_stats;
  693. /*
  694. * RX configuration information.
  695. */
  696. struct ieee80211_rx_status rx_status;
  697. /*
  698. * Scheduled work.
  699. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  700. * which means it cannot be placed on the hw->workqueue
  701. * due to RTNL locking requirements.
  702. */
  703. struct work_struct intf_work;
  704. struct work_struct filter_work;
  705. /*
  706. * Data queue arrays for RX, TX and Beacon.
  707. * The Beacon array also contains the Atim queue
  708. * if that is supported by the device.
  709. */
  710. unsigned int data_queues;
  711. struct data_queue *rx;
  712. struct data_queue *tx;
  713. struct data_queue *bcn;
  714. /*
  715. * Firmware image.
  716. */
  717. const struct firmware *fw;
  718. };
  719. /*
  720. * Generic RF access.
  721. * The RF is being accessed by word index.
  722. */
  723. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  724. const unsigned int word, u32 *data)
  725. {
  726. *data = rt2x00dev->rf[word];
  727. }
  728. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  729. const unsigned int word, u32 data)
  730. {
  731. rt2x00dev->rf[word] = data;
  732. }
  733. /*
  734. * Generic EEPROM access.
  735. * The EEPROM is being accessed by word index.
  736. */
  737. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  738. const unsigned int word)
  739. {
  740. return (void *)&rt2x00dev->eeprom[word];
  741. }
  742. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  743. const unsigned int word, u16 *data)
  744. {
  745. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  746. }
  747. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  748. const unsigned int word, u16 data)
  749. {
  750. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  751. }
  752. /*
  753. * Chipset handlers
  754. */
  755. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  756. const u16 rt, const u16 rf, const u32 rev)
  757. {
  758. INFO(rt2x00dev,
  759. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  760. rt, rf, rev);
  761. rt2x00dev->chip.rt = rt;
  762. rt2x00dev->chip.rf = rf;
  763. rt2x00dev->chip.rev = rev;
  764. }
  765. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  766. {
  767. return (chipset->rt == chip);
  768. }
  769. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  770. {
  771. return (chipset->rf == chip);
  772. }
  773. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  774. {
  775. return chipset->rev;
  776. }
  777. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  778. const u32 rev)
  779. {
  780. return (((chipset->rev & 0xffff0) == rev) &&
  781. !!(chipset->rev & 0x0000f));
  782. }
  783. /*
  784. * Duration calculations
  785. * The rate variable passed is: 100kbs.
  786. * To convert from bytes to bits we multiply size with 8,
  787. * then the size is multiplied with 10 to make the
  788. * real rate -> rate argument correction.
  789. */
  790. static inline u16 get_duration(const unsigned int size, const u8 rate)
  791. {
  792. return ((size * 8 * 10) / rate);
  793. }
  794. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  795. {
  796. return ((size * 8 * 10) % rate);
  797. }
  798. /**
  799. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  800. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  801. * @skb: The skb to map.
  802. */
  803. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  804. /**
  805. * rt2x00queue_get_queue - Convert queue index to queue pointer
  806. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  807. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  808. */
  809. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  810. const enum data_queue_qid queue);
  811. /**
  812. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  813. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  814. * @index: Index identifier for obtaining the correct index.
  815. */
  816. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  817. enum queue_index index);
  818. /*
  819. * Interrupt context handlers.
  820. */
  821. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  822. void rt2x00lib_txdone(struct queue_entry *entry,
  823. struct txdone_entry_desc *txdesc);
  824. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  825. struct queue_entry *entry);
  826. /*
  827. * mac80211 handlers.
  828. */
  829. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  830. int rt2x00mac_start(struct ieee80211_hw *hw);
  831. void rt2x00mac_stop(struct ieee80211_hw *hw);
  832. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  833. struct ieee80211_if_init_conf *conf);
  834. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  835. struct ieee80211_if_init_conf *conf);
  836. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  837. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  838. struct ieee80211_vif *vif,
  839. struct ieee80211_if_conf *conf);
  840. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  841. unsigned int changed_flags,
  842. unsigned int *total_flags,
  843. int mc_count, struct dev_addr_list *mc_list);
  844. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  845. struct ieee80211_low_level_stats *stats);
  846. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  847. struct ieee80211_tx_queue_stats *stats);
  848. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  849. struct ieee80211_vif *vif,
  850. struct ieee80211_bss_conf *bss_conf,
  851. u32 changes);
  852. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  853. const struct ieee80211_tx_queue_params *params);
  854. /*
  855. * Driver allocation handlers.
  856. */
  857. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  858. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  859. #ifdef CONFIG_PM
  860. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  861. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  862. #endif /* CONFIG_PM */
  863. #endif /* RT2X00_H */