rt2x00.h 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00
  19. Abstract: rt2x00 global information.
  20. */
  21. #ifndef RT2X00_H
  22. #define RT2X00_H
  23. #include <linux/bitops.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/firmware.h>
  27. #include <linux/leds.h>
  28. #include <linux/mutex.h>
  29. #include <linux/etherdevice.h>
  30. #include <net/mac80211.h>
  31. #include "rt2x00debug.h"
  32. #include "rt2x00leds.h"
  33. #include "rt2x00reg.h"
  34. #include "rt2x00queue.h"
  35. /*
  36. * Module information.
  37. */
  38. #define DRV_VERSION "2.1.6"
  39. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  40. /*
  41. * Debug definitions.
  42. * Debug output has to be enabled during compile time.
  43. */
  44. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  45. printk(__kernlvl "%s -> %s: %s - " __msg, \
  46. wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
  47. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  48. printk(__kernlvl "%s -> %s: %s - " __msg, \
  49. KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args)
  50. #ifdef CONFIG_RT2X00_DEBUG
  51. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  52. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
  53. #else
  54. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  55. do { } while (0)
  56. #endif /* CONFIG_RT2X00_DEBUG */
  57. /*
  58. * Various debug levels.
  59. * The debug levels PANIC and ERROR both indicate serious problems,
  60. * for this reason they should never be ignored.
  61. * The special ERROR_PROBE message is for messages that are generated
  62. * when the rt2x00_dev is not yet initialized.
  63. */
  64. #define PANIC(__dev, __msg, __args...) \
  65. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  66. #define ERROR(__dev, __msg, __args...) \
  67. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  68. #define ERROR_PROBE(__msg, __args...) \
  69. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  70. #define WARNING(__dev, __msg, __args...) \
  71. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  72. #define NOTICE(__dev, __msg, __args...) \
  73. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  74. #define INFO(__dev, __msg, __args...) \
  75. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  76. #define DEBUG(__dev, __msg, __args...) \
  77. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  78. #define EEPROM(__dev, __msg, __args...) \
  79. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  80. /*
  81. * Standard timing and size defines.
  82. * These values should follow the ieee80211 specifications.
  83. */
  84. #define ACK_SIZE 14
  85. #define IEEE80211_HEADER 24
  86. #define PLCP 48
  87. #define BEACON 100
  88. #define PREAMBLE 144
  89. #define SHORT_PREAMBLE 72
  90. #define SLOT_TIME 20
  91. #define SHORT_SLOT_TIME 9
  92. #define SIFS 10
  93. #define PIFS ( SIFS + SLOT_TIME )
  94. #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
  95. #define DIFS ( PIFS + SLOT_TIME )
  96. #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
  97. #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
  98. /*
  99. * IEEE802.11 header defines
  100. */
  101. static inline int is_rts_frame(u16 fc)
  102. {
  103. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  104. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS));
  105. }
  106. static inline int is_cts_frame(u16 fc)
  107. {
  108. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  109. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS));
  110. }
  111. static inline int is_probe_resp(u16 fc)
  112. {
  113. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
  114. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP));
  115. }
  116. static inline int is_beacon(u16 fc)
  117. {
  118. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
  119. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON));
  120. }
  121. /*
  122. * Chipset identification
  123. * The chipset on the device is composed of a RT and RF chip.
  124. * The chipset combination is important for determining device capabilities.
  125. */
  126. struct rt2x00_chip {
  127. u16 rt;
  128. #define RT2460 0x0101
  129. #define RT2560 0x0201
  130. #define RT2570 0x1201
  131. #define RT2561s 0x0301 /* Turbo */
  132. #define RT2561 0x0302
  133. #define RT2661 0x0401
  134. #define RT2571 0x1300
  135. u16 rf;
  136. u32 rev;
  137. };
  138. /*
  139. * RF register values that belong to a particular channel.
  140. */
  141. struct rf_channel {
  142. int channel;
  143. u32 rf1;
  144. u32 rf2;
  145. u32 rf3;
  146. u32 rf4;
  147. };
  148. /*
  149. * Antenna setup values.
  150. */
  151. struct antenna_setup {
  152. enum antenna rx;
  153. enum antenna tx;
  154. };
  155. /*
  156. * Quality statistics about the currently active link.
  157. */
  158. struct link_qual {
  159. /*
  160. * Statistics required for Link tuning.
  161. * For the average RSSI value we use the "Walking average" approach.
  162. * When adding RSSI to the average value the following calculation
  163. * is needed:
  164. *
  165. * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
  166. *
  167. * The advantage of this approach is that we only need 1 variable
  168. * to store the average in (No need for a count and a total).
  169. * But more importantly, normal average values will over time
  170. * move less and less towards newly added values this results
  171. * that with link tuning, the device can have a very good RSSI
  172. * for a few minutes but when the device is moved away from the AP
  173. * the average will not decrease fast enough to compensate.
  174. * The walking average compensates this and will move towards
  175. * the new values correctly allowing a effective link tuning.
  176. */
  177. int avg_rssi;
  178. int false_cca;
  179. /*
  180. * Statistics required for Signal quality calculation.
  181. * For calculating the Signal quality we have to determine
  182. * the total number of success and failed RX and TX frames.
  183. * After that we also use the average RSSI value to help
  184. * determining the signal quality.
  185. * For the calculation we will use the following algorithm:
  186. *
  187. * rssi_percentage = (avg_rssi * 100) / rssi_offset
  188. * rx_percentage = (rx_success * 100) / rx_total
  189. * tx_percentage = (tx_success * 100) / tx_total
  190. * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
  191. * (WEIGHT_TX * tx_percentage) +
  192. * (WEIGHT_RX * rx_percentage)) / 100
  193. *
  194. * This value should then be checked to not be greated then 100.
  195. */
  196. int rx_percentage;
  197. int rx_success;
  198. int rx_failed;
  199. int tx_percentage;
  200. int tx_success;
  201. int tx_failed;
  202. #define WEIGHT_RSSI 20
  203. #define WEIGHT_RX 40
  204. #define WEIGHT_TX 40
  205. };
  206. /*
  207. * Antenna settings about the currently active link.
  208. */
  209. struct link_ant {
  210. /*
  211. * Antenna flags
  212. */
  213. unsigned int flags;
  214. #define ANTENNA_RX_DIVERSITY 0x00000001
  215. #define ANTENNA_TX_DIVERSITY 0x00000002
  216. #define ANTENNA_MODE_SAMPLE 0x00000004
  217. /*
  218. * Currently active TX/RX antenna setup.
  219. * When software diversity is used, this will indicate
  220. * which antenna is actually used at this time.
  221. */
  222. struct antenna_setup active;
  223. /*
  224. * RSSI information for the different antenna's.
  225. * These statistics are used to determine when
  226. * to switch antenna when using software diversity.
  227. *
  228. * rssi[0] -> Antenna A RSSI
  229. * rssi[1] -> Antenna B RSSI
  230. */
  231. int rssi_history[2];
  232. /*
  233. * Current RSSI average of the currently active antenna.
  234. * Similar to the avg_rssi in the link_qual structure
  235. * this value is updated by using the walking average.
  236. */
  237. int rssi_ant;
  238. };
  239. /*
  240. * To optimize the quality of the link we need to store
  241. * the quality of received frames and periodically
  242. * optimize the link.
  243. */
  244. struct link {
  245. /*
  246. * Link tuner counter
  247. * The number of times the link has been tuned
  248. * since the radio has been switched on.
  249. */
  250. u32 count;
  251. /*
  252. * Quality measurement values.
  253. */
  254. struct link_qual qual;
  255. /*
  256. * TX/RX antenna setup.
  257. */
  258. struct link_ant ant;
  259. /*
  260. * Active VGC level
  261. */
  262. int vgc_level;
  263. /*
  264. * Work structure for scheduling periodic link tuning.
  265. */
  266. struct delayed_work work;
  267. };
  268. /*
  269. * Small helper macro to work with moving/walking averages.
  270. */
  271. #define MOVING_AVERAGE(__avg, __val, __samples) \
  272. ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
  273. /*
  274. * When we lack RSSI information return something less then -80 to
  275. * tell the driver to tune the device to maximum sensitivity.
  276. */
  277. #define DEFAULT_RSSI ( -128 )
  278. /*
  279. * Link quality access functions.
  280. */
  281. static inline int rt2x00_get_link_rssi(struct link *link)
  282. {
  283. if (link->qual.avg_rssi && link->qual.rx_success)
  284. return link->qual.avg_rssi;
  285. return DEFAULT_RSSI;
  286. }
  287. static inline int rt2x00_get_link_ant_rssi(struct link *link)
  288. {
  289. if (link->ant.rssi_ant && link->qual.rx_success)
  290. return link->ant.rssi_ant;
  291. return DEFAULT_RSSI;
  292. }
  293. static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
  294. enum antenna ant)
  295. {
  296. if (link->ant.rssi_history[ant - ANTENNA_A])
  297. return link->ant.rssi_history[ant - ANTENNA_A];
  298. return DEFAULT_RSSI;
  299. }
  300. static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
  301. {
  302. int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
  303. link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
  304. return old_rssi;
  305. }
  306. /*
  307. * Interface structure
  308. * Per interface configuration details, this structure
  309. * is allocated as the private data for ieee80211_vif.
  310. */
  311. struct rt2x00_intf {
  312. /*
  313. * All fields within the rt2x00_intf structure
  314. * must be protected with a spinlock.
  315. */
  316. spinlock_t lock;
  317. /*
  318. * BSS configuration. Copied from the structure
  319. * passed to us through the bss_info_changed()
  320. * callback funtion.
  321. */
  322. struct ieee80211_bss_conf conf;
  323. /*
  324. * MAC of the device.
  325. */
  326. u8 mac[ETH_ALEN];
  327. /*
  328. * BBSID of the AP to associate with.
  329. */
  330. u8 bssid[ETH_ALEN];
  331. /*
  332. * Entry in the beacon queue which belongs to
  333. * this interface. Each interface has its own
  334. * dedicated beacon entry.
  335. */
  336. struct queue_entry *beacon;
  337. /*
  338. * Actions that needed rescheduling.
  339. */
  340. unsigned int delayed_flags;
  341. #define DELAYED_UPDATE_BEACON 0x00000001
  342. #define DELAYED_CONFIG_ERP 0x00000002
  343. #define DELAYED_LED_ASSOC 0x00000004
  344. };
  345. static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
  346. {
  347. return (struct rt2x00_intf *)vif->drv_priv;
  348. }
  349. /**
  350. * struct hw_mode_spec: Hardware specifications structure
  351. *
  352. * Details about the supported modes, rates and channels
  353. * of a particular chipset. This is used by rt2x00lib
  354. * to build the ieee80211_hw_mode array for mac80211.
  355. *
  356. * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
  357. * @supported_rates: Rate types which are supported (CCK, OFDM).
  358. * @num_channels: Number of supported channels. This is used as array size
  359. * for @tx_power_a, @tx_power_bg and @channels.
  360. * @channels: Device/chipset specific channel values (See &struct rf_channel).
  361. * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
  362. * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
  363. * @tx_power_default: Default TX power value to use when either
  364. * @tx_power_a or @tx_power_bg is missing.
  365. */
  366. struct hw_mode_spec {
  367. unsigned int supported_bands;
  368. #define SUPPORT_BAND_2GHZ 0x00000001
  369. #define SUPPORT_BAND_5GHZ 0x00000002
  370. unsigned int supported_rates;
  371. #define SUPPORT_RATE_CCK 0x00000001
  372. #define SUPPORT_RATE_OFDM 0x00000002
  373. unsigned int num_channels;
  374. const struct rf_channel *channels;
  375. const u8 *tx_power_a;
  376. const u8 *tx_power_bg;
  377. u8 tx_power_default;
  378. };
  379. /*
  380. * Configuration structure wrapper around the
  381. * mac80211 configuration structure.
  382. * When mac80211 configures the driver, rt2x00lib
  383. * can precalculate values which are equal for all
  384. * rt2x00 drivers. Those values can be stored in here.
  385. */
  386. struct rt2x00lib_conf {
  387. struct ieee80211_conf *conf;
  388. struct rf_channel rf;
  389. struct antenna_setup ant;
  390. enum ieee80211_band band;
  391. u32 basic_rates;
  392. u32 slot_time;
  393. short sifs;
  394. short pifs;
  395. short difs;
  396. short eifs;
  397. };
  398. /*
  399. * Configuration structure for erp settings.
  400. */
  401. struct rt2x00lib_erp {
  402. int short_preamble;
  403. int ack_timeout;
  404. int ack_consume_time;
  405. };
  406. /*
  407. * Configuration structure wrapper around the
  408. * rt2x00 interface configuration handler.
  409. */
  410. struct rt2x00intf_conf {
  411. /*
  412. * Interface type
  413. */
  414. enum ieee80211_if_types type;
  415. /*
  416. * TSF sync value, this is dependant on the operation type.
  417. */
  418. enum tsf_sync sync;
  419. /*
  420. * The MAC and BSSID addressess are simple array of bytes,
  421. * these arrays are little endian, so when sending the addressess
  422. * to the drivers, copy the it into a endian-signed variable.
  423. *
  424. * Note that all devices (except rt2500usb) have 32 bits
  425. * register word sizes. This means that whatever variable we
  426. * pass _must_ be a multiple of 32 bits. Otherwise the device
  427. * might not accept what we are sending to it.
  428. * This will also make it easier for the driver to write
  429. * the data to the device.
  430. */
  431. __le32 mac[2];
  432. __le32 bssid[2];
  433. };
  434. /*
  435. * rt2x00lib callback functions.
  436. */
  437. struct rt2x00lib_ops {
  438. /*
  439. * Interrupt handlers.
  440. */
  441. irq_handler_t irq_handler;
  442. /*
  443. * Device init handlers.
  444. */
  445. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  446. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  447. u16 (*get_firmware_crc) (void *data, const size_t len);
  448. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
  449. const size_t len);
  450. /*
  451. * Device initialization/deinitialization handlers.
  452. */
  453. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  454. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  455. /*
  456. * queue initialization handlers
  457. */
  458. void (*init_rxentry) (struct rt2x00_dev *rt2x00dev,
  459. struct queue_entry *entry);
  460. void (*init_txentry) (struct rt2x00_dev *rt2x00dev,
  461. struct queue_entry *entry);
  462. /*
  463. * Radio control handlers.
  464. */
  465. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  466. enum dev_state state);
  467. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  468. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  469. struct link_qual *qual);
  470. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
  471. void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
  472. /*
  473. * TX control handlers
  474. */
  475. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  476. struct sk_buff *skb,
  477. struct txentry_desc *txdesc);
  478. int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
  479. struct data_queue *queue, struct sk_buff *skb);
  480. int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
  481. struct sk_buff *skb);
  482. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  483. const enum data_queue_qid queue);
  484. /*
  485. * RX control handlers
  486. */
  487. void (*fill_rxdone) (struct queue_entry *entry,
  488. struct rxdone_entry_desc *rxdesc);
  489. /*
  490. * Configuration handlers.
  491. */
  492. void (*config_filter) (struct rt2x00_dev *rt2x00dev,
  493. const unsigned int filter_flags);
  494. void (*config_intf) (struct rt2x00_dev *rt2x00dev,
  495. struct rt2x00_intf *intf,
  496. struct rt2x00intf_conf *conf,
  497. const unsigned int flags);
  498. #define CONFIG_UPDATE_TYPE ( 1 << 1 )
  499. #define CONFIG_UPDATE_MAC ( 1 << 2 )
  500. #define CONFIG_UPDATE_BSSID ( 1 << 3 )
  501. void (*config_erp) (struct rt2x00_dev *rt2x00dev,
  502. struct rt2x00lib_erp *erp);
  503. void (*config) (struct rt2x00_dev *rt2x00dev,
  504. struct rt2x00lib_conf *libconf,
  505. const unsigned int flags);
  506. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  507. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  508. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  509. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  510. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  511. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  512. #define CONFIG_UPDATE_ALL 0xffff
  513. };
  514. /*
  515. * rt2x00 driver callback operation structure.
  516. */
  517. struct rt2x00_ops {
  518. const char *name;
  519. const unsigned int max_sta_intf;
  520. const unsigned int max_ap_intf;
  521. const unsigned int eeprom_size;
  522. const unsigned int rf_size;
  523. const unsigned int tx_queues;
  524. const struct data_queue_desc *rx;
  525. const struct data_queue_desc *tx;
  526. const struct data_queue_desc *bcn;
  527. const struct data_queue_desc *atim;
  528. const struct rt2x00lib_ops *lib;
  529. const struct ieee80211_ops *hw;
  530. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  531. const struct rt2x00debug *debugfs;
  532. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  533. };
  534. /*
  535. * rt2x00 device flags
  536. */
  537. enum rt2x00_flags {
  538. /*
  539. * Device state flags
  540. */
  541. DEVICE_PRESENT,
  542. DEVICE_REGISTERED_HW,
  543. DEVICE_INITIALIZED,
  544. DEVICE_STARTED,
  545. DEVICE_STARTED_SUSPEND,
  546. DEVICE_ENABLED_RADIO,
  547. DEVICE_DISABLED_RADIO_HW,
  548. /*
  549. * Driver features
  550. */
  551. DRIVER_REQUIRE_FIRMWARE,
  552. DRIVER_REQUIRE_BEACON_GUARD,
  553. DRIVER_REQUIRE_ATIM_QUEUE,
  554. DRIVER_REQUIRE_SCHEDULED,
  555. /*
  556. * Driver configuration
  557. */
  558. CONFIG_SUPPORT_HW_BUTTON,
  559. CONFIG_FRAME_TYPE,
  560. CONFIG_RF_SEQUENCE,
  561. CONFIG_EXTERNAL_LNA_A,
  562. CONFIG_EXTERNAL_LNA_BG,
  563. CONFIG_DOUBLE_ANTENNA,
  564. CONFIG_DISABLE_LINK_TUNING,
  565. };
  566. /*
  567. * rt2x00 device structure.
  568. */
  569. struct rt2x00_dev {
  570. /*
  571. * Device structure.
  572. * The structure stored in here depends on the
  573. * system bus (PCI or USB).
  574. * When accessing this variable, the rt2x00dev_{pci,usb}
  575. * macro's should be used for correct typecasting.
  576. */
  577. void *dev;
  578. #define rt2x00dev_pci(__dev) ( (struct pci_dev *)(__dev)->dev )
  579. #define rt2x00dev_usb(__dev) ( (struct usb_interface *)(__dev)->dev )
  580. #define rt2x00dev_usb_dev(__dev)\
  581. ( (struct usb_device *)interface_to_usbdev(rt2x00dev_usb(__dev)) )
  582. /*
  583. * Callback functions.
  584. */
  585. const struct rt2x00_ops *ops;
  586. /*
  587. * IEEE80211 control structure.
  588. */
  589. struct ieee80211_hw *hw;
  590. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  591. enum ieee80211_band curr_band;
  592. /*
  593. * rfkill structure for RF state switching support.
  594. * This will only be compiled in when required.
  595. */
  596. #ifdef CONFIG_RT2X00_LIB_RFKILL
  597. unsigned long rfkill_state;
  598. #define RFKILL_STATE_ALLOCATED 1
  599. #define RFKILL_STATE_REGISTERED 2
  600. struct rfkill *rfkill;
  601. struct input_polled_dev *poll_dev;
  602. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  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. * Chipset identification.
  628. */
  629. struct rt2x00_chip chip;
  630. /*
  631. * hw capability specifications.
  632. */
  633. struct hw_mode_spec spec;
  634. /*
  635. * This is the default TX/RX antenna setup as indicated
  636. * by the device's EEPROM. When mac80211 sets its
  637. * antenna value to 0 we should be using these values.
  638. */
  639. struct antenna_setup default_ant;
  640. /*
  641. * Register pointers
  642. * csr.base: CSR base register address. (PCI)
  643. * csr.cache: CSR cache for usb_control_msg. (USB)
  644. */
  645. union csr {
  646. void __iomem *base;
  647. void *cache;
  648. } csr;
  649. /*
  650. * Mutex to protect register accesses on USB devices.
  651. * There are 2 reasons this is needed, one is to ensure
  652. * use of the csr_cache (for USB devices) by one thread
  653. * isn't corrupted by another thread trying to access it.
  654. * The other is that access to BBP and RF registers
  655. * require multiple BUS transactions and if another thread
  656. * attempted to access one of those registers at the same
  657. * time one of the writes could silently fail.
  658. */
  659. struct mutex usb_cache_mutex;
  660. /*
  661. * Current packet filter configuration for the device.
  662. * This contains all currently active FIF_* flags send
  663. * to us by mac80211 during configure_filter().
  664. */
  665. unsigned int packet_filter;
  666. /*
  667. * Interface details:
  668. * - Open ap interface count.
  669. * - Open sta interface count.
  670. * - Association count.
  671. */
  672. unsigned int intf_ap_count;
  673. unsigned int intf_sta_count;
  674. unsigned int intf_associated;
  675. /*
  676. * Link quality
  677. */
  678. struct link link;
  679. /*
  680. * EEPROM data.
  681. */
  682. __le16 *eeprom;
  683. /*
  684. * Active RF register values.
  685. * These are stored here so we don't need
  686. * to read the rf registers and can directly
  687. * use this value instead.
  688. * This field should be accessed by using
  689. * rt2x00_rf_read() and rt2x00_rf_write().
  690. */
  691. u32 *rf;
  692. /*
  693. * USB Max frame size (for rt2500usb & rt73usb).
  694. */
  695. u16 usb_maxpacket;
  696. /*
  697. * Current TX power value.
  698. */
  699. u16 tx_power;
  700. /*
  701. * Rssi <-> Dbm offset
  702. */
  703. u8 rssi_offset;
  704. /*
  705. * Frequency offset (for rt61pci & rt73usb).
  706. */
  707. u8 freq_offset;
  708. /*
  709. * Low level statistics which will have
  710. * to be kept up to date while device is running.
  711. */
  712. struct ieee80211_low_level_stats low_level_stats;
  713. /*
  714. * RX configuration information.
  715. */
  716. struct ieee80211_rx_status rx_status;
  717. /*
  718. * Scheduled work.
  719. */
  720. struct work_struct intf_work;
  721. struct work_struct filter_work;
  722. /*
  723. * Data queue arrays for RX, TX and Beacon.
  724. * The Beacon array also contains the Atim queue
  725. * if that is supported by the device.
  726. */
  727. int data_queues;
  728. struct data_queue *rx;
  729. struct data_queue *tx;
  730. struct data_queue *bcn;
  731. /*
  732. * Firmware image.
  733. */
  734. const struct firmware *fw;
  735. };
  736. /*
  737. * Generic RF access.
  738. * The RF is being accessed by word index.
  739. */
  740. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  741. const unsigned int word, u32 *data)
  742. {
  743. *data = rt2x00dev->rf[word];
  744. }
  745. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  746. const unsigned int word, u32 data)
  747. {
  748. rt2x00dev->rf[word] = data;
  749. }
  750. /*
  751. * Generic EEPROM access.
  752. * The EEPROM is being accessed by word index.
  753. */
  754. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  755. const unsigned int word)
  756. {
  757. return (void *)&rt2x00dev->eeprom[word];
  758. }
  759. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  760. const unsigned int word, u16 *data)
  761. {
  762. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  763. }
  764. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  765. const unsigned int word, u16 data)
  766. {
  767. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  768. }
  769. /*
  770. * Chipset handlers
  771. */
  772. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  773. const u16 rt, const u16 rf, const u32 rev)
  774. {
  775. INFO(rt2x00dev,
  776. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  777. rt, rf, rev);
  778. rt2x00dev->chip.rt = rt;
  779. rt2x00dev->chip.rf = rf;
  780. rt2x00dev->chip.rev = rev;
  781. }
  782. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  783. {
  784. return (chipset->rt == chip);
  785. }
  786. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  787. {
  788. return (chipset->rf == chip);
  789. }
  790. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  791. {
  792. return chipset->rev;
  793. }
  794. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  795. const u32 rev)
  796. {
  797. return (((chipset->rev & 0xffff0) == rev) &&
  798. !!(chipset->rev & 0x0000f));
  799. }
  800. /*
  801. * Duration calculations
  802. * The rate variable passed is: 100kbs.
  803. * To convert from bytes to bits we multiply size with 8,
  804. * then the size is multiplied with 10 to make the
  805. * real rate -> rate argument correction.
  806. */
  807. static inline u16 get_duration(const unsigned int size, const u8 rate)
  808. {
  809. return ((size * 8 * 10) / rate);
  810. }
  811. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  812. {
  813. return ((size * 8 * 10) % rate);
  814. }
  815. /**
  816. * rt2x00queue_create_tx_descriptor - Create TX descriptor from mac80211 input
  817. * @entry: The entry which will be used to transfer the TX frame.
  818. * @txdesc: rt2x00 TX descriptor which will be initialized by this function.
  819. *
  820. * This function will initialize the &struct txentry_desc based on information
  821. * from mac80211. This descriptor can then be used by rt2x00lib and the drivers
  822. * to correctly initialize the hardware descriptor.
  823. * Note that before calling this function the skb->cb array must be untouched
  824. * by rt2x00lib. Only after this function completes will it be save to
  825. * overwrite the skb->cb information.
  826. * The reason for this is that mac80211 writes its own tx information into
  827. * the skb->cb array, and this function will use that information to initialize
  828. * the &struct txentry_desc structure.
  829. */
  830. void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
  831. struct txentry_desc *txdesc);
  832. /**
  833. * rt2x00queue_write_tx_descriptor - Write TX descriptor to hardware
  834. * @entry: The entry which will be used to transfer the TX frame.
  835. * @txdesc: TX descriptor which will be used to write hardware descriptor
  836. *
  837. * This function will write a TX descriptor initialized by
  838. * &rt2x00queue_create_tx_descriptor to the hardware. After this call
  839. * has completed the frame is now owned by the hardware, the hardware
  840. * queue will have automatically be kicked unless this frame was generated
  841. * by rt2x00lib, in which case the frame is "special" and must be kicked
  842. * by the caller.
  843. */
  844. void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
  845. struct txentry_desc *txdesc);
  846. /**
  847. * rt2x00queue_get_queue - Convert queue index to queue pointer
  848. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  849. * @queue: rt2x00 queue index (see &enum data_queue_qid).
  850. */
  851. struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
  852. const enum data_queue_qid queue);
  853. /**
  854. * rt2x00queue_get_entry - Get queue entry where the given index points to.
  855. * @queue: Pointer to &struct data_queue from where we obtain the entry.
  856. * @index: Index identifier for obtaining the correct index.
  857. */
  858. struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
  859. enum queue_index index);
  860. /**
  861. * rt2x00queue_index_inc - Index incrementation function
  862. * @queue: Queue (&struct data_queue) to perform the action on.
  863. * @index: Index type (&enum queue_index) to perform the action on.
  864. *
  865. * This function will increase the requested index on the queue,
  866. * it will grab the appropriate locks and handle queue overflow events by
  867. * resetting the index to the start of the queue.
  868. */
  869. void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
  870. /*
  871. * Interrupt context handlers.
  872. */
  873. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  874. void rt2x00lib_txdone(struct queue_entry *entry,
  875. struct txdone_entry_desc *txdesc);
  876. void rt2x00lib_rxdone(struct queue_entry *entry,
  877. struct rxdone_entry_desc *rxdesc);
  878. /*
  879. * mac80211 handlers.
  880. */
  881. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  882. int rt2x00mac_start(struct ieee80211_hw *hw);
  883. void rt2x00mac_stop(struct ieee80211_hw *hw);
  884. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  885. struct ieee80211_if_init_conf *conf);
  886. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  887. struct ieee80211_if_init_conf *conf);
  888. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  889. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  890. struct ieee80211_vif *vif,
  891. struct ieee80211_if_conf *conf);
  892. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  893. unsigned int changed_flags,
  894. unsigned int *total_flags,
  895. int mc_count, struct dev_addr_list *mc_list);
  896. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  897. struct ieee80211_low_level_stats *stats);
  898. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  899. struct ieee80211_tx_queue_stats *stats);
  900. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  901. struct ieee80211_vif *vif,
  902. struct ieee80211_bss_conf *bss_conf,
  903. u32 changes);
  904. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  905. const struct ieee80211_tx_queue_params *params);
  906. /*
  907. * Driver allocation handlers.
  908. */
  909. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  910. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  911. #ifdef CONFIG_PM
  912. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  913. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  914. #endif /* CONFIG_PM */
  915. #endif /* RT2X00_H */