rt2x00.h 26 KB

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