rt2x00.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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. enum rt2x00_delayed_flags {
  310. DELAYED_UPDATE_BEACON,
  311. };
  312. /*
  313. * Interface structure
  314. * Per interface configuration details, this structure
  315. * is allocated as the private data for ieee80211_vif.
  316. */
  317. struct rt2x00_intf {
  318. /*
  319. * beacon->skb must be protected with the mutex.
  320. */
  321. struct mutex beacon_skb_mutex;
  322. /*
  323. * Entry in the beacon queue which belongs to
  324. * this interface. Each interface has its own
  325. * dedicated beacon entry.
  326. */
  327. struct queue_entry *beacon;
  328. bool enable_beacon;
  329. /*
  330. * Actions that needed rescheduling.
  331. */
  332. unsigned long delayed_flags;
  333. /*
  334. * Software sequence counter, this is only required
  335. * for hardware which doesn't support hardware
  336. * sequence counting.
  337. */
  338. spinlock_t seqlock;
  339. u16 seqno;
  340. };
  341. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  342. {
  343. return (struct rt2x00_intf *)vif->drv_priv;
  344. }
  345. /**
  346. * struct hw_mode_spec: Hardware specifications structure
  347. *
  348. * Details about the supported modes, rates and channels
  349. * of a particular chipset. This is used by rt2x00lib
  350. * to build the ieee80211_hw_mode array for mac80211.
  351. *
  352. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  353. * @supported_rates: Rate types which are supported (CCK, OFDM).
  354. * @num_channels: Number of supported channels. This is used as array size
  355. * for @tx_power_a, @tx_power_bg and @channels.
  356. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  357. * @channels_info: Additional information for channels (See &struct channel_info).
  358. * @ht: Driver HT Capabilities (See &ieee80211_sta_ht_cap).
  359. */
  360. struct hw_mode_spec {
  361. unsigned int supported_bands;
  362. #define SUPPORT_BAND_2GHZ 0x00000001
  363. #define SUPPORT_BAND_5GHZ 0x00000002
  364. unsigned int supported_rates;
  365. #define SUPPORT_RATE_CCK 0x00000001
  366. #define SUPPORT_RATE_OFDM 0x00000002
  367. unsigned int num_channels;
  368. const struct rf_channel *channels;
  369. const struct channel_info *channels_info;
  370. struct ieee80211_sta_ht_cap ht;
  371. };
  372. /*
  373. * Configuration structure wrapper around the
  374. * mac80211 configuration structure.
  375. * When mac80211 configures the driver, rt2x00lib
  376. * can precalculate values which are equal for all
  377. * rt2x00 drivers. Those values can be stored in here.
  378. */
  379. struct rt2x00lib_conf {
  380. struct ieee80211_conf *conf;
  381. struct rf_channel rf;
  382. struct channel_info channel;
  383. };
  384. /*
  385. * Configuration structure for erp settings.
  386. */
  387. struct rt2x00lib_erp {
  388. int short_preamble;
  389. int cts_protection;
  390. u32 basic_rates;
  391. int slot_time;
  392. short sifs;
  393. short pifs;
  394. short difs;
  395. short eifs;
  396. u16 beacon_int;
  397. u16 ht_opmode;
  398. };
  399. /*
  400. * Configuration structure for hardware encryption.
  401. */
  402. struct rt2x00lib_crypto {
  403. enum cipher cipher;
  404. enum set_key_cmd cmd;
  405. const u8 *address;
  406. u32 bssidx;
  407. u32 aid;
  408. u8 key[16];
  409. u8 tx_mic[8];
  410. u8 rx_mic[8];
  411. };
  412. /*
  413. * Configuration structure wrapper around the
  414. * rt2x00 interface configuration handler.
  415. */
  416. struct rt2x00intf_conf {
  417. /*
  418. * Interface type
  419. */
  420. enum nl80211_iftype type;
  421. /*
  422. * TSF sync value, this is dependant on the operation type.
  423. */
  424. enum tsf_sync sync;
  425. /*
  426. * The MAC and BSSID addressess are simple array of bytes,
  427. * these arrays are little endian, so when sending the addressess
  428. * to the drivers, copy the it into a endian-signed variable.
  429. *
  430. * Note that all devices (except rt2500usb) have 32 bits
  431. * register word sizes. This means that whatever variable we
  432. * pass _must_ be a multiple of 32 bits. Otherwise the device
  433. * might not accept what we are sending to it.
  434. * This will also make it easier for the driver to write
  435. * the data to the device.
  436. */
  437. __le32 mac[2];
  438. __le32 bssid[2];
  439. };
  440. /*
  441. * rt2x00lib callback functions.
  442. */
  443. struct rt2x00lib_ops {
  444. /*
  445. * Interrupt handlers.
  446. */
  447. irq_handler_t irq_handler;
  448. /*
  449. * TX status tasklet handler.
  450. */
  451. void (*txstatus_tasklet) (unsigned long data);
  452. void (*pretbtt_tasklet) (unsigned long data);
  453. void (*tbtt_tasklet) (unsigned long data);
  454. void (*rxdone_tasklet) (unsigned long data);
  455. void (*autowake_tasklet) (unsigned long data);
  456. /*
  457. * Device init handlers.
  458. */
  459. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  460. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  461. int (*check_firmware) (struct rt2x00_dev *rt2x00dev,
  462. const u8 *data, const size_t len);
  463. int (*load_firmware) (struct rt2x00_dev *rt2x00dev,
  464. const u8 *data, const size_t len);
  465. /*
  466. * Device initialization/deinitialization handlers.
  467. */
  468. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  469. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  470. /*
  471. * queue initialization handlers
  472. */
  473. bool (*get_entry_state) (struct queue_entry *entry);
  474. void (*clear_entry) (struct queue_entry *entry);
  475. /*
  476. * Radio control handlers.
  477. */
  478. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  479. enum dev_state state);
  480. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  481. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  482. struct link_qual *qual);
  483. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev,
  484. struct link_qual *qual);
  485. void (*link_tuner) (struct rt2x00_dev *rt2x00dev,
  486. struct link_qual *qual, const u32 count);
  487. /*
  488. * Data queue handlers.
  489. */
  490. void (*watchdog) (struct rt2x00_dev *rt2x00dev);
  491. void (*start_queue) (struct data_queue *queue);
  492. void (*kick_queue) (struct data_queue *queue);
  493. void (*stop_queue) (struct data_queue *queue);
  494. void (*flush_queue) (struct data_queue *queue);
  495. /*
  496. * TX control handlers
  497. */
  498. void (*write_tx_desc) (struct queue_entry *entry,
  499. struct txentry_desc *txdesc);
  500. void (*write_tx_data) (struct queue_entry *entry,
  501. struct txentry_desc *txdesc);
  502. void (*write_beacon) (struct queue_entry *entry,
  503. struct txentry_desc *txdesc);
  504. void (*clear_beacon) (struct queue_entry *entry);
  505. int (*get_tx_data_len) (struct queue_entry *entry);
  506. /*
  507. * RX control handlers
  508. */
  509. void (*fill_rxdone) (struct queue_entry *entry,
  510. struct rxdone_entry_desc *rxdesc);
  511. /*
  512. * Configuration handlers.
  513. */
  514. int (*config_shared_key) (struct rt2x00_dev *rt2x00dev,
  515. struct rt2x00lib_crypto *crypto,
  516. struct ieee80211_key_conf *key);
  517. int (*config_pairwise_key) (struct rt2x00_dev *rt2x00dev,
  518. struct rt2x00lib_crypto *crypto,
  519. struct ieee80211_key_conf *key);
  520. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  521. const unsigned int filter_flags);
  522. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  523. struct rt2x00_intf *intf,
  524. struct rt2x00intf_conf *conf,
  525. const unsigned int flags);
  526. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  527. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  528. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  529. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  530. struct rt2x00lib_erp *erp,
  531. u32 changed);
  532. void (*config_ant) (struct rt2x00_dev *rt2x00dev,
  533. struct antenna_setup *ant);
  534. void (*config) (struct rt2x00_dev *rt2x00dev,
  535. struct rt2x00lib_conf *libconf,
  536. const unsigned int changed_flags);
  537. };
  538. /*
  539. * rt2x00 driver callback operation structure.
  540. */
  541. struct rt2x00_ops {
  542. const char *name;
  543. const unsigned int max_sta_intf;
  544. const unsigned int max_ap_intf;
  545. const unsigned int eeprom_size;
  546. const unsigned int rf_size;
  547. const unsigned int tx_queues;
  548. const unsigned int extra_tx_headroom;
  549. const struct data_queue_desc *rx;
  550. const struct data_queue_desc *tx;
  551. const struct data_queue_desc *bcn;
  552. const struct data_queue_desc *atim;
  553. const struct rt2x00lib_ops *lib;
  554. const void *drv;
  555. const struct ieee80211_ops *hw;
  556. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  557. const struct rt2x00debug *debugfs;
  558. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  559. };
  560. /*
  561. * rt2x00 device flags
  562. */
  563. enum rt2x00_flags {
  564. /*
  565. * Device state flags
  566. */
  567. DEVICE_STATE_PRESENT,
  568. DEVICE_STATE_REGISTERED_HW,
  569. DEVICE_STATE_INITIALIZED,
  570. DEVICE_STATE_STARTED,
  571. DEVICE_STATE_ENABLED_RADIO,
  572. DEVICE_STATE_SCANNING,
  573. /*
  574. * Driver requirements
  575. */
  576. DRIVER_REQUIRE_FIRMWARE,
  577. DRIVER_REQUIRE_BEACON_GUARD,
  578. DRIVER_REQUIRE_ATIM_QUEUE,
  579. DRIVER_REQUIRE_DMA,
  580. DRIVER_REQUIRE_COPY_IV,
  581. DRIVER_REQUIRE_L2PAD,
  582. DRIVER_REQUIRE_TXSTATUS_FIFO,
  583. DRIVER_REQUIRE_TASKLET_CONTEXT,
  584. /*
  585. * Driver features
  586. */
  587. CONFIG_SUPPORT_HW_BUTTON,
  588. CONFIG_SUPPORT_HW_CRYPTO,
  589. DRIVER_SUPPORT_CONTROL_FILTERS,
  590. DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL,
  591. DRIVER_SUPPORT_PRE_TBTT_INTERRUPT,
  592. DRIVER_SUPPORT_LINK_TUNING,
  593. DRIVER_SUPPORT_WATCHDOG,
  594. /*
  595. * Driver configuration
  596. */
  597. CONFIG_FRAME_TYPE,
  598. CONFIG_RF_SEQUENCE,
  599. CONFIG_EXTERNAL_LNA_A,
  600. CONFIG_EXTERNAL_LNA_BG,
  601. CONFIG_DOUBLE_ANTENNA,
  602. CONFIG_CHANNEL_HT40,
  603. };
  604. /*
  605. * rt2x00 device structure.
  606. */
  607. struct rt2x00_dev {
  608. /*
  609. * Device structure.
  610. * The structure stored in here depends on the
  611. * system bus (PCI or USB).
  612. * When accessing this variable, the rt2x00dev_{pci,usb}
  613. * macros should be used for correct typecasting.
  614. */
  615. struct device *dev;
  616. /*
  617. * Callback functions.
  618. */
  619. const struct rt2x00_ops *ops;
  620. /*
  621. * IEEE80211 control structure.
  622. */
  623. struct ieee80211_hw *hw;
  624. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  625. enum ieee80211_band curr_band;
  626. int curr_freq;
  627. /*
  628. * If enabled, the debugfs interface structures
  629. * required for deregistration of debugfs.
  630. */
  631. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  632. struct rt2x00debug_intf *debugfs_intf;
  633. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  634. /*
  635. * LED structure for changing the LED status
  636. * by mac8011 or the kernel.
  637. */
  638. #ifdef CONFIG_RT2X00_LIB_LEDS
  639. struct rt2x00_led led_radio;
  640. struct rt2x00_led led_assoc;
  641. struct rt2x00_led led_qual;
  642. u16 led_mcu_reg;
  643. #endif /* CONFIG_RT2X00_LIB_LEDS */
  644. /*
  645. * Device flags.
  646. * In these flags the current status and some
  647. * of the device capabilities are stored.
  648. */
  649. unsigned long flags;
  650. /*
  651. * Device information, Bus IRQ and name (PCI, SoC)
  652. */
  653. int irq;
  654. const char *name;
  655. /*
  656. * Chipset identification.
  657. */
  658. struct rt2x00_chip chip;
  659. /*
  660. * hw capability specifications.
  661. */
  662. struct hw_mode_spec spec;
  663. /*
  664. * This is the default TX/RX antenna setup as indicated
  665. * by the device's EEPROM.
  666. */
  667. struct antenna_setup default_ant;
  668. /*
  669. * Register pointers
  670. * csr.base: CSR base register address. (PCI)
  671. * csr.cache: CSR cache for usb_control_msg. (USB)
  672. */
  673. union csr {
  674. void __iomem *base;
  675. void *cache;
  676. } csr;
  677. /*
  678. * Mutex to protect register accesses.
  679. * For PCI and USB devices it protects against concurrent indirect
  680. * register access (BBP, RF, MCU) since accessing those
  681. * registers require multiple calls to the CSR registers.
  682. * For USB devices it also protects the csr_cache since that
  683. * field is used for normal CSR access and it cannot support
  684. * multiple callers simultaneously.
  685. */
  686. struct mutex csr_mutex;
  687. /*
  688. * Current packet filter configuration for the device.
  689. * This contains all currently active FIF_* flags send
  690. * to us by mac80211 during configure_filter().
  691. */
  692. unsigned int packet_filter;
  693. /*
  694. * Interface details:
  695. * - Open ap interface count.
  696. * - Open sta interface count.
  697. * - Association count.
  698. * - Beaconing enabled count.
  699. */
  700. unsigned int intf_ap_count;
  701. unsigned int intf_sta_count;
  702. unsigned int intf_associated;
  703. unsigned int intf_beaconing;
  704. /*
  705. * Link quality
  706. */
  707. struct link link;
  708. /*
  709. * EEPROM data.
  710. */
  711. __le16 *eeprom;
  712. /*
  713. * Active RF register values.
  714. * These are stored here so we don't need
  715. * to read the rf registers and can directly
  716. * use this value instead.
  717. * This field should be accessed by using
  718. * rt2x00_rf_read() and rt2x00_rf_write().
  719. */
  720. u32 *rf;
  721. /*
  722. * LNA gain
  723. */
  724. short lna_gain;
  725. /*
  726. * Current TX power value.
  727. */
  728. u16 tx_power;
  729. /*
  730. * Current retry values.
  731. */
  732. u8 short_retry;
  733. u8 long_retry;
  734. /*
  735. * Rssi <-> Dbm offset
  736. */
  737. u8 rssi_offset;
  738. /*
  739. * Frequency offset (for rt61pci & rt73usb).
  740. */
  741. u8 freq_offset;
  742. /*
  743. * Calibration information (for rt2800usb & rt2800pci).
  744. * [0] -> BW20
  745. * [1] -> BW40
  746. */
  747. u8 calibration[2];
  748. /*
  749. * Beacon interval.
  750. */
  751. u16 beacon_int;
  752. /*
  753. * Low level statistics which will have
  754. * to be kept up to date while device is running.
  755. */
  756. struct ieee80211_low_level_stats low_level_stats;
  757. /**
  758. * Work queue for all work which should not be placed
  759. * on the mac80211 workqueue (because of dependencies
  760. * between various work structures).
  761. */
  762. struct workqueue_struct *workqueue;
  763. /*
  764. * Scheduled work.
  765. * NOTE: intf_work will use ieee80211_iterate_active_interfaces()
  766. * which means it cannot be placed on the hw->workqueue
  767. * due to RTNL locking requirements.
  768. */
  769. struct work_struct intf_work;
  770. /**
  771. * Scheduled work for TX/RX done handling (USB devices)
  772. */
  773. struct work_struct rxdone_work;
  774. struct work_struct txdone_work;
  775. /*
  776. * Data queue arrays for RX, TX and Beacon.
  777. * The Beacon array also contains the Atim queue
  778. * if that is supported by the device.
  779. */
  780. unsigned int data_queues;
  781. struct data_queue *rx;
  782. struct data_queue *tx;
  783. struct data_queue *bcn;
  784. /*
  785. * Firmware image.
  786. */
  787. const struct firmware *fw;
  788. /*
  789. * FIFO for storing tx status reports between isr and tasklet.
  790. */
  791. DECLARE_KFIFO_PTR(txstatus_fifo, u32);
  792. /*
  793. * Tasklet for processing tx status reports (rt2800pci).
  794. */
  795. struct tasklet_struct txstatus_tasklet;
  796. struct tasklet_struct pretbtt_tasklet;
  797. struct tasklet_struct tbtt_tasklet;
  798. struct tasklet_struct rxdone_tasklet;
  799. struct tasklet_struct autowake_tasklet;
  800. /*
  801. * Protect the interrupt mask register.
  802. */
  803. spinlock_t irqmask_lock;
  804. };
  805. /*
  806. * Register defines.
  807. * Some registers require multiple attempts before success,
  808. * in those cases REGISTER_BUSY_COUNT attempts should be
  809. * taken with a REGISTER_BUSY_DELAY interval.
  810. */
  811. #define REGISTER_BUSY_COUNT 100
  812. #define REGISTER_BUSY_DELAY 100
  813. /*
  814. * Generic RF access.
  815. * The RF is being accessed by word index.
  816. */
  817. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  818. const unsigned int word, u32 *data)
  819. {
  820. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  821. *data = rt2x00dev->rf[word - 1];
  822. }
  823. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  824. const unsigned int word, u32 data)
  825. {
  826. BUG_ON(word < 1 || word > rt2x00dev->ops->rf_size / sizeof(u32));
  827. rt2x00dev->rf[word - 1] = data;
  828. }
  829. /*
  830. * Generic EEPROM access.
  831. * The EEPROM is being accessed by word index.
  832. */
  833. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  834. const unsigned int word)
  835. {
  836. return (void *)&rt2x00dev->eeprom[word];
  837. }
  838. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  839. const unsigned int word, u16 *data)
  840. {
  841. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  842. }
  843. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  844. const unsigned int word, u16 data)
  845. {
  846. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  847. }
  848. /*
  849. * Chipset handlers
  850. */
  851. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  852. const u16 rt, const u16 rf, const u16 rev)
  853. {
  854. rt2x00dev->chip.rt = rt;
  855. rt2x00dev->chip.rf = rf;
  856. rt2x00dev->chip.rev = rev;
  857. INFO(rt2x00dev,
  858. "Chipset detected - rt: %04x, rf: %04x, rev: %04x.\n",
  859. rt2x00dev->chip.rt, rt2x00dev->chip.rf, rt2x00dev->chip.rev);
  860. }
  861. static inline bool rt2x00_rt(struct rt2x00_dev *rt2x00dev, const u16 rt)
  862. {
  863. return (rt2x00dev->chip.rt == rt);
  864. }
  865. static inline bool rt2x00_rf(struct rt2x00_dev *rt2x00dev, const u16 rf)
  866. {
  867. return (rt2x00dev->chip.rf == rf);
  868. }
  869. static inline u16 rt2x00_rev(struct rt2x00_dev *rt2x00dev)
  870. {
  871. return rt2x00dev->chip.rev;
  872. }
  873. static inline bool rt2x00_rt_rev(struct rt2x00_dev *rt2x00dev,
  874. const u16 rt, const u16 rev)
  875. {
  876. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) == rev);
  877. }
  878. static inline bool rt2x00_rt_rev_lt(struct rt2x00_dev *rt2x00dev,
  879. const u16 rt, const u16 rev)
  880. {
  881. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) < rev);
  882. }
  883. static inline bool rt2x00_rt_rev_gte(struct rt2x00_dev *rt2x00dev,
  884. const u16 rt, const u16 rev)
  885. {
  886. return (rt2x00_rt(rt2x00dev, rt) && rt2x00_rev(rt2x00dev) >= rev);
  887. }
  888. static inline void rt2x00_set_chip_intf(struct rt2x00_dev *rt2x00dev,
  889. enum rt2x00_chip_intf intf)
  890. {
  891. rt2x00dev->chip.intf = intf;
  892. }
  893. static inline bool rt2x00_intf(struct rt2x00_dev *rt2x00dev,
  894. enum rt2x00_chip_intf intf)
  895. {
  896. return (rt2x00dev->chip.intf == intf);
  897. }
  898. static inline bool rt2x00_is_pci(struct rt2x00_dev *rt2x00dev)
  899. {
  900. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCI) ||
  901. rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  902. }
  903. static inline bool rt2x00_is_pcie(struct rt2x00_dev *rt2x00dev)
  904. {
  905. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_PCIE);
  906. }
  907. static inline bool rt2x00_is_usb(struct rt2x00_dev *rt2x00dev)
  908. {
  909. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
  910. }
  911. static inline bool rt2x00_is_soc(struct rt2x00_dev *rt2x00dev)
  912. {
  913. return rt2x00_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
  914. }
  915. /**
  916. * rt2x00queue_map_txskb - Map a skb into DMA for TX purposes.
  917. * @entry: Pointer to &struct queue_entry
  918. */
  919. void rt2x00queue_map_txskb(struct queue_entry *entry);
  920. /**
  921. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  922. * @entry: Pointer to &struct queue_entry
  923. */
  924. void rt2x00queue_unmap_skb(struct queue_entry *entry);
  925. /**
  926. * rt2x00queue_get_queue - Convert queue index to queue pointer
  927. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  928. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  929. */
  930. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  931. const enum data_queue_qid queue);
  932. /**
  933. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  934. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  935. * @index: Index identifier for obtaining the correct index.
  936. */
  937. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  938. enum queue_index index);
  939. /**
  940. * rt2x00queue_pause_queue - Pause a data queue
  941. * @queue: Pointer to &struct data_queue.
  942. *
  943. * This function will pause the data queue locally, preventing
  944. * new frames to be added to the queue (while the hardware is
  945. * still allowed to run).
  946. */
  947. void rt2x00queue_pause_queue(struct data_queue *queue);
  948. /**
  949. * rt2x00queue_unpause_queue - unpause a data queue
  950. * @queue: Pointer to &struct data_queue.
  951. *
  952. * This function will unpause the data queue locally, allowing
  953. * new frames to be added to the queue again.
  954. */
  955. void rt2x00queue_unpause_queue(struct data_queue *queue);
  956. /**
  957. * rt2x00queue_start_queue - Start a data queue
  958. * @queue: Pointer to &struct data_queue.
  959. *
  960. * This function will start handling all pending frames in the queue.
  961. */
  962. void rt2x00queue_start_queue(struct data_queue *queue);
  963. /**
  964. * rt2x00queue_stop_queue - Halt a data queue
  965. * @queue: Pointer to &struct data_queue.
  966. *
  967. * This function will stop all pending frames in the queue.
  968. */
  969. void rt2x00queue_stop_queue(struct data_queue *queue);
  970. /**
  971. * rt2x00queue_flush_queue - Flush a data queue
  972. * @queue: Pointer to &struct data_queue.
  973. * @drop: True to drop all pending frames.
  974. *
  975. * This function will flush the queue. After this call
  976. * the queue is guarenteed to be empty.
  977. */
  978. void rt2x00queue_flush_queue(struct data_queue *queue, bool drop);
  979. /**
  980. * rt2x00queue_start_queues - Start all data queues
  981. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  982. *
  983. * This function will loop through all available queues to start them
  984. */
  985. void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev);
  986. /**
  987. * rt2x00queue_stop_queues - Halt all data queues
  988. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  989. *
  990. * This function will loop through all available queues to stop
  991. * any pending frames.
  992. */
  993. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  994. /**
  995. * rt2x00queue_flush_queues - Flush all data queues
  996. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  997. * @drop: True to drop all pending frames.
  998. *
  999. * This function will loop through all available queues to flush
  1000. * any pending frames.
  1001. */
  1002. void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
  1003. /*
  1004. * Debugfs handlers.
  1005. */
  1006. /**
  1007. * rt2x00debug_dump_frame - Dump a frame to userspace through debugfs.
  1008. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  1009. * @type: The type of frame that is being dumped.
  1010. * @skb: The skb containing the frame to be dumped.
  1011. */
  1012. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1013. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1014. enum rt2x00_dump_type type, struct sk_buff *skb);
  1015. #else
  1016. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  1017. enum rt2x00_dump_type type,
  1018. struct sk_buff *skb)
  1019. {
  1020. }
  1021. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1022. /*
  1023. * Interrupt context handlers.
  1024. */
  1025. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  1026. void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev);
  1027. void rt2x00lib_dmastart(struct queue_entry *entry);
  1028. void rt2x00lib_dmadone(struct queue_entry *entry);
  1029. void rt2x00lib_txdone(struct queue_entry *entry,
  1030. struct txdone_entry_desc *txdesc);
  1031. void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
  1032. void rt2x00lib_rxdone(struct queue_entry *entry);
  1033. /*
  1034. * mac80211 handlers.
  1035. */
  1036. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  1037. int rt2x00mac_start(struct ieee80211_hw *hw);
  1038. void rt2x00mac_stop(struct ieee80211_hw *hw);
  1039. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  1040. struct ieee80211_vif *vif);
  1041. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  1042. struct ieee80211_vif *vif);
  1043. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed);
  1044. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  1045. unsigned int changed_flags,
  1046. unsigned int *total_flags,
  1047. u64 multicast);
  1048. int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  1049. bool set);
  1050. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  1051. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1052. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1053. struct ieee80211_key_conf *key);
  1054. #else
  1055. #define rt2x00mac_set_key NULL
  1056. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  1057. void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw);
  1058. void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw);
  1059. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  1060. struct ieee80211_low_level_stats *stats);
  1061. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  1062. struct ieee80211_vif *vif,
  1063. struct ieee80211_bss_conf *bss_conf,
  1064. u32 changes);
  1065. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1066. const struct ieee80211_tx_queue_params *params);
  1067. void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
  1068. void rt2x00mac_flush(struct ieee80211_hw *hw, bool drop);
  1069. /*
  1070. * Driver allocation handlers.
  1071. */
  1072. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  1073. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  1074. #ifdef CONFIG_PM
  1075. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  1076. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  1077. #endif /* CONFIG_PM */
  1078. #endif /* RT2X00_H */