rt2x00.h 28 KB

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