rt2x00.h 26 KB

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