rt2x00.h 26 KB

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