rt2x00.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  3. Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  4. <http://rt2x00.serialmonkey.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the
  15. Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. /*
  19. Module: rt2x00
  20. Abstract: rt2x00 global information.
  21. */
  22. #ifndef RT2X00_H
  23. #define RT2X00_H
  24. #include <linux/bitops.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/firmware.h>
  28. #include <linux/leds.h>
  29. #include <linux/mutex.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/input-polldev.h>
  32. #include <net/mac80211.h>
  33. #include "rt2x00debug.h"
  34. #include "rt2x00dump.h"
  35. #include "rt2x00leds.h"
  36. #include "rt2x00reg.h"
  37. #include "rt2x00queue.h"
  38. /*
  39. * Module information.
  40. */
  41. #define DRV_VERSION "2.3.0"
  42. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  43. /*
  44. * Debug definitions.
  45. * Debug output has to be enabled during compile time.
  46. */
  47. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  48. printk(__kernlvl "%s -> %s: %s - " __msg, \
  49. wiphy_name((__dev)->hw->wiphy), __func__, __lvl, ##__args)
  50. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  51. printk(__kernlvl "%s -> %s: %s - " __msg, \
  52. KBUILD_MODNAME, __func__, __lvl, ##__args)
  53. #ifdef CONFIG_RT2X00_DEBUG
  54. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  55. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
  56. #else
  57. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  58. do { } while (0)
  59. #endif /* CONFIG_RT2X00_DEBUG */
  60. /*
  61. * Various debug levels.
  62. * The debug levels PANIC and ERROR both indicate serious problems,
  63. * for this reason they should never be ignored.
  64. * The special ERROR_PROBE message is for messages that are generated
  65. * when the rt2x00_dev is not yet initialized.
  66. */
  67. #define PANIC(__dev, __msg, __args...) \
  68. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  69. #define ERROR(__dev, __msg, __args...) \
  70. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  71. #define ERROR_PROBE(__msg, __args...) \
  72. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  73. #define WARNING(__dev, __msg, __args...) \
  74. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  75. #define NOTICE(__dev, __msg, __args...) \
  76. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  77. #define INFO(__dev, __msg, __args...) \
  78. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  79. #define DEBUG(__dev, __msg, __args...) \
  80. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  81. #define EEPROM(__dev, __msg, __args...) \
  82. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  83. /*
  84. * Duration calculations
  85. * The rate variable passed is: 100kbs.
  86. * To convert from bytes to bits we multiply size with 8,
  87. * then the size is multiplied with 10 to make the
  88. * real rate -> rate argument correction.
  89. */
  90. #define GET_DURATION(__size, __rate) (((__size) * 8 * 10) / (__rate))
  91. #define GET_DURATION_RES(__size, __rate)(((__size) * 8 * 10) % (__rate))
  92. /*
  93. * Determine the number of L2 padding bytes required between the header and
  94. * the payload.
  95. */
  96. #define L2PAD_SIZE(__hdrlen) (-(__hdrlen) & 3)
  97. /*
  98. * Determine the alignment requirement,
  99. * to make sure the 802.11 payload is padded to a 4-byte boundrary
  100. * we must determine the address of the payload and calculate the
  101. * amount of bytes needed to move the data.
  102. */
  103. #define ALIGN_SIZE(__skb, __header) \
  104. ( ((unsigned long)((__skb)->data + (__header))) & 3 )
  105. /*
  106. * Constants for extra TX headroom for alignment purposes.
  107. */
  108. #define RT2X00_ALIGN_SIZE 4 /* Only whole frame needs alignment */
  109. #define RT2X00_L2PAD_SIZE 8 /* Both header & payload need alignment */
  110. /*
  111. * Standard timing and size defines.
  112. * These values should follow the ieee80211 specifications.
  113. */
  114. #define ACK_SIZE 14
  115. #define IEEE80211_HEADER 24
  116. #define PLCP 48
  117. #define BEACON 100
  118. #define PREAMBLE 144
  119. #define SHORT_PREAMBLE 72
  120. #define SLOT_TIME 20
  121. #define SHORT_SLOT_TIME 9
  122. #define SIFS 10
  123. #define PIFS ( SIFS + SLOT_TIME )
  124. #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
  125. #define DIFS ( PIFS + SLOT_TIME )
  126. #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
  127. #define EIFS ( SIFS + DIFS + \
  128. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
  129. #define SHORT_EIFS ( SIFS + SHORT_DIFS + \
  130. GET_DURATION(IEEE80211_HEADER + ACK_SIZE, 10) )
  131. /*
  132. * Structure for average calculation
  133. * The avg field contains the actual average value,
  134. * but avg_weight is internally used during calculations
  135. * to prevent rounding errors.
  136. */
  137. struct avg_val {
  138. int avg;
  139. int avg_weight;
  140. };
  141. enum rt2x00_chip_intf {
  142. RT2X00_CHIP_INTF_PCI,
  143. RT2X00_CHIP_INTF_USB,
  144. RT2X00_CHIP_INTF_SOC,
  145. };
  146. /*
  147. * Chipset identification
  148. * The chipset on the device is composed of a RT and RF chip.
  149. * The chipset combination is important for determining device capabilities.
  150. */
  151. struct rt2x00_chip {
  152. u16 rt;
  153. #define RT2460 0x2460
  154. #define RT2560 0x2560
  155. #define RT2570 0x2570
  156. #define RT2661 0x2661
  157. #define RT2573 0x2573
  158. #define RT2860 0x2860 /* 2.4GHz */
  159. #define RT2872 0x2872 /* WSOC */
  160. #define RT2883 0x2883 /* WSOC */
  161. #define RT3070 0x3070
  162. #define RT3071 0x3071
  163. #define RT3090 0x3090 /* 2.4GHz PCIe */
  164. #define RT3390 0x3390
  165. #define RT3572 0x3572
  166. #define RT3593 0x3593 /* PCIe */
  167. #define RT3883 0x3883 /* WSOC */
  168. u16 rf;
  169. u16 rev;
  170. enum rt2x00_chip_intf intf;
  171. };
  172. /*
  173. * RF register values that belong to a particular channel.
  174. */
  175. struct rf_channel {
  176. int channel;
  177. u32 rf1;
  178. u32 rf2;
  179. u32 rf3;
  180. u32 rf4;
  181. };
  182. /*
  183. * Channel information structure
  184. */
  185. struct channel_info {
  186. unsigned int flags;
  187. #define GEOGRAPHY_ALLOWED 0x00000001
  188. short tx_power1;
  189. short tx_power2;
  190. };
  191. /*
  192. * Antenna setup values.
  193. */
  194. struct antenna_setup {
  195. enum antenna rx;
  196. enum antenna tx;
  197. };
  198. /*
  199. * Quality statistics about the currently active link.
  200. */
  201. struct link_qual {
  202. /*
  203. * Statistics required for Link tuning by driver
  204. * The rssi value is provided by rt2x00lib during the
  205. * link_tuner() callback function.
  206. * The false_cca field is filled during the link_stats()
  207. * callback function and could be used during the
  208. * link_tuner() callback function.
  209. */
  210. int rssi;
  211. int false_cca;
  212. /*
  213. * VGC levels
  214. * Hardware driver will tune the VGC level during each call
  215. * to the link_tuner() callback function. This vgc_level is
  216. * is determined based on the link quality statistics like
  217. * average RSSI and the false CCA count.
  218. *
  219. * In some cases the drivers need to differentiate between
  220. * the currently "desired" VGC level and the level configured
  221. * in the hardware. The latter is important to reduce the
  222. * number of BBP register reads to reduce register access
  223. * overhead. For this reason we store both values here.
  224. */
  225. u8 vgc_level;
  226. u8 vgc_level_reg;
  227. /*
  228. * Statistics required for Signal quality calculation.
  229. * These fields might be changed during the link_stats()
  230. * callback function.
  231. */
  232. int rx_success;
  233. int rx_failed;
  234. int tx_success;
  235. int tx_failed;
  236. };
  237. /*
  238. * Antenna settings about the currently active link.
  239. */
  240. struct link_ant {
  241. /*
  242. * Antenna flags
  243. */
  244. unsigned int flags;
  245. #define ANTENNA_RX_DIVERSITY 0x00000001
  246. #define ANTENNA_TX_DIVERSITY 0x00000002
  247. #define ANTENNA_MODE_SAMPLE 0x00000004
  248. /*
  249. * Currently active TX/RX antenna setup.
  250. * When software diversity is used, this will indicate
  251. * which antenna is actually used at this time.
  252. */
  253. struct antenna_setup active;
  254. /*
  255. * RSSI history information for the antenna.
  256. * Used to determine when to switch antenna
  257. * when using software diversity.
  258. */
  259. int rssi_history;
  260. /*
  261. * Current RSSI average of the currently active antenna.
  262. * Similar to the avg_rssi in the link_qual structure
  263. * this value is updated by using the walking average.
  264. */
  265. struct avg_val rssi_ant;
  266. };
  267. /*
  268. * To optimize the quality of the link we need to store
  269. * the quality of received frames and periodically
  270. * optimize the link.
  271. */
  272. struct link {
  273. /*
  274. * Link tuner counter
  275. * The number of times the link has been tuned
  276. * since the radio has been switched on.
  277. */
  278. u32 count;
  279. /*
  280. * Quality measurement values.
  281. */
  282. struct link_qual qual;
  283. /*
  284. * TX/RX antenna setup.
  285. */
  286. struct link_ant ant;
  287. /*
  288. * Currently active average RSSI value
  289. */
  290. struct avg_val avg_rssi;
  291. /*
  292. * Work structure for scheduling periodic link tuning.
  293. */
  294. struct delayed_work work;
  295. };
  296. /*
  297. * Interface structure
  298. * Per interface configuration details, this structure
  299. * is allocated as the private data for ieee80211_vif.
  300. */
  301. struct rt2x00_intf {
  302. /*
  303. * All fields within the rt2x00_intf structure
  304. * must be protected with a spinlock.
  305. */
  306. spinlock_t lock;
  307. /*
  308. * MAC of the device.
  309. */
  310. u8 mac[ETH_ALEN];
  311. /*
  312. * BBSID of the AP to associate with.
  313. */
  314. u8 bssid[ETH_ALEN];
  315. /*
  316. * beacon->skb must be protected with the mutex.
  317. */
  318. struct mutex beacon_skb_mutex;
  319. /*
  320. * Entry in the beacon queue which belongs to
  321. * this interface. Each interface has its own
  322. * dedicated beacon entry.
  323. */
  324. struct queue_entry *beacon;
  325. /*
  326. * Actions that needed rescheduling.
  327. */
  328. unsigned int delayed_flags;
  329. #define DELAYED_UPDATE_BEACON 0x00000001
  330. /*
  331. * Software sequence counter, this is only required
  332. * for hardware which doesn't support hardware
  333. * sequence counting.
  334. */
  335. spinlock_t seqlock;
  336. u16 seqno;
  337. };
  338. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  339. {
  340. return (struct rt2x00_intf *)vif->drv_priv;
  341. }
  342. /**
  343. * struct hw_mode_spec: Hardware specifications structure
  344. *
  345. * Details about the supported modes, rates and channels
  346. * of a particular chipset. This is used by rt2x00lib
  347. * to build the ieee80211_hw_mode array for mac80211.
  348. *
  349. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  350. * @supported_rates: Rate types which are supported (CCK, OFDM).
  351. * @num_channels: Number of supported channels. This is used as array size
  352. * for @tx_power_a, @tx_power_bg and @channels.
  353. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  354. * @channels_info: Additional information for channels (See &struct channel_info).
  355. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  356. */
  357. struct hw_mode_spec {
  358. unsigned int supported_bands;
  359. #define SUPPORT_BAND_2GHZ 0x00000001
  360. #define SUPPORT_BAND_5GHZ 0x00000002
  361. unsigned int supported_rates;
  362. #define SUPPORT_RATE_CCK 0x00000001
  363. #define SUPPORT_RATE_OFDM 0x00000002
  364. unsigned int num_channels;
  365. const struct rf_channel *channels;
  366. const struct channel_info *channels_info;
  367. struct ieee80211_sta_ht_cap ht;
  368. };
  369. /*
  370. * Configuration structure wrapper around the
  371. * mac80211 configuration structure.
  372. * When mac80211 configures the driver, rt2x00lib
  373. * can precalculate values which are equal for all
  374. * rt2x00 drivers. Those values can be stored in here.
  375. */
  376. struct rt2x00lib_conf {
  377. struct ieee80211_conf *conf;
  378. struct rf_channel rf;
  379. struct channel_info channel;
  380. };
  381. /*
  382. * Configuration structure for erp settings.
  383. */
  384. struct rt2x00lib_erp {
  385. int short_preamble;
  386. int cts_protection;
  387. u32 basic_rates;
  388. int slot_time;
  389. short sifs;
  390. short pifs;
  391. short difs;
  392. short eifs;
  393. u16 beacon_int;
  394. };
  395. /*
  396. * Configuration structure for hardware encryption.
  397. */
  398. struct rt2x00lib_crypto {
  399. enum cipher cipher;
  400. enum set_key_cmd cmd;
  401. const u8 *address;
  402. u32 bssidx;
  403. u32 aid;
  404. u8 key[16];
  405. u8 tx_mic[8];
  406. u8 rx_mic[8];
  407. };
  408. /*
  409. * Configuration structure wrapper around the
  410. * rt2x00 interface configuration handler.
  411. */
  412. struct rt2x00intf_conf {
  413. /*
  414. * Interface type
  415. */
  416. enum nl80211_iftype type;
  417. /*
  418. * TSF sync value, this is dependant on the operation type.
  419. */
  420. enum tsf_sync sync;
  421. /*
  422. * The MAC and BSSID addressess are simple array of bytes,
  423. * these arrays are little endian, so when sending the addressess
  424. * to the drivers, copy the it into a endian-signed variable.
  425. *
  426. * Note that all devices (except rt2500usb) have 32 bits
  427. * register word sizes. This means that whatever variable we
  428. * pass _must_ be a multiple of 32 bits. Otherwise the device
  429. * might not accept what we are sending to it.
  430. * This will also make it easier for the driver to write
  431. * the data to the device.
  432. */
  433. __le32 mac[2];
  434. __le32 bssid[2];
  435. };
  436. /*
  437. * rt2x00lib callback functions.
  438. */
  439. struct rt2x00lib_ops {
  440. /*
  441. * Interrupt handlers.
  442. */
  443. irq_handler_t irq_handler;
  444. /*
  445. * Device init handlers.
  446. */
  447. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  448. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  449. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  450. const u8 *data, const size_t len);
  451. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  452. const u8 *data, const size_t len);
  453. /*
  454. * Device initialization/deinitialization handlers.
  455. */
  456. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  457. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  458. /*
  459. * queue initialization handlers
  460. */
  461. bool (*get_entry_state) (struct queue_entry *entry);
  462. void (*clear_entry) (struct queue_entry *entry);
  463. /*
  464. * Radio control handlers.
  465. */
  466. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  467. enum dev_state state);
  468. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  469. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  470. struct link_qual *qual);
  471. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  472. struct link_qual *qual);
  473. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  474. struct link_qual *qual, const u32 count);
  475. /*
  476. * TX control handlers
  477. */
  478. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  479. struct sk_buff *skb,
  480. struct txentry_desc *txdesc);
  481. int (*write_tx_data) (struct queue_entry *entry,
  482. struct txentry_desc *txdesc);
  483. void (*write_tx_datadesc) (struct queue_entry *entry,
  484. struct txentry_desc *txdesc);
  485. void (*write_beacon) (struct queue_entry *entry,
  486. struct txentry_desc *txdesc);
  487. int (*get_tx_data_len) (struct queue_entry *entry);
  488. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  489. const enum data_queue_qid queue);
  490. void (*kill_tx_queue) (struct rt2x00_dev *rt2x00dev,
  491. const enum data_queue_qid queue);
  492. /*
  493. * RX control handlers
  494. */
  495. void (*fill_rxdone) (struct queue_entry *entry,
  496. struct rxdone_entry_desc *rxdesc);
  497. /*
  498. * Configuration handlers.
  499. */
  500. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  501. struct rt2x00lib_crypto *crypto,
  502. struct ieee80211_key_conf *key);
  503. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  504. struct rt2x00lib_crypto *crypto,
  505. struct ieee80211_key_conf *key);
  506. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  507. const unsigned int filter_flags);
  508. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  509. struct rt2x00_intf *intf,
  510. struct rt2x00intf_conf *conf,
  511. const unsigned int flags);
  512. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  513. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  514. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  515. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  516. struct rt2x00lib_erp *erp);
  517. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  518. struct antenna_setup *ant);
  519. void (*config) (struct rt2x00_dev *rt2x00dev,
  520. struct rt2x00lib_conf *libconf,
  521. const unsigned int changed_flags);
  522. };
  523. /*
  524. * rt2x00 driver callback operation structure.
  525. */
  526. struct rt2x00_ops {
  527. const char *name;
  528. const unsigned int max_sta_intf;
  529. const unsigned int max_ap_intf;
  530. const unsigned int eeprom_size;
  531. const unsigned int rf_size;
  532. const unsigned int tx_queues;
  533. const unsigned int extra_tx_headroom;
  534. const struct data_queue_desc *rx;
  535. const struct data_queue_desc *tx;
  536. const struct data_queue_desc *bcn;
  537. const struct data_queue_desc *atim;
  538. const struct rt2x00lib_ops *lib;
  539. const struct ieee80211_ops *hw;
  540. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  541. const struct rt2x00debug *debugfs;
  542. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  543. };
  544. /*
  545. * rt2x00 device flags
  546. */
  547. enum rt2x00_flags {
  548. /*
  549. * Device state flags
  550. */
  551. DEVICE_STATE_PRESENT,
  552. DEVICE_STATE_REGISTERED_HW,
  553. DEVICE_STATE_INITIALIZED,
  554. DEVICE_STATE_STARTED,
  555. DEVICE_STATE_ENABLED_RADIO,
  556. /*
  557. * Driver requirements
  558. */
  559. DRIVER_REQUIRE_FIRMWARE,
  560. DRIVER_REQUIRE_BEACON_GUARD,
  561. DRIVER_REQUIRE_ATIM_QUEUE,
  562. DRIVER_REQUIRE_DMA,
  563. DRIVER_REQUIRE_COPY_IV,
  564. DRIVER_REQUIRE_L2PAD,
  565. /*
  566. * Driver features
  567. */
  568. CONFIG_SUPPORT_HW_BUTTON,
  569. CONFIG_SUPPORT_HW_CRYPTO,
  570. DRIVER_SUPPORT_CONTROL_FILTERS,
  571. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  572. /*
  573. * Driver configuration
  574. */
  575. CONFIG_FRAME_TYPE,
  576. CONFIG_RF_SEQUENCE,
  577. CONFIG_EXTERNAL_LNA_A,
  578. CONFIG_EXTERNAL_LNA_BG,
  579. CONFIG_DOUBLE_ANTENNA,
  580. CONFIG_DISABLE_LINK_TUNING,
  581. CONFIG_CHANNEL_HT40,
  582. };
  583. /*
  584. * rt2x00 device structure.
  585. */
  586. struct rt2x00_dev {
  587. /*
  588. * Device structure.
  589. * The structure stored in here depends on the
  590. * system bus (PCI or USB).
  591. * When accessing this variable, the rt2x00dev_{pci,usb}
  592. * macros should be used for correct typecasting.
  593. */
  594. struct device *dev;
  595. /*
  596. * Callback functions.
  597. */
  598. const struct rt2x00_ops *ops;
  599. /*
  600. * IEEE80211 control structure.
  601. */
  602. struct ieee80211_hw *hw;
  603. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  604. enum ieee80211_band curr_band;
  605. /*
  606. * If enabled, the debugfs interface structures
  607. * required for deregistration of debugfs.
  608. */
  609. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  610. struct rt2x00debug_intf *debugfs_intf;
  611. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  612. /*
  613. * LED structure for changing the LED status
  614. * by mac8011 or the kernel.
  615. */
  616. #ifdef CONFIG_RT2X00_LIB_LEDS
  617. struct rt2x00_led led_radio;
  618. struct rt2x00_led led_assoc;
  619. struct rt2x00_led led_qual;
  620. u16 led_mcu_reg;
  621. #endif /* CONFIG_RT2X00_LIB_LEDS */
  622. /*
  623. * Device flags.
  624. * In these flags the current status and some
  625. * of the device capabilities are stored.
  626. */
  627. unsigned long flags;
  628. /*
  629. * Device information, Bus IRQ and name (PCI, SoC)
  630. */
  631. int irq;
  632. const char *name;
  633. /*
  634. * Chipset identification.
  635. */
  636. struct rt2x00_chip chip;
  637. /*
  638. * hw capability specifications.
  639. */
  640. struct hw_mode_spec spec;
  641. /*
  642. * This is the default TX/RX antenna setup as indicated
  643. * by the device's EEPROM.
  644. */
  645. struct antenna_setup default_ant;
  646. /*
  647. * Register pointers
  648. * csr.base: CSR base register address. (PCI)
  649. * csr.cache: CSR cache for usb_control_msg. (USB)
  650. */
  651. union csr {
  652. void __iomem *base;
  653. void *cache;
  654. } csr;
  655. /*
  656. * Mutex to protect register accesses.
  657. * For PCI and USB devices it protects against concurrent indirect
  658. * register access (BBP, RF, MCU) since accessing those
  659. * registers require multiple calls to the CSR registers.
  660. * For USB devices it also protects the csr_cache since that
  661. * field is used for normal CSR access and it cannot support
  662. * multiple callers simultaneously.
  663. */
  664. struct mutex csr_mutex;
  665. /*
  666. * Current packet filter configuration for the device.
  667. * This contains all currently active FIF_* flags send
  668. * to us by mac80211 during configure_filter().
  669. */
  670. unsigned int packet_filter;
  671. /*
  672. * Interface details:
  673. * - Open ap interface count.
  674. * - Open sta interface count.
  675. * - Association count.
  676. */
  677. unsigned int intf_ap_count;
  678. unsigned int intf_sta_count;
  679. unsigned int intf_associated;
  680. /*
  681. * Link quality
  682. */
  683. struct link link;
  684. /*
  685. * EEPROM data.
  686. */
  687. __le16 *eeprom;
  688. /*
  689. * Active RF register values.
  690. * These are stored here so we don't need
  691. * to read the rf registers and can directly
  692. * use this value instead.
  693. * This field should be accessed by using
  694. * rt2x00_rf_read() and rt2x00_rf_write().
  695. */
  696. u32 *rf;
  697. /*
  698. * LNA gain
  699. */
  700. short lna_gain;
  701. /*
  702. * Current TX power value.
  703. */
  704. u16 tx_power;
  705. /*
  706. * Current retry values.
  707. */
  708. u8 short_retry;
  709. u8 long_retry;
  710. /*
  711. * Rssi <-> Dbm offset
  712. */
  713. u8 rssi_offset;
  714. /*
  715. * Frequency offset (for rt61pci & rt73usb).
  716. */
  717. u8 freq_offset;
  718. /*
  719. * Calibration information (for rt2800usb & rt2800pci).
  720. * [0] -> BW20
  721. * [1] -> BW40
  722. */
  723. u8 calibration[2];
  724. /*
  725. * Beacon interval.
  726. */
  727. u16 beacon_int;
  728. /*
  729. * Low level statistics which will have
  730. * to be kept up to date while device is running.
  731. */
  732. struct ieee80211_low_level_stats low_level_stats;
  733. /*
  734. * RX configuration information.
  735. */
  736. struct ieee80211_rx_status rx_status;
  737. /*
  738. * Scheduled work.
  739. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  740. * which means it cannot be placed on the hw->workqueue
  741. * due to RTNL locking requirements.
  742. */
  743. struct work_struct intf_work;
  744. /*
  745. * Data queue arrays for RX, TX and Beacon.
  746. * The Beacon array also contains the Atim queue
  747. * if that is supported by the device.
  748. */
  749. unsigned int data_queues;
  750. struct data_queue *rx;
  751. struct data_queue *tx;
  752. struct data_queue *bcn;
  753. /*
  754. * Firmware image.
  755. */
  756. const struct firmware *fw;
  757. /*
  758. * Driver specific data.
  759. */
  760. void *priv;
  761. };
  762. /*
  763. * Register defines.
  764. * Some registers require multiple attempts before success,
  765. * in those cases REGISTER_BUSY_COUNT attempts should be
  766. * taken with a REGISTER_BUSY_DELAY interval.
  767. */
  768. #define REGISTER_BUSY_COUNT 5
  769. #define REGISTER_BUSY_DELAY 100
  770. /*
  771. * Generic RF access.
  772. * The RF is being accessed by word index.
  773. */
  774. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  775. const unsigned int word, u32 *data)
  776. {
  777. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  778. *data = rt2x00dev->rf[word - 1];
  779. }
  780. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  781. const unsigned int word, u32 data)
  782. {
  783. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  784. rt2x00dev->rf[word - 1] = data;
  785. }
  786. /*
  787. * Generic EEPROM access.
  788. * The EEPROM is being accessed by word index.
  789. */
  790. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  791. const unsigned int word)
  792. {
  793. return (void *)&rt2x00dev->eeprom[word];
  794. }
  795. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  796. const unsigned int word, u16 *data)
  797. {
  798. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  799. }
  800. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  801. const unsigned int word, u16 data)
  802. {
  803. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  804. }
  805. /*
  806. * Chipset handlers
  807. */
  808. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  809. const u16 rt, const u16 rf, const u16 rev)
  810. {
  811. rt2x00dev->chip.rt = rt;
  812. rt2x00dev->chip.rf = rf;
  813. rt2x00dev->chip.rev = rev;
  814. INFO(rt2x00dev,
  815. "Chipset detected - rt: %04x, rf: %04x, rev: %04x.\n",
  816. rt2x00dev->chip.rt, rt2x00dev->chip.rf, rt2x00dev->chip.rev);
  817. }
  818. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  819. {
  820. return (rt2x00dev->chip.rt == rt);
  821. }
  822. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  823. {
  824. return (rt2x00dev->chip.rf == rf);
  825. }
  826. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  827. {
  828. return rt2x00dev->chip.rev;
  829. }
  830. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  831. const u16 rt, const u16 rev)
  832. {
  833. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  834. }
  835. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  836. const u16 rt, const u16 rev)
  837. {
  838. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  839. }
  840. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  841. const u16 rt, const u16 rev)
  842. {
  843. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  844. }
  845. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  846. enum rt2x00_chip_intf intf)
  847. {
  848. rt2x00dev->chip.intf = intf;
  849. }
  850. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  851. enum rt2x00_chip_intf intf)
  852. {
  853. return (rt2x00dev->chip.intf == intf);
  854. }
  855. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  856. {
  857. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI);
  858. }
  859. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  860. {
  861. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  862. }
  863. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  864. {
  865. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  866. }
  867. /**
  868. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  869. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  870. * @skb: The skb to map.
  871. */
  872. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  873. /**
  874. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  875. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  876. * @skb: The skb to unmap.
  877. */
  878. void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  879. /**
  880. * rt2x00queue_get_queue - Convert queue index to queue pointer
  881. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  882. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  883. */
  884. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  885. const enum data_queue_qid queue);
  886. /**
  887. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  888. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  889. * @index: Index identifier for obtaining the correct index.
  890. */
  891. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  892. enum queue_index index);
  893. /*
  894. * Debugfs handlers.
  895. */
  896. /**
  897. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  898. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  899. * @type: The type of frame that is being dumped.
  900. * @skb: The skb containing the frame to be dumped.
  901. */
  902. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  903. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  904. enum rt2x00_dump_type type, struct sk_buff *skb);
  905. #else
  906. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  907. enum rt2x00_dump_type type,
  908. struct sk_buff *skb)
  909. {
  910. }
  911. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  912. /*
  913. * Interrupt context handlers.
  914. */
  915. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  916. void rt2x00lib_txdone(struct queue_entry *entry,
  917. struct txdone_entry_desc *txdesc);
  918. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  919. struct queue_entry *entry);
  920. /*
  921. * mac80211 handlers.
  922. */
  923. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  924. int rt2x00mac_start(struct ieee80211_hw *hw);
  925. void rt2x00mac_stop(struct ieee80211_hw *hw);
  926. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  927. struct ieee80211_vif *vif);
  928. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  929. struct ieee80211_vif *vif);
  930. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  931. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  932. unsigned int changed_flags,
  933. unsigned int *total_flags,
  934. u64 multicast);
  935. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  936. bool set);
  937. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  938. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  939. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  940. struct ieee80211_key_conf *key);
  941. #else
  942. #define rt2x00mac_set_key NULL
  943. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  944. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  945. struct ieee80211_low_level_stats *stats);
  946. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  947. struct ieee80211_vif *vif,
  948. struct ieee80211_bss_conf *bss_conf,
  949. u32 changes);
  950. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  951. const struct ieee80211_tx_queue_params *params);
  952. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  953. /*
  954. * Driver allocation handlers.
  955. */
  956. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  957. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  958. #ifdef CONFIG_PM
  959. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  960. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  961. #endif /* CONFIG_PM */
  962. #endif /* RT2X00_H */