rt2x00.h 26 KB

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