rt2x00.h 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. * Threaded Interrupt handlers.
  451. */
  452. irq_handler_t irq_handler_thread;
  453. /*
  454. * Device init handlers.
  455. */
  456. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  457. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  458. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  459. const u8 *data, const size_t len);
  460. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  461. const u8 *data, const size_t len);
  462. /*
  463. * Device initialization/deinitialization handlers.
  464. */
  465. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  466. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  467. /*
  468. * queue initialization handlers
  469. */
  470. bool (*get_entry_state) (struct queue_entry *entry);
  471. void (*clear_entry) (struct queue_entry *entry);
  472. /*
  473. * Radio control handlers.
  474. */
  475. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  476. enum dev_state state);
  477. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  478. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  479. struct link_qual *qual);
  480. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  481. struct link_qual *qual);
  482. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  483. struct link_qual *qual, const u32 count);
  484. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  485. /*
  486. * TX control handlers
  487. */
  488. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  489. struct sk_buff *skb,
  490. struct txentry_desc *txdesc);
  491. void (*write_tx_data) (struct queue_entry *entry,
  492. struct txentry_desc *txdesc);
  493. void (*write_beacon) (struct queue_entry *entry,
  494. struct txentry_desc *txdesc);
  495. int (*get_tx_data_len) (struct queue_entry *entry);
  496. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  497. const enum data_queue_qid queue);
  498. void (*kill_tx_queue) (struct rt2x00_dev *rt2x00dev,
  499. const enum data_queue_qid queue);
  500. /*
  501. * RX control handlers
  502. */
  503. void (*fill_rxdone) (struct queue_entry *entry,
  504. struct rxdone_entry_desc *rxdesc);
  505. /*
  506. * Configuration handlers.
  507. */
  508. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  509. struct rt2x00lib_crypto *crypto,
  510. struct ieee80211_key_conf *key);
  511. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  512. struct rt2x00lib_crypto *crypto,
  513. struct ieee80211_key_conf *key);
  514. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  515. const unsigned int filter_flags);
  516. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  517. struct rt2x00_intf *intf,
  518. struct rt2x00intf_conf *conf,
  519. const unsigned int flags);
  520. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  521. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  522. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  523. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  524. struct rt2x00lib_erp *erp);
  525. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  526. struct antenna_setup *ant);
  527. void (*config) (struct rt2x00_dev *rt2x00dev,
  528. struct rt2x00lib_conf *libconf,
  529. const unsigned int changed_flags);
  530. };
  531. /*
  532. * rt2x00 driver callback operation structure.
  533. */
  534. struct rt2x00_ops {
  535. const char *name;
  536. const unsigned int max_sta_intf;
  537. const unsigned int max_ap_intf;
  538. const unsigned int eeprom_size;
  539. const unsigned int rf_size;
  540. const unsigned int tx_queues;
  541. const unsigned int extra_tx_headroom;
  542. const struct data_queue_desc *rx;
  543. const struct data_queue_desc *tx;
  544. const struct data_queue_desc *bcn;
  545. const struct data_queue_desc *atim;
  546. const struct rt2x00lib_ops *lib;
  547. const void *drv;
  548. const struct ieee80211_ops *hw;
  549. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  550. const struct rt2x00debug *debugfs;
  551. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  552. };
  553. /*
  554. * rt2x00 device flags
  555. */
  556. enum rt2x00_flags {
  557. /*
  558. * Device state flags
  559. */
  560. DEVICE_STATE_PRESENT,
  561. DEVICE_STATE_REGISTERED_HW,
  562. DEVICE_STATE_INITIALIZED,
  563. DEVICE_STATE_STARTED,
  564. DEVICE_STATE_ENABLED_RADIO,
  565. DEVICE_STATE_SCANNING,
  566. /*
  567. * Driver requirements
  568. */
  569. DRIVER_REQUIRE_FIRMWARE,
  570. DRIVER_REQUIRE_BEACON_GUARD,
  571. DRIVER_REQUIRE_ATIM_QUEUE,
  572. DRIVER_REQUIRE_DMA,
  573. DRIVER_REQUIRE_COPY_IV,
  574. DRIVER_REQUIRE_L2PAD,
  575. /*
  576. * Driver features
  577. */
  578. CONFIG_SUPPORT_HW_BUTTON,
  579. CONFIG_SUPPORT_HW_CRYPTO,
  580. DRIVER_SUPPORT_CONTROL_FILTERS,
  581. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  582. DRIVER_SUPPORT_PRE_TBTT_INTERRUPT,
  583. DRIVER_SUPPORT_LINK_TUNING,
  584. DRIVER_SUPPORT_WATCHDOG,
  585. /*
  586. * Driver configuration
  587. */
  588. CONFIG_FRAME_TYPE,
  589. CONFIG_RF_SEQUENCE,
  590. CONFIG_EXTERNAL_LNA_A,
  591. CONFIG_EXTERNAL_LNA_BG,
  592. CONFIG_DOUBLE_ANTENNA,
  593. CONFIG_CHANNEL_HT40,
  594. };
  595. /*
  596. * rt2x00 device structure.
  597. */
  598. struct rt2x00_dev {
  599. /*
  600. * Device structure.
  601. * The structure stored in here depends on the
  602. * system bus (PCI or USB).
  603. * When accessing this variable, the rt2x00dev_{pci,usb}
  604. * macros should be used for correct typecasting.
  605. */
  606. struct device *dev;
  607. /*
  608. * Callback functions.
  609. */
  610. const struct rt2x00_ops *ops;
  611. /*
  612. * IEEE80211 control structure.
  613. */
  614. struct ieee80211_hw *hw;
  615. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  616. enum ieee80211_band curr_band;
  617. /*
  618. * If enabled, the debugfs interface structures
  619. * required for deregistration of debugfs.
  620. */
  621. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  622. struct rt2x00debug_intf *debugfs_intf;
  623. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  624. /*
  625. * LED structure for changing the LED status
  626. * by mac8011 or the kernel.
  627. */
  628. #ifdef CONFIG_RT2X00_LIB_LEDS
  629. struct rt2x00_led led_radio;
  630. struct rt2x00_led led_assoc;
  631. struct rt2x00_led led_qual;
  632. u16 led_mcu_reg;
  633. #endif /* CONFIG_RT2X00_LIB_LEDS */
  634. /*
  635. * Device flags.
  636. * In these flags the current status and some
  637. * of the device capabilities are stored.
  638. */
  639. unsigned long flags;
  640. /*
  641. * Device information, Bus IRQ and name (PCI, SoC)
  642. */
  643. int irq;
  644. const char *name;
  645. /*
  646. * Chipset identification.
  647. */
  648. struct rt2x00_chip chip;
  649. /*
  650. * hw capability specifications.
  651. */
  652. struct hw_mode_spec spec;
  653. /*
  654. * This is the default TX/RX antenna setup as indicated
  655. * by the device's EEPROM.
  656. */
  657. struct antenna_setup default_ant;
  658. /*
  659. * Register pointers
  660. * csr.base: CSR base register address. (PCI)
  661. * csr.cache: CSR cache for usb_control_msg. (USB)
  662. */
  663. union csr {
  664. void __iomem *base;
  665. void *cache;
  666. } csr;
  667. /*
  668. * Mutex to protect register accesses.
  669. * For PCI and USB devices it protects against concurrent indirect
  670. * register access (BBP, RF, MCU) since accessing those
  671. * registers require multiple calls to the CSR registers.
  672. * For USB devices it also protects the csr_cache since that
  673. * field is used for normal CSR access and it cannot support
  674. * multiple callers simultaneously.
  675. */
  676. struct mutex csr_mutex;
  677. /*
  678. * Current packet filter configuration for the device.
  679. * This contains all currently active FIF_* flags send
  680. * to us by mac80211 during configure_filter().
  681. */
  682. unsigned int packet_filter;
  683. /*
  684. * Interface details:
  685. * - Open ap interface count.
  686. * - Open sta interface count.
  687. * - Association count.
  688. */
  689. unsigned int intf_ap_count;
  690. unsigned int intf_sta_count;
  691. unsigned int intf_associated;
  692. /*
  693. * Link quality
  694. */
  695. struct link link;
  696. /*
  697. * EEPROM data.
  698. */
  699. __le16 *eeprom;
  700. /*
  701. * Active RF register values.
  702. * These are stored here so we don't need
  703. * to read the rf registers and can directly
  704. * use this value instead.
  705. * This field should be accessed by using
  706. * rt2x00_rf_read() and rt2x00_rf_write().
  707. */
  708. u32 *rf;
  709. /*
  710. * LNA gain
  711. */
  712. short lna_gain;
  713. /*
  714. * Current TX power value.
  715. */
  716. u16 tx_power;
  717. /*
  718. * Current retry values.
  719. */
  720. u8 short_retry;
  721. u8 long_retry;
  722. /*
  723. * Rssi <-> Dbm offset
  724. */
  725. u8 rssi_offset;
  726. /*
  727. * Frequency offset (for rt61pci & rt73usb).
  728. */
  729. u8 freq_offset;
  730. /*
  731. * Calibration information (for rt2800usb & rt2800pci).
  732. * [0] -> BW20
  733. * [1] -> BW40
  734. */
  735. u8 calibration[2];
  736. /*
  737. * Beacon interval.
  738. */
  739. u16 beacon_int;
  740. /*
  741. * Low level statistics which will have
  742. * to be kept up to date while device is running.
  743. */
  744. struct ieee80211_low_level_stats low_level_stats;
  745. /*
  746. * RX configuration information.
  747. */
  748. struct ieee80211_rx_status rx_status;
  749. /*
  750. * Scheduled work.
  751. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  752. * which means it cannot be placed on the hw->workqueue
  753. * due to RTNL locking requirements.
  754. */
  755. struct work_struct intf_work;
  756. /*
  757. * Data queue arrays for RX, TX and Beacon.
  758. * The Beacon array also contains the Atim queue
  759. * if that is supported by the device.
  760. */
  761. unsigned int data_queues;
  762. struct data_queue *rx;
  763. struct data_queue *tx;
  764. struct data_queue *bcn;
  765. /*
  766. * Firmware image.
  767. */
  768. const struct firmware *fw;
  769. /*
  770. * Interrupt values, stored between interrupt service routine
  771. * and interrupt thread routine.
  772. */
  773. u32 irqvalue[2];
  774. };
  775. /*
  776. * Register defines.
  777. * Some registers require multiple attempts before success,
  778. * in those cases REGISTER_BUSY_COUNT attempts should be
  779. * taken with a REGISTER_BUSY_DELAY interval.
  780. */
  781. #define REGISTER_BUSY_COUNT 5
  782. #define REGISTER_BUSY_DELAY 100
  783. /*
  784. * Generic RF access.
  785. * The RF is being accessed by word index.
  786. */
  787. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  788. const unsigned int word, u32 *data)
  789. {
  790. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  791. *data = rt2x00dev->rf[word - 1];
  792. }
  793. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  794. const unsigned int word, u32 data)
  795. {
  796. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  797. rt2x00dev->rf[word - 1] = data;
  798. }
  799. /*
  800. * Generic EEPROM access.
  801. * The EEPROM is being accessed by word index.
  802. */
  803. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  804. const unsigned int word)
  805. {
  806. return (void *)&rt2x00dev->eeprom[word];
  807. }
  808. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  809. const unsigned int word, u16 *data)
  810. {
  811. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  812. }
  813. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  814. const unsigned int word, u16 data)
  815. {
  816. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  817. }
  818. /*
  819. * Chipset handlers
  820. */
  821. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  822. const u16 rt, const u16 rf, const u16 rev)
  823. {
  824. rt2x00dev->chip.rt = rt;
  825. rt2x00dev->chip.rf = rf;
  826. rt2x00dev->chip.rev = rev;
  827. INFO(rt2x00dev,
  828. "Chipset detected - rt: %04x, rf: %04x, rev: %04x.\n",
  829. rt2x00dev->chip.rt, rt2x00dev->chip.rf, rt2x00dev->chip.rev);
  830. }
  831. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  832. {
  833. return (rt2x00dev->chip.rt == rt);
  834. }
  835. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  836. {
  837. return (rt2x00dev->chip.rf == rf);
  838. }
  839. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  840. {
  841. return rt2x00dev->chip.rev;
  842. }
  843. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  844. const u16 rt, const u16 rev)
  845. {
  846. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  847. }
  848. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  849. const u16 rt, const u16 rev)
  850. {
  851. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  852. }
  853. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  854. const u16 rt, const u16 rev)
  855. {
  856. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  857. }
  858. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  859. enum rt2x00_chip_intf intf)
  860. {
  861. rt2x00dev->chip.intf = intf;
  862. }
  863. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  864. enum rt2x00_chip_intf intf)
  865. {
  866. return (rt2x00dev->chip.intf == intf);
  867. }
  868. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  869. {
  870. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  871. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  872. }
  873. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  874. {
  875. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  876. }
  877. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  878. {
  879. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  880. }
  881. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  882. {
  883. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  884. }
  885. /**
  886. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  887. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  888. * @skb: The skb to map.
  889. */
  890. void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  891. /**
  892. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  893. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  894. * @skb: The skb to unmap.
  895. */
  896. void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  897. /**
  898. * rt2x00queue_get_queue - Convert queue index to queue pointer
  899. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  900. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  901. */
  902. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  903. const enum data_queue_qid queue);
  904. /**
  905. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  906. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  907. * @index: Index identifier for obtaining the correct index.
  908. */
  909. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  910. enum queue_index index);
  911. /*
  912. * Debugfs handlers.
  913. */
  914. /**
  915. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  916. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  917. * @type: The type of frame that is being dumped.
  918. * @skb: The skb containing the frame to be dumped.
  919. */
  920. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  921. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  922. enum rt2x00_dump_type type, struct sk_buff *skb);
  923. #else
  924. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  925. enum rt2x00_dump_type type,
  926. struct sk_buff *skb)
  927. {
  928. }
  929. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  930. /*
  931. * Interrupt context handlers.
  932. */
  933. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  934. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  935. void rt2x00lib_txdone(struct queue_entry *entry,
  936. struct txdone_entry_desc *txdesc);
  937. void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
  938. struct queue_entry *entry);
  939. /*
  940. * mac80211 handlers.
  941. */
  942. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  943. int rt2x00mac_start(struct ieee80211_hw *hw);
  944. void rt2x00mac_stop(struct ieee80211_hw *hw);
  945. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  946. struct ieee80211_vif *vif);
  947. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  948. struct ieee80211_vif *vif);
  949. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  950. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  951. unsigned int changed_flags,
  952. unsigned int *total_flags,
  953. u64 multicast);
  954. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  955. bool set);
  956. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  957. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  958. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  959. struct ieee80211_key_conf *key);
  960. #else
  961. #define rt2x00mac_set_key NULL
  962. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  963. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw);
  964. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw);
  965. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  966. struct ieee80211_low_level_stats *stats);
  967. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  968. struct ieee80211_vif *vif,
  969. struct ieee80211_bss_conf *bss_conf,
  970. u32 changes);
  971. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  972. const struct ieee80211_tx_queue_params *params);
  973. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  974. /*
  975. * Driver allocation handlers.
  976. */
  977. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  978. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  979. #ifdef CONFIG_PM
  980. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  981. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  982. #endif /* CONFIG_PM */
  983. #endif /* RT2X00_H */