rt2x00.h 25 KB

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