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