rt2x00.h 25 KB

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