rt2x00.h 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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 antenna's.
  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. DEVICE_STATE_DISABLED_RADIO_HW,
  526. /*
  527. * Driver requirements
  528. */
  529. DRIVER_REQUIRE_FIRMWARE,
  530. DRIVER_REQUIRE_BEACON_GUARD,
  531. DRIVER_REQUIRE_ATIM_QUEUE,
  532. DRIVER_REQUIRE_SCHEDULED,
  533. DRIVER_REQUIRE_DMA,
  534. DRIVER_REQUIRE_COPY_IV,
  535. DRIVER_REQUIRE_L2PAD,
  536. /*
  537. * Driver features
  538. */
  539. CONFIG_SUPPORT_HW_BUTTON,
  540. CONFIG_SUPPORT_HW_CRYPTO,
  541. /*
  542. * Driver configuration
  543. */
  544. CONFIG_FRAME_TYPE,
  545. CONFIG_RF_SEQUENCE,
  546. CONFIG_EXTERNAL_LNA_A,
  547. CONFIG_EXTERNAL_LNA_BG,
  548. CONFIG_DOUBLE_ANTENNA,
  549. CONFIG_DISABLE_LINK_TUNING,
  550. CONFIG_CHANNEL_HT40,
  551. };
  552. /*
  553. * rt2x00 device structure.
  554. */
  555. struct rt2x00_dev {
  556. /*
  557. * Device structure.
  558. * The structure stored in here depends on the
  559. * system bus (PCI or USB).
  560. * When accessing this variable, the rt2x00dev_{pci,usb}
  561. * macro's should be used for correct typecasting.
  562. */
  563. struct device *dev;
  564. /*
  565. * Callback functions.
  566. */
  567. const struct rt2x00_ops *ops;
  568. /*
  569. * IEEE80211 control structure.
  570. */
  571. struct ieee80211_hw *hw;
  572. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  573. enum ieee80211_band curr_band;
  574. /*
  575. * rfkill structure for RF state switching support.
  576. * This will only be compiled in when required.
  577. */
  578. #ifdef CONFIG_RT2X00_LIB_RFKILL
  579. unsigned long rfkill_state;
  580. #define RFKILL_STATE_ALLOCATED 1
  581. #define RFKILL_STATE_REGISTERED 2
  582. #define RFKILL_STATE_BLOCKED 3
  583. struct input_polled_dev *rfkill_poll_dev;
  584. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  585. /*
  586. * If enabled, the debugfs interface structures
  587. * required for deregistration of debugfs.
  588. */
  589. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  590. struct rt2x00debug_intf *debugfs_intf;
  591. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  592. /*
  593. * LED structure for changing the LED status
  594. * by mac8011 or the kernel.
  595. */
  596. #ifdef CONFIG_RT2X00_LIB_LEDS
  597. struct rt2x00_led led_radio;
  598. struct rt2x00_led led_assoc;
  599. struct rt2x00_led led_qual;
  600. u16 led_mcu_reg;
  601. #endif /* CONFIG_RT2X00_LIB_LEDS */
  602. /*
  603. * Device flags.
  604. * In these flags the current status and some
  605. * of the device capabilities are stored.
  606. */
  607. unsigned long flags;
  608. /*
  609. * Device information, Bus IRQ and name (PCI, SoC)
  610. */
  611. int irq;
  612. const char *name;
  613. /*
  614. * Chipset identification.
  615. */
  616. struct rt2x00_chip chip;
  617. /*
  618. * hw capability specifications.
  619. */
  620. struct hw_mode_spec spec;
  621. /*
  622. * This is the default TX/RX antenna setup as indicated
  623. * by the device's EEPROM.
  624. */
  625. struct antenna_setup default_ant;
  626. /*
  627. * Register pointers
  628. * csr.base: CSR base register address. (PCI)
  629. * csr.cache: CSR cache for usb_control_msg. (USB)
  630. */
  631. union csr {
  632. void __iomem *base;
  633. void *cache;
  634. } csr;
  635. /*
  636. * Mutex to protect register accesses.
  637. * For PCI and USB devices it protects against concurrent indirect
  638. * register access (BBP, RF, MCU) since accessing those
  639. * registers require multiple calls to the CSR registers.
  640. * For USB devices it also protects the csr_cache since that
  641. * field is used for normal CSR access and it cannot support
  642. * multiple callers simultaneously.
  643. */
  644. struct mutex csr_mutex;
  645. /*
  646. * Current packet filter configuration for the device.
  647. * This contains all currently active FIF_* flags send
  648. * to us by mac80211 during configure_filter().
  649. */
  650. unsigned int packet_filter;
  651. /*
  652. * Interface details:
  653. * - Open ap interface count.
  654. * - Open sta interface count.
  655. * - Association count.
  656. */
  657. unsigned int intf_ap_count;
  658. unsigned int intf_sta_count;
  659. unsigned int intf_associated;
  660. /*
  661. * Link quality
  662. */
  663. struct link link;
  664. /*
  665. * EEPROM data.
  666. */
  667. __le16 *eeprom;
  668. /*
  669. * Active RF register values.
  670. * These are stored here so we don't need
  671. * to read the rf registers and can directly
  672. * use this value instead.
  673. * This field should be accessed by using
  674. * rt2x00_rf_read() and rt2x00_rf_write().
  675. */
  676. u32 *rf;
  677. /*
  678. * LNA gain
  679. */
  680. short lna_gain;
  681. /*
  682. * Current TX power value.
  683. */
  684. u16 tx_power;
  685. /*
  686. * Current retry values.
  687. */
  688. u8 short_retry;
  689. u8 long_retry;
  690. /*
  691. * Rssi <-> Dbm offset
  692. */
  693. u8 rssi_offset;
  694. /*
  695. * Frequency offset (for rt61pci & rt73usb).
  696. */
  697. u8 freq_offset;
  698. /*
  699. * Calibration information (for rt2800usb & rt2800pci).
  700. * [0] -> BW20
  701. * [1] -> BW40
  702. */
  703. u8 calibration[2];
  704. /*
  705. * Beacon interval.
  706. */
  707. u16 beacon_int;
  708. /*
  709. * Low level statistics which will have
  710. * to be kept up to date while device is running.
  711. */
  712. struct ieee80211_low_level_stats low_level_stats;
  713. /*
  714. * RX configuration information.
  715. */
  716. struct ieee80211_rx_status rx_status;
  717. /*
  718. * Scheduled work.
  719. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  720. * which means it cannot be placed on the hw->workqueue
  721. * due to RTNL locking requirements.
  722. */
  723. struct work_struct intf_work;
  724. struct work_struct filter_work;
  725. /*
  726. * Data queue arrays for RX, TX and Beacon.
  727. * The Beacon array also contains the Atim queue
  728. * if that is supported by the device.
  729. */
  730. unsigned int data_queues;
  731. struct data_queue *rx;
  732. struct data_queue *tx;
  733. struct data_queue *bcn;
  734. /*
  735. * Firmware image.
  736. */
  737. const struct firmware *fw;
  738. };
  739. /*
  740. * Generic RF access.
  741. * The RF is being accessed by word index.
  742. */
  743. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  744. const unsigned int word, u32 *data)
  745. {
  746. *data = rt2x00dev->rf[word];
  747. }
  748. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  749. const unsigned int word, u32 data)
  750. {
  751. rt2x00dev->rf[word] = data;
  752. }
  753. /*
  754. * Generic EEPROM access.
  755. * The EEPROM is being accessed by word index.
  756. */
  757. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  758. const unsigned int word)
  759. {
  760. return (void *)&rt2x00dev->eeprom[word];
  761. }
  762. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  763. const unsigned int word, u16 *data)
  764. {
  765. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  766. }
  767. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  768. const unsigned int word, u16 data)
  769. {
  770. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  771. }
  772. /*
  773. * Chipset handlers
  774. */
  775. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  776. const u16 rt, const u16 rf, const u32 rev)
  777. {
  778. INFO(rt2x00dev,
  779. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  780. rt, rf, rev);
  781. rt2x00dev->chip.rt = rt;
  782. rt2x00dev->chip.rf = rf;
  783. rt2x00dev->chip.rev = rev;
  784. }
  785. static inline void rt2x00_set_chip_rt(struct rt2x00_dev *rt2x00dev,
  786. const u16 rt)
  787. {
  788. rt2x00dev->chip.rt = rt;
  789. }
  790. static inline void rt2x00_set_chip_rf(struct rt2x00_dev *rt2x00dev,
  791. const u16 rf, const u32 rev)
  792. {
  793. rt2x00_set_chip(rt2x00dev, rt2x00dev->chip.rt, rf, rev);
  794. }
  795. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  796. {
  797. return (chipset->rt == chip);
  798. }
  799. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  800. {
  801. return (chipset->rf == chip);
  802. }
  803. static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)
  804. {
  805. return chipset->rev;
  806. }
  807. static inline bool rt2x00_check_rev(const struct rt2x00_chip *chipset,
  808. const u32 mask, const u32 rev)
  809. {
  810. return ((chipset->rev & mask) == rev);
  811. }
  812. /**
  813. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  814. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  815. * @skb: The skb to map.
  816. */
  817. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  818. /**
  819. * rt2x00queue_get_queue - Convert queue index to queue pointer
  820. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  821. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  822. */
  823. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  824. const enum data_queue_qid queue);
  825. /**
  826. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  827. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  828. * @index: Index identifier for obtaining the correct index.
  829. */
  830. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  831. enum queue_index index);
  832. /*
  833. * Interrupt context handlers.
  834. */
  835. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  836. void rt2x00lib_txdone(struct queue_entry *entry,
  837. struct txdone_entry_desc *txdesc);
  838. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  839. struct queue_entry *entry);
  840. /*
  841. * mac80211 handlers.
  842. */
  843. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  844. int rt2x00mac_start(struct ieee80211_hw *hw);
  845. void rt2x00mac_stop(struct ieee80211_hw *hw);
  846. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  847. struct ieee80211_if_init_conf *conf);
  848. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  849. struct ieee80211_if_init_conf *conf);
  850. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  851. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  852. unsigned int changed_flags,
  853. unsigned int *total_flags,
  854. int mc_count, struct dev_addr_list *mc_list);
  855. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  856. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  857. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  858. struct ieee80211_key_conf *key);
  859. #else
  860. #define rt2x00mac_set_key NULL
  861. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  862. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  863. struct ieee80211_low_level_stats *stats);
  864. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  865. struct ieee80211_tx_queue_stats *stats);
  866. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  867. struct ieee80211_vif *vif,
  868. struct ieee80211_bss_conf *bss_conf,
  869. u32 changes);
  870. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  871. const struct ieee80211_tx_queue_params *params);
  872. /*
  873. * Driver allocation handlers.
  874. */
  875. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  876. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  877. #ifdef CONFIG_PM
  878. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  879. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  880. #endif /* CONFIG_PM */
  881. #endif /* RT2X00_H */