rt2x00.h 24 KB

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