rt2x00.h 29 KB

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