rt2x00.h 25 KB

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