rt2x00.h 27 KB

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