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. * 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. /*
  312. * Software sequence counter, this is only required
  313. * for hardware which doesn't support hardware
  314. * sequence counting.
  315. */
  316. spinlock_t seqlock;
  317. u16 seqno;
  318. };
  319. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  320. {
  321. return (struct rt2x00_intf *)vif->drv_priv;
  322. }
  323. /**
  324. * struct hw_mode_spec: Hardware specifications structure
  325. *
  326. * Details about the supported modes, rates and channels
  327. * of a particular chipset. This is used by rt2x00lib
  328. * to build the ieee80211_hw_mode array for mac80211.
  329. *
  330. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  331. * @supported_rates: Rate types which are supported (CCK, OFDM).
  332. * @num_channels: Number of supported channels. This is used as array size
  333. * for @tx_power_a, @tx_power_bg and @channels.
  334. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  335. * @channels_info: Additional information for channels (See &struct channel_info).
  336. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  337. */
  338. struct hw_mode_spec {
  339. unsigned int supported_bands;
  340. #define SUPPORT_BAND_2GHZ 0x00000001
  341. #define SUPPORT_BAND_5GHZ 0x00000002
  342. unsigned int supported_rates;
  343. #define SUPPORT_RATE_CCK 0x00000001
  344. #define SUPPORT_RATE_OFDM 0x00000002
  345. unsigned int num_channels;
  346. const struct rf_channel *channels;
  347. const struct channel_info *channels_info;
  348. struct ieee80211_sta_ht_cap ht;
  349. };
  350. /*
  351. * Configuration structure wrapper around the
  352. * mac80211 configuration structure.
  353. * When mac80211 configures the driver, rt2x00lib
  354. * can precalculate values which are equal for all
  355. * rt2x00 drivers. Those values can be stored in here.
  356. */
  357. struct rt2x00lib_conf {
  358. struct ieee80211_conf *conf;
  359. struct rf_channel rf;
  360. struct channel_info channel;
  361. };
  362. /*
  363. * Configuration structure for erp settings.
  364. */
  365. struct rt2x00lib_erp {
  366. int short_preamble;
  367. int cts_protection;
  368. u32 basic_rates;
  369. int slot_time;
  370. short sifs;
  371. short pifs;
  372. short difs;
  373. short eifs;
  374. u16 beacon_int;
  375. };
  376. /*
  377. * Configuration structure for hardware encryption.
  378. */
  379. struct rt2x00lib_crypto {
  380. enum cipher cipher;
  381. enum set_key_cmd cmd;
  382. const u8 *address;
  383. u32 bssidx;
  384. u32 aid;
  385. u8 key[16];
  386. u8 tx_mic[8];
  387. u8 rx_mic[8];
  388. };
  389. /*
  390. * Configuration structure wrapper around the
  391. * rt2x00 interface configuration handler.
  392. */
  393. struct rt2x00intf_conf {
  394. /*
  395. * Interface type
  396. */
  397. enum nl80211_iftype type;
  398. /*
  399. * TSF sync value, this is dependant on the operation type.
  400. */
  401. enum tsf_sync sync;
  402. /*
  403. * The MAC and BSSID addressess are simple array of bytes,
  404. * these arrays are little endian, so when sending the addressess
  405. * to the drivers, copy the it into a endian-signed variable.
  406. *
  407. * Note that all devices (except rt2500usb) have 32 bits
  408. * register word sizes. This means that whatever variable we
  409. * pass _must_ be a multiple of 32 bits. Otherwise the device
  410. * might not accept what we are sending to it.
  411. * This will also make it easier for the driver to write
  412. * the data to the device.
  413. */
  414. __le32 mac[2];
  415. __le32 bssid[2];
  416. };
  417. /*
  418. * rt2x00lib callback functions.
  419. */
  420. struct rt2x00lib_ops {
  421. /*
  422. * Interrupt handlers.
  423. */
  424. irq_handler_t irq_handler;
  425. /*
  426. * Device init handlers.
  427. */
  428. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  429. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  430. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  431. const u8 *data, const size_t len);
  432. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  433. const u8 *data, const size_t len);
  434. /*
  435. * Device initialization/deinitialization handlers.
  436. */
  437. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  438. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  439. /*
  440. * queue initialization handlers
  441. */
  442. bool (*get_entry_state) (struct queue_entry *entry);
  443. void (*clear_entry) (struct queue_entry *entry);
  444. /*
  445. * Radio control handlers.
  446. */
  447. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  448. enum dev_state state);
  449. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  450. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  451. struct link_qual *qual);
  452. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  453. struct link_qual *qual);
  454. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  455. struct link_qual *qual, const u32 count);
  456. /*
  457. * TX control handlers
  458. */
  459. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  460. struct sk_buff *skb,
  461. struct txentry_desc *txdesc);
  462. int (*write_tx_data) (struct queue_entry *entry);
  463. void (*write_beacon) (struct queue_entry *entry);
  464. int (*get_tx_data_len) (struct queue_entry *entry);
  465. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  466. const enum data_queue_qid queue);
  467. void (*kill_tx_queue) (struct rt2x00_dev *rt2x00dev,
  468. const enum data_queue_qid queue);
  469. /*
  470. * RX control handlers
  471. */
  472. void (*fill_rxdone) (struct queue_entry *entry,
  473. struct rxdone_entry_desc *rxdesc);
  474. /*
  475. * Configuration handlers.
  476. */
  477. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  478. struct rt2x00lib_crypto *crypto,
  479. struct ieee80211_key_conf *key);
  480. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  481. struct rt2x00lib_crypto *crypto,
  482. struct ieee80211_key_conf *key);
  483. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  484. const unsigned int filter_flags);
  485. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  486. struct rt2x00_intf *intf,
  487. struct rt2x00intf_conf *conf,
  488. const unsigned int flags);
  489. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  490. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  491. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  492. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  493. struct rt2x00lib_erp *erp);
  494. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  495. struct antenna_setup *ant);
  496. void (*config) (struct rt2x00_dev *rt2x00dev,
  497. struct rt2x00lib_conf *libconf,
  498. const unsigned int changed_flags);
  499. };
  500. /*
  501. * rt2x00 driver callback operation structure.
  502. */
  503. struct rt2x00_ops {
  504. const char *name;
  505. const unsigned int max_sta_intf;
  506. const unsigned int max_ap_intf;
  507. const unsigned int eeprom_size;
  508. const unsigned int rf_size;
  509. const unsigned int tx_queues;
  510. const struct data_queue_desc *rx;
  511. const struct data_queue_desc *tx;
  512. const struct data_queue_desc *bcn;
  513. const struct data_queue_desc *atim;
  514. const struct rt2x00lib_ops *lib;
  515. const struct ieee80211_ops *hw;
  516. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  517. const struct rt2x00debug *debugfs;
  518. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  519. };
  520. /*
  521. * rt2x00 device flags
  522. */
  523. enum rt2x00_flags {
  524. /*
  525. * Device state flags
  526. */
  527. DEVICE_STATE_PRESENT,
  528. DEVICE_STATE_REGISTERED_HW,
  529. DEVICE_STATE_INITIALIZED,
  530. DEVICE_STATE_STARTED,
  531. DEVICE_STATE_ENABLED_RADIO,
  532. /*
  533. * Driver requirements
  534. */
  535. DRIVER_REQUIRE_FIRMWARE,
  536. DRIVER_REQUIRE_BEACON_GUARD,
  537. DRIVER_REQUIRE_ATIM_QUEUE,
  538. DRIVER_REQUIRE_DMA,
  539. DRIVER_REQUIRE_COPY_IV,
  540. DRIVER_REQUIRE_L2PAD,
  541. /*
  542. * Driver features
  543. */
  544. CONFIG_SUPPORT_HW_BUTTON,
  545. CONFIG_SUPPORT_HW_CRYPTO,
  546. DRIVER_SUPPORT_CONTROL_FILTERS,
  547. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  548. /*
  549. * Driver configuration
  550. */
  551. CONFIG_FRAME_TYPE,
  552. CONFIG_RF_SEQUENCE,
  553. CONFIG_EXTERNAL_LNA_A,
  554. CONFIG_EXTERNAL_LNA_BG,
  555. CONFIG_DOUBLE_ANTENNA,
  556. CONFIG_DISABLE_LINK_TUNING,
  557. CONFIG_CHANNEL_HT40,
  558. };
  559. /*
  560. * rt2x00 device structure.
  561. */
  562. struct rt2x00_dev {
  563. /*
  564. * Device structure.
  565. * The structure stored in here depends on the
  566. * system bus (PCI or USB).
  567. * When accessing this variable, the rt2x00dev_{pci,usb}
  568. * macros should be used for correct typecasting.
  569. */
  570. struct device *dev;
  571. /*
  572. * Callback functions.
  573. */
  574. const struct rt2x00_ops *ops;
  575. /*
  576. * IEEE80211 control structure.
  577. */
  578. struct ieee80211_hw *hw;
  579. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  580. enum ieee80211_band curr_band;
  581. /*
  582. * If enabled, the debugfs interface structures
  583. * required for deregistration of debugfs.
  584. */
  585. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  586. struct rt2x00debug_intf *debugfs_intf;
  587. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  588. /*
  589. * LED structure for changing the LED status
  590. * by mac8011 or the kernel.
  591. */
  592. #ifdef CONFIG_RT2X00_LIB_LEDS
  593. struct rt2x00_led led_radio;
  594. struct rt2x00_led led_assoc;
  595. struct rt2x00_led led_qual;
  596. u16 led_mcu_reg;
  597. #endif /* CONFIG_RT2X00_LIB_LEDS */
  598. /*
  599. * Device flags.
  600. * In these flags the current status and some
  601. * of the device capabilities are stored.
  602. */
  603. unsigned long flags;
  604. /*
  605. * Device information, Bus IRQ and name (PCI, SoC)
  606. */
  607. int irq;
  608. const char *name;
  609. /*
  610. * Chipset identification.
  611. */
  612. struct rt2x00_chip chip;
  613. /*
  614. * hw capability specifications.
  615. */
  616. struct hw_mode_spec spec;
  617. /*
  618. * This is the default TX/RX antenna setup as indicated
  619. * by the device's EEPROM.
  620. */
  621. struct antenna_setup default_ant;
  622. /*
  623. * Register pointers
  624. * csr.base: CSR base register address. (PCI)
  625. * csr.cache: CSR cache for usb_control_msg. (USB)
  626. */
  627. union csr {
  628. void __iomem *base;
  629. void *cache;
  630. } csr;
  631. /*
  632. * Mutex to protect register accesses.
  633. * For PCI and USB devices it protects against concurrent indirect
  634. * register access (BBP, RF, MCU) since accessing those
  635. * registers require multiple calls to the CSR registers.
  636. * For USB devices it also protects the csr_cache since that
  637. * field is used for normal CSR access and it cannot support
  638. * multiple callers simultaneously.
  639. */
  640. struct mutex csr_mutex;
  641. /*
  642. * Current packet filter configuration for the device.
  643. * This contains all currently active FIF_* flags send
  644. * to us by mac80211 during configure_filter().
  645. */
  646. unsigned int packet_filter;
  647. /*
  648. * Interface details:
  649. * - Open ap interface count.
  650. * - Open sta interface count.
  651. * - Association count.
  652. */
  653. unsigned int intf_ap_count;
  654. unsigned int intf_sta_count;
  655. unsigned int intf_associated;
  656. /*
  657. * Link quality
  658. */
  659. struct link link;
  660. /*
  661. * EEPROM data.
  662. */
  663. __le16 *eeprom;
  664. /*
  665. * Active RF register values.
  666. * These are stored here so we don't need
  667. * to read the rf registers and can directly
  668. * use this value instead.
  669. * This field should be accessed by using
  670. * rt2x00_rf_read() and rt2x00_rf_write().
  671. */
  672. u32 *rf;
  673. /*
  674. * LNA gain
  675. */
  676. short lna_gain;
  677. /*
  678. * Current TX power value.
  679. */
  680. u16 tx_power;
  681. /*
  682. * Current retry values.
  683. */
  684. u8 short_retry;
  685. u8 long_retry;
  686. /*
  687. * Rssi <-> Dbm offset
  688. */
  689. u8 rssi_offset;
  690. /*
  691. * Frequency offset (for rt61pci & rt73usb).
  692. */
  693. u8 freq_offset;
  694. /*
  695. * Calibration information (for rt2800usb & rt2800pci).
  696. * [0] -> BW20
  697. * [1] -> BW40
  698. */
  699. u8 calibration[2];
  700. /*
  701. * Beacon interval.
  702. */
  703. u16 beacon_int;
  704. /*
  705. * Low level statistics which will have
  706. * to be kept up to date while device is running.
  707. */
  708. struct ieee80211_low_level_stats low_level_stats;
  709. /*
  710. * RX configuration information.
  711. */
  712. struct ieee80211_rx_status rx_status;
  713. /*
  714. * Scheduled work.
  715. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  716. * which means it cannot be placed on the hw->workqueue
  717. * due to RTNL locking requirements.
  718. */
  719. struct work_struct intf_work;
  720. /*
  721. * Data queue arrays for RX, TX and Beacon.
  722. * The Beacon array also contains the Atim queue
  723. * if that is supported by the device.
  724. */
  725. unsigned int data_queues;
  726. struct data_queue *rx;
  727. struct data_queue *tx;
  728. struct data_queue *bcn;
  729. /*
  730. * Firmware image.
  731. */
  732. const struct firmware *fw;
  733. };
  734. /*
  735. * Generic RF access.
  736. * The RF is being accessed by word index.
  737. */
  738. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  739. const unsigned int word, u32 *data)
  740. {
  741. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  742. *data = rt2x00dev->rf[word - 1];
  743. }
  744. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  745. const unsigned int word, u32 data)
  746. {
  747. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  748. rt2x00dev->rf[word - 1] = data;
  749. }
  750. /*
  751. * Generic EEPROM access.
  752. * The EEPROM is being accessed by word index.
  753. */
  754. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  755. const unsigned int word)
  756. {
  757. return (void *)&rt2x00dev->eeprom[word];
  758. }
  759. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  760. const unsigned int word, u16 *data)
  761. {
  762. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  763. }
  764. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  765. const unsigned int word, u16 data)
  766. {
  767. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  768. }
  769. /*
  770. * Chipset handlers
  771. */
  772. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  773. const u16 rt, const u16 rf, const u32 rev)
  774. {
  775. INFO(rt2x00dev,
  776. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  777. rt, rf, rev);
  778. rt2x00dev->chip.rt = rt;
  779. rt2x00dev->chip.rf = rf;
  780. rt2x00dev->chip.rev = rev;
  781. }
  782. static inline void rt2x00_set_chip_rt(struct rt2x00_dev *rt2x00dev,
  783. const u16 rt)
  784. {
  785. rt2x00dev->chip.rt = rt;
  786. }
  787. static inline void rt2x00_set_chip_rf(struct rt2x00_dev *rt2x00dev,
  788. const u16 rf, const u32 rev)
  789. {
  790. rt2x00_set_chip(rt2x00dev, rt2x00dev->chip.rt, rf, rev);
  791. }
  792. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  793. {
  794. return (chipset->rt == chip);
  795. }
  796. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  797. {
  798. return (chipset->rf == chip);
  799. }
  800. static inline u32 rt2x00_rev(const struct rt2x00_chip *chipset)
  801. {
  802. return chipset->rev;
  803. }
  804. static inline bool rt2x00_check_rev(const struct rt2x00_chip *chipset,
  805. const u32 mask, const u32 rev)
  806. {
  807. return ((chipset->rev & mask) == rev);
  808. }
  809. /**
  810. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  811. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  812. * @skb: The skb to map.
  813. */
  814. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  815. /**
  816. * rt2x00queue_get_queue - Convert queue index to queue pointer
  817. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  818. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  819. */
  820. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  821. const enum data_queue_qid queue);
  822. /**
  823. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  824. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  825. * @index: Index identifier for obtaining the correct index.
  826. */
  827. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  828. enum queue_index index);
  829. /*
  830. * Interrupt context handlers.
  831. */
  832. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  833. void rt2x00lib_txdone(struct queue_entry *entry,
  834. struct txdone_entry_desc *txdesc);
  835. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  836. struct queue_entry *entry);
  837. /*
  838. * mac80211 handlers.
  839. */
  840. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  841. int rt2x00mac_start(struct ieee80211_hw *hw);
  842. void rt2x00mac_stop(struct ieee80211_hw *hw);
  843. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  844. struct ieee80211_if_init_conf *conf);
  845. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  846. struct ieee80211_if_init_conf *conf);
  847. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  848. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  849. unsigned int changed_flags,
  850. unsigned int *total_flags,
  851. u64 multicast);
  852. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  853. bool set);
  854. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  855. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  856. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  857. struct ieee80211_key_conf *key);
  858. #else
  859. #define rt2x00mac_set_key NULL
  860. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  861. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  862. struct ieee80211_low_level_stats *stats);
  863. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  864. struct ieee80211_tx_queue_stats *stats);
  865. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  866. struct ieee80211_vif *vif,
  867. struct ieee80211_bss_conf *bss_conf,
  868. u32 changes);
  869. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  870. const struct ieee80211_tx_queue_params *params);
  871. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  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 */