rt2x00.h 25 KB

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