rt2x00.h 32 KB

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