rt2x00.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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. u16 (*get_firmware_crc) (const void *data, const size_t len);
  412. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const void *data,
  413. const size_t len);
  414. /*
  415. * Device initialization/deinitialization handlers.
  416. */
  417. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  418. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  419. /*
  420. * queue initialization handlers
  421. */
  422. bool (*get_entry_state) (struct queue_entry *entry);
  423. void (*clear_entry) (struct queue_entry *entry);
  424. /*
  425. * Radio control handlers.
  426. */
  427. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  428. enum dev_state state);
  429. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  430. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  431. struct link_qual *qual);
  432. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  433. struct link_qual *qual);
  434. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  435. struct link_qual *qual, const u32 count);
  436. /*
  437. * TX control handlers
  438. */
  439. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  440. struct sk_buff *skb,
  441. struct txentry_desc *txdesc);
  442. int (*write_tx_data) (struct queue_entry *entry);
  443. void (*write_beacon) (struct queue_entry *entry);
  444. int (*get_tx_data_len) (struct queue_entry *entry);
  445. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  446. const enum data_queue_qid queue);
  447. /*
  448. * RX control handlers
  449. */
  450. void (*fill_rxdone) (struct queue_entry *entry,
  451. struct rxdone_entry_desc *rxdesc);
  452. /*
  453. * Configuration handlers.
  454. */
  455. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  456. struct rt2x00lib_crypto *crypto,
  457. struct ieee80211_key_conf *key);
  458. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  459. struct rt2x00lib_crypto *crypto,
  460. struct ieee80211_key_conf *key);
  461. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  462. const unsigned int filter_flags);
  463. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  464. struct rt2x00_intf *intf,
  465. struct rt2x00intf_conf *conf,
  466. const unsigned int flags);
  467. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  468. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  469. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  470. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  471. struct rt2x00lib_erp *erp);
  472. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  473. struct antenna_setup *ant);
  474. void (*config) (struct rt2x00_dev *rt2x00dev,
  475. struct rt2x00lib_conf *libconf,
  476. const unsigned int changed_flags);
  477. };
  478. /*
  479. * rt2x00 driver callback operation structure.
  480. */
  481. struct rt2x00_ops {
  482. const char *name;
  483. const unsigned int max_sta_intf;
  484. const unsigned int max_ap_intf;
  485. const unsigned int eeprom_size;
  486. const unsigned int rf_size;
  487. const unsigned int tx_queues;
  488. const struct data_queue_desc *rx;
  489. const struct data_queue_desc *tx;
  490. const struct data_queue_desc *bcn;
  491. const struct data_queue_desc *atim;
  492. const struct rt2x00lib_ops *lib;
  493. const struct ieee80211_ops *hw;
  494. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  495. const struct rt2x00debug *debugfs;
  496. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  497. };
  498. /*
  499. * rt2x00 device flags
  500. */
  501. enum rt2x00_flags {
  502. /*
  503. * Device state flags
  504. */
  505. DEVICE_STATE_PRESENT,
  506. DEVICE_STATE_REGISTERED_HW,
  507. DEVICE_STATE_INITIALIZED,
  508. DEVICE_STATE_STARTED,
  509. DEVICE_STATE_ENABLED_RADIO,
  510. DEVICE_STATE_DISABLED_RADIO_HW,
  511. /*
  512. * Driver requirements
  513. */
  514. DRIVER_REQUIRE_FIRMWARE,
  515. DRIVER_REQUIRE_BEACON_GUARD,
  516. DRIVER_REQUIRE_ATIM_QUEUE,
  517. DRIVER_REQUIRE_SCHEDULED,
  518. DRIVER_REQUIRE_DMA,
  519. DRIVER_REQUIRE_COPY_IV,
  520. /*
  521. * Driver features
  522. */
  523. CONFIG_SUPPORT_HW_BUTTON,
  524. CONFIG_SUPPORT_HW_CRYPTO,
  525. /*
  526. * Driver configuration
  527. */
  528. CONFIG_FRAME_TYPE,
  529. CONFIG_RF_SEQUENCE,
  530. CONFIG_EXTERNAL_LNA_A,
  531. CONFIG_EXTERNAL_LNA_BG,
  532. CONFIG_DOUBLE_ANTENNA,
  533. CONFIG_DISABLE_LINK_TUNING,
  534. };
  535. /*
  536. * rt2x00 device structure.
  537. */
  538. struct rt2x00_dev {
  539. /*
  540. * Device structure.
  541. * The structure stored in here depends on the
  542. * system bus (PCI or USB).
  543. * When accessing this variable, the rt2x00dev_{pci,usb}
  544. * macro's should be used for correct typecasting.
  545. */
  546. struct device *dev;
  547. /*
  548. * Callback functions.
  549. */
  550. const struct rt2x00_ops *ops;
  551. /*
  552. * IEEE80211 control structure.
  553. */
  554. struct ieee80211_hw *hw;
  555. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  556. enum ieee80211_band curr_band;
  557. /*
  558. * rfkill structure for RF state switching support.
  559. * This will only be compiled in when required.
  560. */
  561. #ifdef CONFIG_RT2X00_LIB_RFKILL
  562. unsigned long rfkill_state;
  563. #define RFKILL_STATE_ALLOCATED 1
  564. #define RFKILL_STATE_REGISTERED 2
  565. #define RFKILL_STATE_BLOCKED 3
  566. struct input_polled_dev *rfkill_poll_dev;
  567. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  568. /*
  569. * If enabled, the debugfs interface structures
  570. * required for deregistration of debugfs.
  571. */
  572. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  573. struct rt2x00debug_intf *debugfs_intf;
  574. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  575. /*
  576. * LED structure for changing the LED status
  577. * by mac8011 or the kernel.
  578. */
  579. #ifdef CONFIG_RT2X00_LIB_LEDS
  580. struct rt2x00_led led_radio;
  581. struct rt2x00_led led_assoc;
  582. struct rt2x00_led led_qual;
  583. u16 led_mcu_reg;
  584. #endif /* CONFIG_RT2X00_LIB_LEDS */
  585. /*
  586. * Device flags.
  587. * In these flags the current status and some
  588. * of the device capabilities are stored.
  589. */
  590. unsigned long flags;
  591. /*
  592. * Chipset identification.
  593. */
  594. struct rt2x00_chip chip;
  595. /*
  596. * hw capability specifications.
  597. */
  598. struct hw_mode_spec spec;
  599. /*
  600. * This is the default TX/RX antenna setup as indicated
  601. * by the device's EEPROM.
  602. */
  603. struct antenna_setup default_ant;
  604. /*
  605. * Register pointers
  606. * csr.base: CSR base register address. (PCI)
  607. * csr.cache: CSR cache for usb_control_msg. (USB)
  608. */
  609. union csr {
  610. void __iomem *base;
  611. void *cache;
  612. } csr;
  613. /*
  614. * Mutex to protect register accesses.
  615. * For PCI and USB devices it protects against concurrent indirect
  616. * register access (BBP, RF, MCU) since accessing those
  617. * registers require multiple calls to the CSR registers.
  618. * For USB devices it also protects the csr_cache since that
  619. * field is used for normal CSR access and it cannot support
  620. * multiple callers simultaneously.
  621. */
  622. struct mutex csr_mutex;
  623. /*
  624. * Current packet filter configuration for the device.
  625. * This contains all currently active FIF_* flags send
  626. * to us by mac80211 during configure_filter().
  627. */
  628. unsigned int packet_filter;
  629. /*
  630. * Interface details:
  631. * - Open ap interface count.
  632. * - Open sta interface count.
  633. * - Association count.
  634. */
  635. unsigned int intf_ap_count;
  636. unsigned int intf_sta_count;
  637. unsigned int intf_associated;
  638. /*
  639. * Link quality
  640. */
  641. struct link link;
  642. /*
  643. * EEPROM data.
  644. */
  645. __le16 *eeprom;
  646. /*
  647. * Active RF register values.
  648. * These are stored here so we don't need
  649. * to read the rf registers and can directly
  650. * use this value instead.
  651. * This field should be accessed by using
  652. * rt2x00_rf_read() and rt2x00_rf_write().
  653. */
  654. u32 *rf;
  655. /*
  656. * LNA gain
  657. */
  658. short lna_gain;
  659. /*
  660. * Current TX power value.
  661. */
  662. u16 tx_power;
  663. /*
  664. * Current retry values.
  665. */
  666. u8 short_retry;
  667. u8 long_retry;
  668. /*
  669. * Rssi <-> Dbm offset
  670. */
  671. u8 rssi_offset;
  672. /*
  673. * Frequency offset (for rt61pci & rt73usb).
  674. */
  675. u8 freq_offset;
  676. /*
  677. * Low level statistics which will have
  678. * to be kept up to date while device is running.
  679. */
  680. struct ieee80211_low_level_stats low_level_stats;
  681. /*
  682. * RX configuration information.
  683. */
  684. struct ieee80211_rx_status rx_status;
  685. /*
  686. * Scheduled work.
  687. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  688. * which means it cannot be placed on the hw->workqueue
  689. * due to RTNL locking requirements.
  690. */
  691. struct work_struct intf_work;
  692. struct work_struct filter_work;
  693. /*
  694. * Data queue arrays for RX, TX and Beacon.
  695. * The Beacon array also contains the Atim queue
  696. * if that is supported by the device.
  697. */
  698. unsigned int data_queues;
  699. struct data_queue *rx;
  700. struct data_queue *tx;
  701. struct data_queue *bcn;
  702. /*
  703. * Firmware image.
  704. */
  705. const struct firmware *fw;
  706. };
  707. /*
  708. * Generic RF access.
  709. * The RF is being accessed by word index.
  710. */
  711. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  712. const unsigned int word, u32 *data)
  713. {
  714. *data = rt2x00dev->rf[word];
  715. }
  716. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  717. const unsigned int word, u32 data)
  718. {
  719. rt2x00dev->rf[word] = data;
  720. }
  721. /*
  722. * Generic EEPROM access.
  723. * The EEPROM is being accessed by word index.
  724. */
  725. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  726. const unsigned int word)
  727. {
  728. return (void *)&rt2x00dev->eeprom[word];
  729. }
  730. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  731. const unsigned int word, u16 *data)
  732. {
  733. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  734. }
  735. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  736. const unsigned int word, u16 data)
  737. {
  738. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  739. }
  740. /*
  741. * Chipset handlers
  742. */
  743. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  744. const u16 rt, const u16 rf, const u32 rev)
  745. {
  746. INFO(rt2x00dev,
  747. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  748. rt, rf, rev);
  749. rt2x00dev->chip.rt = rt;
  750. rt2x00dev->chip.rf = rf;
  751. rt2x00dev->chip.rev = rev;
  752. }
  753. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  754. {
  755. return (chipset->rt == chip);
  756. }
  757. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  758. {
  759. return (chipset->rf == chip);
  760. }
  761. static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)
  762. {
  763. return chipset->rev;
  764. }
  765. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  766. const u32 rev)
  767. {
  768. return (((chipset->rev & 0xffff0) == rev) &&
  769. !!(chipset->rev & 0x0000f));
  770. }
  771. /**
  772. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  773. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  774. * @skb: The skb to map.
  775. */
  776. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  777. /**
  778. * rt2x00queue_get_queue - Convert queue index to queue pointer
  779. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  780. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  781. */
  782. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  783. const enum data_queue_qid queue);
  784. /**
  785. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  786. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  787. * @index: Index identifier for obtaining the correct index.
  788. */
  789. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  790. enum queue_index index);
  791. /*
  792. * Interrupt context handlers.
  793. */
  794. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  795. void rt2x00lib_txdone(struct queue_entry *entry,
  796. struct txdone_entry_desc *txdesc);
  797. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  798. struct queue_entry *entry);
  799. /*
  800. * mac80211 handlers.
  801. */
  802. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  803. int rt2x00mac_start(struct ieee80211_hw *hw);
  804. void rt2x00mac_stop(struct ieee80211_hw *hw);
  805. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  806. struct ieee80211_if_init_conf *conf);
  807. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  808. struct ieee80211_if_init_conf *conf);
  809. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  810. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  811. struct ieee80211_vif *vif,
  812. struct ieee80211_if_conf *conf);
  813. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  814. unsigned int changed_flags,
  815. unsigned int *total_flags,
  816. int mc_count, struct dev_addr_list *mc_list);
  817. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  818. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  819. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  820. struct ieee80211_key_conf *key);
  821. #else
  822. #define rt2x00mac_set_key NULL
  823. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  824. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  825. struct ieee80211_low_level_stats *stats);
  826. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  827. struct ieee80211_tx_queue_stats *stats);
  828. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  829. struct ieee80211_vif *vif,
  830. struct ieee80211_bss_conf *bss_conf,
  831. u32 changes);
  832. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  833. const struct ieee80211_tx_queue_params *params);
  834. /*
  835. * Driver allocation handlers.
  836. */
  837. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  838. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  839. #ifdef CONFIG_PM
  840. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  841. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  842. #endif /* CONFIG_PM */
  843. #endif /* RT2X00_H */