rt2x00.h 26 KB

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