rt2x00.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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/mutex.h>
  28. #include <linux/etherdevice.h>
  29. #include <net/mac80211.h>
  30. #include "rt2x00debug.h"
  31. #include "rt2x00reg.h"
  32. #include "rt2x00queue.h"
  33. /*
  34. * Module information.
  35. */
  36. #define DRV_VERSION "2.0.14"
  37. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  38. /*
  39. * Debug definitions.
  40. * Debug output has to be enabled during compile time.
  41. */
  42. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  43. printk(__kernlvl "%s -> %s: %s - " __msg, \
  44. wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
  45. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  46. printk(__kernlvl "%s -> %s: %s - " __msg, \
  47. KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args)
  48. #ifdef CONFIG_RT2X00_DEBUG
  49. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  50. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
  51. #else
  52. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  53. do { } while (0)
  54. #endif /* CONFIG_RT2X00_DEBUG */
  55. /*
  56. * Various debug levels.
  57. * The debug levels PANIC and ERROR both indicate serious problems,
  58. * for this reason they should never be ignored.
  59. * The special ERROR_PROBE message is for messages that are generated
  60. * when the rt2x00_dev is not yet initialized.
  61. */
  62. #define PANIC(__dev, __msg, __args...) \
  63. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  64. #define ERROR(__dev, __msg, __args...) \
  65. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  66. #define ERROR_PROBE(__msg, __args...) \
  67. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  68. #define WARNING(__dev, __msg, __args...) \
  69. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  70. #define NOTICE(__dev, __msg, __args...) \
  71. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  72. #define INFO(__dev, __msg, __args...) \
  73. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  74. #define DEBUG(__dev, __msg, __args...) \
  75. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  76. #define EEPROM(__dev, __msg, __args...) \
  77. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  78. /*
  79. * Standard timing and size defines.
  80. * These values should follow the ieee80211 specifications.
  81. */
  82. #define ACK_SIZE 14
  83. #define IEEE80211_HEADER 24
  84. #define PLCP 48
  85. #define BEACON 100
  86. #define PREAMBLE 144
  87. #define SHORT_PREAMBLE 72
  88. #define SLOT_TIME 20
  89. #define SHORT_SLOT_TIME 9
  90. #define SIFS 10
  91. #define PIFS ( SIFS + SLOT_TIME )
  92. #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
  93. #define DIFS ( PIFS + SLOT_TIME )
  94. #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
  95. #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
  96. /*
  97. * IEEE802.11 header defines
  98. */
  99. static inline int is_rts_frame(u16 fc)
  100. {
  101. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  102. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS));
  103. }
  104. static inline int is_cts_frame(u16 fc)
  105. {
  106. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  107. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS));
  108. }
  109. static inline int is_probe_resp(u16 fc)
  110. {
  111. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
  112. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP));
  113. }
  114. static inline int is_beacon(u16 fc)
  115. {
  116. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
  117. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON));
  118. }
  119. /*
  120. * Chipset identification
  121. * The chipset on the device is composed of a RT and RF chip.
  122. * The chipset combination is important for determining device capabilities.
  123. */
  124. struct rt2x00_chip {
  125. u16 rt;
  126. #define RT2460 0x0101
  127. #define RT2560 0x0201
  128. #define RT2570 0x1201
  129. #define RT2561s 0x0301 /* Turbo */
  130. #define RT2561 0x0302
  131. #define RT2661 0x0401
  132. #define RT2571 0x1300
  133. u16 rf;
  134. u32 rev;
  135. };
  136. /*
  137. * RF register values that belong to a particular channel.
  138. */
  139. struct rf_channel {
  140. int channel;
  141. u32 rf1;
  142. u32 rf2;
  143. u32 rf3;
  144. u32 rf4;
  145. };
  146. /*
  147. * Antenna setup values.
  148. */
  149. struct antenna_setup {
  150. enum antenna rx;
  151. enum antenna tx;
  152. };
  153. /*
  154. * Quality statistics about the currently active link.
  155. */
  156. struct link_qual {
  157. /*
  158. * Statistics required for Link tuning.
  159. * For the average RSSI value we use the "Walking average" approach.
  160. * When adding RSSI to the average value the following calculation
  161. * is needed:
  162. *
  163. * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
  164. *
  165. * The advantage of this approach is that we only need 1 variable
  166. * to store the average in (No need for a count and a total).
  167. * But more importantly, normal average values will over time
  168. * move less and less towards newly added values this results
  169. * that with link tuning, the device can have a very good RSSI
  170. * for a few minutes but when the device is moved away from the AP
  171. * the average will not decrease fast enough to compensate.
  172. * The walking average compensates this and will move towards
  173. * the new values correctly allowing a effective link tuning.
  174. */
  175. int avg_rssi;
  176. int false_cca;
  177. /*
  178. * Statistics required for Signal quality calculation.
  179. * For calculating the Signal quality we have to determine
  180. * the total number of success and failed RX and TX frames.
  181. * After that we also use the average RSSI value to help
  182. * determining the signal quality.
  183. * For the calculation we will use the following algorithm:
  184. *
  185. * rssi_percentage = (avg_rssi * 100) / rssi_offset
  186. * rx_percentage = (rx_success * 100) / rx_total
  187. * tx_percentage = (tx_success * 100) / tx_total
  188. * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
  189. * (WEIGHT_TX * tx_percentage) +
  190. * (WEIGHT_RX * rx_percentage)) / 100
  191. *
  192. * This value should then be checked to not be greated then 100.
  193. */
  194. int rx_percentage;
  195. int rx_success;
  196. int rx_failed;
  197. int tx_percentage;
  198. int tx_success;
  199. int tx_failed;
  200. #define WEIGHT_RSSI 20
  201. #define WEIGHT_RX 40
  202. #define WEIGHT_TX 40
  203. };
  204. /*
  205. * Antenna settings about the currently active link.
  206. */
  207. struct link_ant {
  208. /*
  209. * Antenna flags
  210. */
  211. unsigned int flags;
  212. #define ANTENNA_RX_DIVERSITY 0x00000001
  213. #define ANTENNA_TX_DIVERSITY 0x00000002
  214. #define ANTENNA_MODE_SAMPLE 0x00000004
  215. /*
  216. * Currently active TX/RX antenna setup.
  217. * When software diversity is used, this will indicate
  218. * which antenna is actually used at this time.
  219. */
  220. struct antenna_setup active;
  221. /*
  222. * RSSI information for the different antenna's.
  223. * These statistics are used to determine when
  224. * to switch antenna when using software diversity.
  225. *
  226. * rssi[0] -> Antenna A RSSI
  227. * rssi[1] -> Antenna B RSSI
  228. */
  229. int rssi_history[2];
  230. /*
  231. * Current RSSI average of the currently active antenna.
  232. * Similar to the avg_rssi in the link_qual structure
  233. * this value is updated by using the walking average.
  234. */
  235. int rssi_ant;
  236. };
  237. /*
  238. * To optimize the quality of the link we need to store
  239. * the quality of received frames and periodically
  240. * optimize the link.
  241. */
  242. struct link {
  243. /*
  244. * Link tuner counter
  245. * The number of times the link has been tuned
  246. * since the radio has been switched on.
  247. */
  248. u32 count;
  249. /*
  250. * Quality measurement values.
  251. */
  252. struct link_qual qual;
  253. /*
  254. * TX/RX antenna setup.
  255. */
  256. struct link_ant ant;
  257. /*
  258. * Active VGC level
  259. */
  260. int vgc_level;
  261. /*
  262. * Work structure for scheduling periodic link tuning.
  263. */
  264. struct delayed_work work;
  265. };
  266. /*
  267. * Small helper macro to work with moving/walking averages.
  268. */
  269. #define MOVING_AVERAGE(__avg, __val, __samples) \
  270. ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
  271. /*
  272. * When we lack RSSI information return something less then -80 to
  273. * tell the driver to tune the device to maximum sensitivity.
  274. */
  275. #define DEFAULT_RSSI ( -128 )
  276. /*
  277. * Link quality access functions.
  278. */
  279. static inline int rt2x00_get_link_rssi(struct link *link)
  280. {
  281. if (link->qual.avg_rssi && link->qual.rx_success)
  282. return link->qual.avg_rssi;
  283. return DEFAULT_RSSI;
  284. }
  285. static inline int rt2x00_get_link_ant_rssi(struct link *link)
  286. {
  287. if (link->ant.rssi_ant && link->qual.rx_success)
  288. return link->ant.rssi_ant;
  289. return DEFAULT_RSSI;
  290. }
  291. static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
  292. enum antenna ant)
  293. {
  294. if (link->ant.rssi_history[ant - ANTENNA_A])
  295. return link->ant.rssi_history[ant - ANTENNA_A];
  296. return DEFAULT_RSSI;
  297. }
  298. static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
  299. {
  300. int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
  301. link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
  302. return old_rssi;
  303. }
  304. /*
  305. * Interface structure
  306. * Per interface configuration details, this structure
  307. * is allocated as the private data for ieee80211_vif.
  308. */
  309. struct rt2x00_intf {
  310. /*
  311. * All fields within the rt2x00_intf structure
  312. * must be protected with a spinlock.
  313. */
  314. spinlock_t lock;
  315. /*
  316. * BSS configuration. Copied from the structure
  317. * passed to us through the bss_info_changed()
  318. * callback funtion.
  319. */
  320. struct ieee80211_bss_conf conf;
  321. /*
  322. * MAC of the device.
  323. */
  324. u8 mac[ETH_ALEN];
  325. /*
  326. * BBSID of the AP to associate with.
  327. */
  328. u8 bssid[ETH_ALEN];
  329. /*
  330. * Entry in the beacon queue which belongs to
  331. * this interface. Each interface has its own
  332. * dedicated beacon entry.
  333. */
  334. struct queue_entry *beacon;
  335. /*
  336. * Actions that needed rescheduling.
  337. */
  338. unsigned int delayed_flags;
  339. #define DELAYED_UPDATE_BEACON 0x00000001
  340. #define DELAYED_CONFIG_PREAMBLE 0x00000002
  341. };
  342. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  343. {
  344. return (struct rt2x00_intf *)vif->drv_priv;
  345. }
  346. /*
  347. * Details about the supported modes, rates and channels
  348. * of a particular chipset. This is used by rt2x00lib
  349. * to build the ieee80211_hw_mode array for mac80211.
  350. */
  351. struct hw_mode_spec {
  352. /*
  353. * Number of modes, rates and channels.
  354. */
  355. int num_modes;
  356. int num_rates;
  357. int num_channels;
  358. /*
  359. * txpower values.
  360. */
  361. const u8 *tx_power_a;
  362. const u8 *tx_power_bg;
  363. u8 tx_power_default;
  364. /*
  365. * Device/chipset specific value.
  366. */
  367. const struct rf_channel *channels;
  368. };
  369. /*
  370. * Configuration structure wrapper around the
  371. * mac80211 configuration structure.
  372. * When mac80211 configures the driver, rt2x00lib
  373. * can precalculate values which are equal for all
  374. * rt2x00 drivers. Those values can be stored in here.
  375. */
  376. struct rt2x00lib_conf {
  377. struct ieee80211_conf *conf;
  378. struct rf_channel rf;
  379. struct antenna_setup ant;
  380. int phymode;
  381. int basic_rates;
  382. int slot_time;
  383. short sifs;
  384. short pifs;
  385. short difs;
  386. short eifs;
  387. };
  388. /*
  389. * Configuration structure wrapper around the
  390. * rt2x00 interface configuration handler.
  391. */
  392. struct rt2x00intf_conf {
  393. /*
  394. * Interface type
  395. */
  396. enum ieee80211_if_types type;
  397. /*
  398. * TSF sync value, this is dependant on the operation type.
  399. */
  400. enum tsf_sync sync;
  401. /*
  402. * The MAC and BSSID addressess are simple array of bytes,
  403. * these arrays are little endian, so when sending the addressess
  404. * to the drivers, copy the it into a endian-signed variable.
  405. *
  406. * Note that all devices (except rt2500usb) have 32 bits
  407. * register word sizes. This means that whatever variable we
  408. * pass _must_ be a multiple of 32 bits. Otherwise the device
  409. * might not accept what we are sending to it.
  410. * This will also make it easier for the driver to write
  411. * the data to the device.
  412. */
  413. __le32 mac[2];
  414. __le32 bssid[2];
  415. };
  416. /*
  417. * rt2x00lib callback functions.
  418. */
  419. struct rt2x00lib_ops {
  420. /*
  421. * Interrupt handlers.
  422. */
  423. irq_handler_t irq_handler;
  424. /*
  425. * Device init handlers.
  426. */
  427. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  428. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  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. struct ieee80211_tx_control *control);
  460. int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
  461. struct data_queue *queue, struct sk_buff *skb,
  462. struct ieee80211_tx_control *control);
  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. unsigned int 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_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. int (*config_preamble) (struct rt2x00_dev *rt2x00dev,
  483. const int short_preamble,
  484. const int ack_timeout,
  485. const int ack_consume_time);
  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 struct data_queue_desc *rx;
  507. const struct data_queue_desc *tx;
  508. const struct data_queue_desc *bcn;
  509. const struct data_queue_desc *atim;
  510. const struct rt2x00lib_ops *lib;
  511. const struct ieee80211_ops *hw;
  512. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  513. const struct rt2x00debug *debugfs;
  514. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  515. };
  516. /*
  517. * rt2x00 device flags
  518. */
  519. enum rt2x00_flags {
  520. /*
  521. * Device state flags
  522. */
  523. DEVICE_PRESENT,
  524. DEVICE_REGISTERED_HW,
  525. DEVICE_INITIALIZED,
  526. DEVICE_STARTED,
  527. DEVICE_STARTED_SUSPEND,
  528. DEVICE_ENABLED_RADIO,
  529. DEVICE_DISABLED_RADIO_HW,
  530. /*
  531. * Driver features
  532. */
  533. DRIVER_SUPPORT_MIXED_INTERFACES,
  534. DRIVER_REQUIRE_FIRMWARE,
  535. DRIVER_REQUIRE_FIRMWARE_CRC_ITU_T,
  536. DRIVER_REQUIRE_FIRMWARE_CCITT,
  537. DRIVER_REQUIRE_BEACON_GUARD,
  538. DRIVER_REQUIRE_ATIM_QUEUE,
  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. void *dev;
  562. #define rt2x00dev_pci(__dev) ( (struct pci_dev *)(__dev)->dev )
  563. #define rt2x00dev_usb(__dev) ( (struct usb_interface *)(__dev)->dev )
  564. #define rt2x00dev_usb_dev(__dev)\
  565. ( (struct usb_device *)interface_to_usbdev(rt2x00dev_usb(__dev)) )
  566. /*
  567. * Callback functions.
  568. */
  569. const struct rt2x00_ops *ops;
  570. /*
  571. * IEEE80211 control structure.
  572. */
  573. struct ieee80211_hw *hw;
  574. struct ieee80211_hw_mode *hwmodes;
  575. unsigned int curr_hwmode;
  576. #define HWMODE_B 0
  577. #define HWMODE_G 1
  578. #define HWMODE_A 2
  579. /*
  580. * rfkill structure for RF state switching support.
  581. * This will only be compiled in when required.
  582. */
  583. #ifdef CONFIG_RT2X00_LIB_RFKILL
  584. struct rfkill *rfkill;
  585. struct input_polled_dev *poll_dev;
  586. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  587. /*
  588. * If enabled, the debugfs interface structures
  589. * required for deregistration of debugfs.
  590. */
  591. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  592. struct rt2x00debug_intf *debugfs_intf;
  593. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  594. /*
  595. * Device flags.
  596. * In these flags the current status and some
  597. * of the device capabilities are stored.
  598. */
  599. unsigned long flags;
  600. /*
  601. * Chipset identification.
  602. */
  603. struct rt2x00_chip chip;
  604. /*
  605. * hw capability specifications.
  606. */
  607. struct hw_mode_spec spec;
  608. /*
  609. * This is the default TX/RX antenna setup as indicated
  610. * by the device's EEPROM. When mac80211 sets its
  611. * antenna value to 0 we should be using these values.
  612. */
  613. struct antenna_setup default_ant;
  614. /*
  615. * Register pointers
  616. * csr_addr: Base register address. (PCI)
  617. * csr_cache: CSR cache for usb_control_msg. (USB)
  618. */
  619. void __iomem *csr_addr;
  620. void *csr_cache;
  621. /*
  622. * Mutex to protect register accesses on USB devices.
  623. * There are 2 reasons this is needed, one is to ensure
  624. * use of the csr_cache (for USB devices) by one thread
  625. * isn't corrupted by another thread trying to access it.
  626. * The other is that access to BBP and RF registers
  627. * require multiple BUS transactions and if another thread
  628. * attempted to access one of those registers at the same
  629. * time one of the writes could silently fail.
  630. */
  631. struct mutex usb_cache_mutex;
  632. /*
  633. * Current packet filter configuration for the device.
  634. * This contains all currently active FIF_* flags send
  635. * to us by mac80211 during configure_filter().
  636. */
  637. unsigned int packet_filter;
  638. /*
  639. * Interface details:
  640. * - Open ap interface count.
  641. * - Open sta interface count.
  642. * - Association count.
  643. */
  644. unsigned int intf_ap_count;
  645. unsigned int intf_sta_count;
  646. unsigned int intf_associated;
  647. /*
  648. * Link quality
  649. */
  650. struct link link;
  651. /*
  652. * EEPROM data.
  653. */
  654. __le16 *eeprom;
  655. /*
  656. * Active RF register values.
  657. * These are stored here so we don't need
  658. * to read the rf registers and can directly
  659. * use this value instead.
  660. * This field should be accessed by using
  661. * rt2x00_rf_read() and rt2x00_rf_write().
  662. */
  663. u32 *rf;
  664. /*
  665. * USB Max frame size (for rt2500usb & rt73usb).
  666. */
  667. u16 usb_maxpacket;
  668. /*
  669. * Current TX power value.
  670. */
  671. u16 tx_power;
  672. /*
  673. * LED register (for rt61pci & rt73usb).
  674. */
  675. u16 led_reg;
  676. /*
  677. * Led mode (LED_MODE_*)
  678. */
  679. u8 led_mode;
  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. */
  700. struct work_struct intf_work;
  701. struct work_struct filter_work;
  702. /*
  703. * Data queue arrays for RX, TX and Beacon.
  704. * The Beacon array also contains the Atim queue
  705. * if that is supported by the device.
  706. */
  707. int data_queues;
  708. struct data_queue *rx;
  709. struct data_queue *tx;
  710. struct data_queue *bcn;
  711. /*
  712. * Firmware image.
  713. */
  714. const struct firmware *fw;
  715. };
  716. /*
  717. * Generic RF access.
  718. * The RF is being accessed by word index.
  719. */
  720. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  721. const unsigned int word, u32 *data)
  722. {
  723. *data = rt2x00dev->rf[word];
  724. }
  725. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  726. const unsigned int word, u32 data)
  727. {
  728. rt2x00dev->rf[word] = data;
  729. }
  730. /*
  731. * Generic EEPROM access.
  732. * The EEPROM is being accessed by word index.
  733. */
  734. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  735. const unsigned int word)
  736. {
  737. return (void *)&rt2x00dev->eeprom[word];
  738. }
  739. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  740. const unsigned int word, u16 *data)
  741. {
  742. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  743. }
  744. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  745. const unsigned int word, u16 data)
  746. {
  747. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  748. }
  749. /*
  750. * Chipset handlers
  751. */
  752. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  753. const u16 rt, const u16 rf, const u32 rev)
  754. {
  755. INFO(rt2x00dev,
  756. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  757. rt, rf, rev);
  758. rt2x00dev->chip.rt = rt;
  759. rt2x00dev->chip.rf = rf;
  760. rt2x00dev->chip.rev = rev;
  761. }
  762. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  763. {
  764. return (chipset->rt == chip);
  765. }
  766. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  767. {
  768. return (chipset->rf == chip);
  769. }
  770. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  771. {
  772. return chipset->rev;
  773. }
  774. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  775. const u32 rev)
  776. {
  777. return (((chipset->rev & 0xffff0) == rev) &&
  778. !!(chipset->rev & 0x0000f));
  779. }
  780. /*
  781. * Duration calculations
  782. * The rate variable passed is: 100kbs.
  783. * To convert from bytes to bits we multiply size with 8,
  784. * then the size is multiplied with 10 to make the
  785. * real rate -> rate argument correction.
  786. */
  787. static inline u16 get_duration(const unsigned int size, const u8 rate)
  788. {
  789. return ((size * 8 * 10) / rate);
  790. }
  791. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  792. {
  793. return ((size * 8 * 10) % rate);
  794. }
  795. /**
  796. * rt2x00queue_get_queue - Convert mac80211 queue index to rt2x00 queue
  797. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  798. * @queue: mac80211 queue index (see &enum ieee80211_tx_queue).
  799. */
  800. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  801. const enum ieee80211_tx_queue queue);
  802. /**
  803. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  804. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  805. * @index: Index identifier for obtaining the correct index.
  806. */
  807. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  808. enum queue_index index);
  809. /**
  810. * rt2x00queue_index_inc - Index incrementation function
  811. * @queue: Queue (&struct data_queue) to perform the action on.
  812. * @action: Index type (&enum queue_index) to perform the action on.
  813. *
  814. * This function will increase the requested index on the queue,
  815. * it will grab the appropriate locks and handle queue overflow events by
  816. * resetting the index to the start of the queue.
  817. */
  818. void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
  819. /*
  820. * Interrupt context handlers.
  821. */
  822. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  823. void rt2x00lib_txdone(struct queue_entry *entry,
  824. struct txdone_entry_desc *txdesc);
  825. void rt2x00lib_rxdone(struct queue_entry *entry,
  826. struct rxdone_entry_desc *rxdesc);
  827. /*
  828. * TX descriptor initializer
  829. */
  830. void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  831. struct sk_buff *skb,
  832. struct ieee80211_tx_control *control);
  833. /*
  834. * mac80211 handlers.
  835. */
  836. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  837. struct ieee80211_tx_control *control);
  838. int rt2x00mac_start(struct ieee80211_hw *hw);
  839. void rt2x00mac_stop(struct ieee80211_hw *hw);
  840. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  841. struct ieee80211_if_init_conf *conf);
  842. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  843. struct ieee80211_if_init_conf *conf);
  844. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  845. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  846. struct ieee80211_vif *vif,
  847. struct ieee80211_if_conf *conf);
  848. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  849. struct ieee80211_low_level_stats *stats);
  850. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  851. struct ieee80211_tx_queue_stats *stats);
  852. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  853. struct ieee80211_vif *vif,
  854. struct ieee80211_bss_conf *bss_conf,
  855. u32 changes);
  856. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
  857. const struct ieee80211_tx_queue_params *params);
  858. /*
  859. * Driver allocation handlers.
  860. */
  861. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  862. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  863. #ifdef CONFIG_PM
  864. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  865. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  866. #endif /* CONFIG_PM */
  867. #endif /* RT2X00_H */