rt2x00.h 25 KB

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