rt2x00.h 28 KB

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