rt2x00.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 by driver
  159. * The rssi value is provided by rt2x00lib during the
  160. * link_tuner() callback function.
  161. * The false_cca field is filled during the link_stats()
  162. * callback function and could be used during the
  163. * link_tuner() callback function.
  164. */
  165. int rssi;
  166. int false_cca;
  167. /*
  168. * VGC levels
  169. * Hardware driver will tune the VGC level during each call
  170. * to the link_tuner() callback function. This vgc_level is
  171. * is determined based on the link quality statistics like
  172. * average RSSI and the false CCA count.
  173. *
  174. * In some cases the drivers need to differentiate between
  175. * the currently "desired" VGC level and the level configured
  176. * in the hardware. The latter is important to reduce the
  177. * number of BBP register reads to reduce register access
  178. * overhead. For this reason we store both values here.
  179. */
  180. u8 vgc_level;
  181. u8 vgc_level_reg;
  182. /*
  183. * Statistics required for Signal quality calculation.
  184. * These fields might be changed during the link_stats()
  185. * callback function.
  186. */
  187. int rx_success;
  188. int rx_failed;
  189. int tx_success;
  190. int tx_failed;
  191. };
  192. /*
  193. * Antenna settings about the currently active link.
  194. */
  195. struct link_ant {
  196. /*
  197. * Antenna flags
  198. */
  199. unsigned int flags;
  200. #define ANTENNA_RX_DIVERSITY 0x00000001
  201. #define ANTENNA_TX_DIVERSITY 0x00000002
  202. #define ANTENNA_MODE_SAMPLE 0x00000004
  203. /*
  204. * Currently active TX/RX antenna setup.
  205. * When software diversity is used, this will indicate
  206. * which antenna is actually used at this time.
  207. */
  208. struct antenna_setup active;
  209. /*
  210. * RSSI information for the different antenna's.
  211. * These statistics are used to determine when
  212. * to switch antenna when using software diversity.
  213. *
  214. * rssi[0] -> Antenna A RSSI
  215. * rssi[1] -> Antenna B RSSI
  216. */
  217. int rssi_history[2];
  218. /*
  219. * Current RSSI average of the currently active antenna.
  220. * Similar to the avg_rssi in the link_qual structure
  221. * this value is updated by using the walking average.
  222. */
  223. int rssi_ant;
  224. };
  225. /*
  226. * To optimize the quality of the link we need to store
  227. * the quality of received frames and periodically
  228. * optimize the link.
  229. */
  230. struct link {
  231. /*
  232. * Link tuner counter
  233. * The number of times the link has been tuned
  234. * since the radio has been switched on.
  235. */
  236. u32 count;
  237. /*
  238. * Quality measurement values.
  239. */
  240. struct link_qual qual;
  241. /*
  242. * TX/RX antenna setup.
  243. */
  244. struct link_ant ant;
  245. /*
  246. * Currently active average RSSI value
  247. */
  248. int avg_rssi;
  249. /*
  250. * Currently precalculated percentages of successful
  251. * TX and RX frames.
  252. */
  253. int rx_percentage;
  254. int tx_percentage;
  255. /*
  256. * Work structure for scheduling periodic link tuning.
  257. */
  258. struct delayed_work work;
  259. };
  260. /*
  261. * Interface structure
  262. * Per interface configuration details, this structure
  263. * is allocated as the private data for ieee80211_vif.
  264. */
  265. struct rt2x00_intf {
  266. /*
  267. * All fields within the rt2x00_intf structure
  268. * must be protected with a spinlock.
  269. */
  270. spinlock_t lock;
  271. /*
  272. * MAC of the device.
  273. */
  274. u8 mac[ETH_ALEN];
  275. /*
  276. * BBSID of the AP to associate with.
  277. */
  278. u8 bssid[ETH_ALEN];
  279. /*
  280. * Entry in the beacon queue which belongs to
  281. * this interface. Each interface has its own
  282. * dedicated beacon entry.
  283. */
  284. struct queue_entry *beacon;
  285. /*
  286. * Actions that needed rescheduling.
  287. */
  288. unsigned int delayed_flags;
  289. #define DELAYED_UPDATE_BEACON 0x00000001
  290. #define DELAYED_CONFIG_ERP 0x00000002
  291. #define DELAYED_LED_ASSOC 0x00000004
  292. /*
  293. * Software sequence counter, this is only required
  294. * for hardware which doesn't support hardware
  295. * sequence counting.
  296. */
  297. spinlock_t seqlock;
  298. u16 seqno;
  299. };
  300. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  301. {
  302. return (struct rt2x00_intf *)vif->drv_priv;
  303. }
  304. /**
  305. * struct hw_mode_spec: Hardware specifications structure
  306. *
  307. * Details about the supported modes, rates and channels
  308. * of a particular chipset. This is used by rt2x00lib
  309. * to build the ieee80211_hw_mode array for mac80211.
  310. *
  311. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  312. * @supported_rates: Rate types which are supported (CCK, OFDM).
  313. * @num_channels: Number of supported channels. This is used as array size
  314. * for @tx_power_a, @tx_power_bg and @channels.
  315. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  316. * @channels_info: Additional information for channels (See &struct channel_info).
  317. */
  318. struct hw_mode_spec {
  319. unsigned int supported_bands;
  320. #define SUPPORT_BAND_2GHZ 0x00000001
  321. #define SUPPORT_BAND_5GHZ 0x00000002
  322. unsigned int supported_rates;
  323. #define SUPPORT_RATE_CCK 0x00000001
  324. #define SUPPORT_RATE_OFDM 0x00000002
  325. unsigned int num_channels;
  326. const struct rf_channel *channels;
  327. const struct channel_info *channels_info;
  328. };
  329. /*
  330. * Configuration structure wrapper around the
  331. * mac80211 configuration structure.
  332. * When mac80211 configures the driver, rt2x00lib
  333. * can precalculate values which are equal for all
  334. * rt2x00 drivers. Those values can be stored in here.
  335. */
  336. struct rt2x00lib_conf {
  337. struct ieee80211_conf *conf;
  338. struct rf_channel rf;
  339. struct channel_info channel;
  340. };
  341. /*
  342. * Configuration structure for erp settings.
  343. */
  344. struct rt2x00lib_erp {
  345. int short_preamble;
  346. int cts_protection;
  347. int ack_timeout;
  348. int ack_consume_time;
  349. u64 basic_rates;
  350. int slot_time;
  351. short sifs;
  352. short pifs;
  353. short difs;
  354. short eifs;
  355. };
  356. /*
  357. * Configuration structure for hardware encryption.
  358. */
  359. struct rt2x00lib_crypto {
  360. enum cipher cipher;
  361. enum set_key_cmd cmd;
  362. const u8 *address;
  363. u32 bssidx;
  364. u32 aid;
  365. u8 key[16];
  366. u8 tx_mic[8];
  367. u8 rx_mic[8];
  368. };
  369. /*
  370. * Configuration structure wrapper around the
  371. * rt2x00 interface configuration handler.
  372. */
  373. struct rt2x00intf_conf {
  374. /*
  375. * Interface type
  376. */
  377. enum nl80211_iftype type;
  378. /*
  379. * TSF sync value, this is dependant on the operation type.
  380. */
  381. enum tsf_sync sync;
  382. /*
  383. * The MAC and BSSID addressess are simple array of bytes,
  384. * these arrays are little endian, so when sending the addressess
  385. * to the drivers, copy the it into a endian-signed variable.
  386. *
  387. * Note that all devices (except rt2500usb) have 32 bits
  388. * register word sizes. This means that whatever variable we
  389. * pass _must_ be a multiple of 32 bits. Otherwise the device
  390. * might not accept what we are sending to it.
  391. * This will also make it easier for the driver to write
  392. * the data to the device.
  393. */
  394. __le32 mac[2];
  395. __le32 bssid[2];
  396. };
  397. /*
  398. * rt2x00lib callback functions.
  399. */
  400. struct rt2x00lib_ops {
  401. /*
  402. * Interrupt handlers.
  403. */
  404. irq_handler_t irq_handler;
  405. /*
  406. * Device init handlers.
  407. */
  408. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  409. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  410. u16 (*get_firmware_crc) (const void *data, const size_t len);
  411. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, const void *data,
  412. const size_t len);
  413. /*
  414. * Device initialization/deinitialization handlers.
  415. */
  416. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  417. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  418. /*
  419. * queue initialization handlers
  420. */
  421. bool (*get_entry_state) (struct queue_entry *entry);
  422. void (*clear_entry) (struct queue_entry *entry);
  423. /*
  424. * Radio control handlers.
  425. */
  426. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  427. enum dev_state state);
  428. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  429. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  430. struct link_qual *qual);
  431. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  432. struct link_qual *qual);
  433. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  434. struct link_qual *qual, const u32 count);
  435. /*
  436. * TX control handlers
  437. */
  438. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  439. struct sk_buff *skb,
  440. struct txentry_desc *txdesc);
  441. int (*write_tx_data) (struct queue_entry *entry);
  442. void (*write_beacon) (struct queue_entry *entry);
  443. int (*get_tx_data_len) (struct queue_entry *entry);
  444. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  445. const enum data_queue_qid queue);
  446. /*
  447. * RX control handlers
  448. */
  449. void (*fill_rxdone) (struct queue_entry *entry,
  450. struct rxdone_entry_desc *rxdesc);
  451. /*
  452. * Configuration handlers.
  453. */
  454. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  455. struct rt2x00lib_crypto *crypto,
  456. struct ieee80211_key_conf *key);
  457. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  458. struct rt2x00lib_crypto *crypto,
  459. struct ieee80211_key_conf *key);
  460. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  461. const unsigned int filter_flags);
  462. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  463. struct rt2x00_intf *intf,
  464. struct rt2x00intf_conf *conf,
  465. const unsigned int flags);
  466. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  467. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  468. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  469. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  470. struct rt2x00lib_erp *erp);
  471. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  472. struct antenna_setup *ant);
  473. void (*config) (struct rt2x00_dev *rt2x00dev,
  474. struct rt2x00lib_conf *libconf,
  475. const unsigned int changed_flags);
  476. };
  477. /*
  478. * rt2x00 driver callback operation structure.
  479. */
  480. struct rt2x00_ops {
  481. const char *name;
  482. const unsigned int max_sta_intf;
  483. const unsigned int max_ap_intf;
  484. const unsigned int eeprom_size;
  485. const unsigned int rf_size;
  486. const unsigned int tx_queues;
  487. const struct data_queue_desc *rx;
  488. const struct data_queue_desc *tx;
  489. const struct data_queue_desc *bcn;
  490. const struct data_queue_desc *atim;
  491. const struct rt2x00lib_ops *lib;
  492. const struct ieee80211_ops *hw;
  493. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  494. const struct rt2x00debug *debugfs;
  495. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  496. };
  497. /*
  498. * rt2x00 device flags
  499. */
  500. enum rt2x00_flags {
  501. /*
  502. * Device state flags
  503. */
  504. DEVICE_STATE_PRESENT,
  505. DEVICE_STATE_REGISTERED_HW,
  506. DEVICE_STATE_INITIALIZED,
  507. DEVICE_STATE_STARTED,
  508. DEVICE_STATE_STARTED_SUSPEND,
  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. /*
  520. * Driver features
  521. */
  522. CONFIG_SUPPORT_HW_BUTTON,
  523. CONFIG_SUPPORT_HW_CRYPTO,
  524. /*
  525. * Driver configuration
  526. */
  527. CONFIG_FRAME_TYPE,
  528. CONFIG_RF_SEQUENCE,
  529. CONFIG_EXTERNAL_LNA_A,
  530. CONFIG_EXTERNAL_LNA_BG,
  531. CONFIG_DOUBLE_ANTENNA,
  532. CONFIG_DISABLE_LINK_TUNING,
  533. CONFIG_CRYPTO_COPY_IV,
  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. struct rfkill *rfkill;
  566. struct delayed_work rfkill_work;
  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 u16 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. const u8 *local_address, const u8 *address,
  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 */