rt2x00.h 26 KB

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