rt2x00.h 27 KB

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