rt2x00.h 28 KB

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