rt2x00.h 26 KB

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