rt2x00.h 26 KB

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