rt2x00.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*
  2. Copyright (C) 2004 - 2007 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/prefetch.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/firmware.h>
  28. #include <linux/mutex.h>
  29. #include <net/mac80211.h>
  30. #include "rt2x00debug.h"
  31. #include "rt2x00reg.h"
  32. #include "rt2x00ring.h"
  33. /*
  34. * Module information.
  35. * DRV_NAME should be set within the individual module source files.
  36. */
  37. #define DRV_VERSION "2.0.12"
  38. #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
  39. /*
  40. * Debug definitions.
  41. * Debug output has to be enabled during compile time.
  42. */
  43. #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
  44. printk(__kernlvl "%s -> %s: %s - " __msg, \
  45. wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
  46. #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
  47. printk(__kernlvl "%s -> %s: %s - " __msg, \
  48. DRV_NAME, __FUNCTION__, __lvl, ##__args)
  49. #ifdef CONFIG_RT2X00_DEBUG
  50. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  51. DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
  52. #else
  53. #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
  54. do { } while (0)
  55. #endif /* CONFIG_RT2X00_DEBUG */
  56. /*
  57. * Various debug levels.
  58. * The debug levels PANIC and ERROR both indicate serious problems,
  59. * for this reason they should never be ignored.
  60. * The special ERROR_PROBE message is for messages that are generated
  61. * when the rt2x00_dev is not yet initialized.
  62. */
  63. #define PANIC(__dev, __msg, __args...) \
  64. DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
  65. #define ERROR(__dev, __msg, __args...) \
  66. DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
  67. #define ERROR_PROBE(__msg, __args...) \
  68. DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
  69. #define WARNING(__dev, __msg, __args...) \
  70. DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
  71. #define NOTICE(__dev, __msg, __args...) \
  72. DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
  73. #define INFO(__dev, __msg, __args...) \
  74. DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
  75. #define DEBUG(__dev, __msg, __args...) \
  76. DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
  77. #define EEPROM(__dev, __msg, __args...) \
  78. DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
  79. /*
  80. * Ring sizes.
  81. * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes.
  82. * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings.
  83. * MGMT_FRAME_SIZE is used for the BEACON ring.
  84. */
  85. #define DATA_FRAME_SIZE 2432
  86. #define MGMT_FRAME_SIZE 256
  87. /*
  88. * Number of entries in a packet ring.
  89. * PCI devices only need 1 Beacon entry,
  90. * but USB devices require a second because they
  91. * have to send a Guardian byte first.
  92. */
  93. #define RX_ENTRIES 12
  94. #define TX_ENTRIES 12
  95. #define ATIM_ENTRIES 1
  96. #define BEACON_ENTRIES 2
  97. /*
  98. * Standard timing and size defines.
  99. * These values should follow the ieee80211 specifications.
  100. */
  101. #define ACK_SIZE 14
  102. #define IEEE80211_HEADER 24
  103. #define PLCP 48
  104. #define BEACON 100
  105. #define PREAMBLE 144
  106. #define SHORT_PREAMBLE 72
  107. #define SLOT_TIME 20
  108. #define SHORT_SLOT_TIME 9
  109. #define SIFS 10
  110. #define PIFS ( SIFS + SLOT_TIME )
  111. #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
  112. #define DIFS ( PIFS + SLOT_TIME )
  113. #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
  114. #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
  115. /*
  116. * IEEE802.11 header defines
  117. */
  118. static inline int is_rts_frame(u16 fc)
  119. {
  120. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  121. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS));
  122. }
  123. static inline int is_cts_frame(u16 fc)
  124. {
  125. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  126. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS));
  127. }
  128. static inline int is_probe_resp(u16 fc)
  129. {
  130. return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
  131. ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP));
  132. }
  133. /*
  134. * Chipset identification
  135. * The chipset on the device is composed of a RT and RF chip.
  136. * The chipset combination is important for determining device capabilities.
  137. */
  138. struct rt2x00_chip {
  139. u16 rt;
  140. #define RT2460 0x0101
  141. #define RT2560 0x0201
  142. #define RT2570 0x1201
  143. #define RT2561s 0x0301 /* Turbo */
  144. #define RT2561 0x0302
  145. #define RT2661 0x0401
  146. #define RT2571 0x1300
  147. u16 rf;
  148. u32 rev;
  149. };
  150. /*
  151. * RF register values that belong to a particular channel.
  152. */
  153. struct rf_channel {
  154. int channel;
  155. u32 rf1;
  156. u32 rf2;
  157. u32 rf3;
  158. u32 rf4;
  159. };
  160. /*
  161. * Antenna setup values.
  162. */
  163. struct antenna_setup {
  164. enum antenna rx;
  165. enum antenna tx;
  166. };
  167. /*
  168. * Quality statistics about the currently active link.
  169. */
  170. struct link_qual {
  171. /*
  172. * Statistics required for Link tuning.
  173. * For the average RSSI value we use the "Walking average" approach.
  174. * When adding RSSI to the average value the following calculation
  175. * is needed:
  176. *
  177. * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
  178. *
  179. * The advantage of this approach is that we only need 1 variable
  180. * to store the average in (No need for a count and a total).
  181. * But more importantly, normal average values will over time
  182. * move less and less towards newly added values this results
  183. * that with link tuning, the device can have a very good RSSI
  184. * for a few minutes but when the device is moved away from the AP
  185. * the average will not decrease fast enough to compensate.
  186. * The walking average compensates this and will move towards
  187. * the new values correctly allowing a effective link tuning.
  188. */
  189. int avg_rssi;
  190. int false_cca;
  191. /*
  192. * Statistics required for Signal quality calculation.
  193. * For calculating the Signal quality we have to determine
  194. * the total number of success and failed RX and TX frames.
  195. * After that we also use the average RSSI value to help
  196. * determining the signal quality.
  197. * For the calculation we will use the following algorithm:
  198. *
  199. * rssi_percentage = (avg_rssi * 100) / rssi_offset
  200. * rx_percentage = (rx_success * 100) / rx_total
  201. * tx_percentage = (tx_success * 100) / tx_total
  202. * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
  203. * (WEIGHT_TX * tx_percentage) +
  204. * (WEIGHT_RX * rx_percentage)) / 100
  205. *
  206. * This value should then be checked to not be greated then 100.
  207. */
  208. int rx_percentage;
  209. int rx_success;
  210. int rx_failed;
  211. int tx_percentage;
  212. int tx_success;
  213. int tx_failed;
  214. #define WEIGHT_RSSI 20
  215. #define WEIGHT_RX 40
  216. #define WEIGHT_TX 40
  217. };
  218. /*
  219. * Antenna settings about the currently active link.
  220. */
  221. struct link_ant {
  222. /*
  223. * Antenna flags
  224. */
  225. unsigned int flags;
  226. #define ANTENNA_RX_DIVERSITY 0x00000001
  227. #define ANTENNA_TX_DIVERSITY 0x00000002
  228. #define ANTENNA_MODE_SAMPLE 0x00000004
  229. /*
  230. * Currently active TX/RX antenna setup.
  231. * When software diversity is used, this will indicate
  232. * which antenna is actually used at this time.
  233. */
  234. struct antenna_setup active;
  235. /*
  236. * RSSI information for the different antenna's.
  237. * These statistics are used to determine when
  238. * to switch antenna when using software diversity.
  239. *
  240. * rssi[0] -> Antenna A RSSI
  241. * rssi[1] -> Antenna B RSSI
  242. */
  243. int rssi_history[2];
  244. /*
  245. * Current RSSI average of the currently active antenna.
  246. * Similar to the avg_rssi in the link_qual structure
  247. * this value is updated by using the walking average.
  248. */
  249. int rssi_ant;
  250. };
  251. /*
  252. * To optimize the quality of the link we need to store
  253. * the quality of received frames and periodically
  254. * optimize the link.
  255. */
  256. struct link {
  257. /*
  258. * Link tuner counter
  259. * The number of times the link has been tuned
  260. * since the radio has been switched on.
  261. */
  262. u32 count;
  263. /*
  264. * Quality measurement values.
  265. */
  266. struct link_qual qual;
  267. /*
  268. * TX/RX antenna setup.
  269. */
  270. struct link_ant ant;
  271. /*
  272. * Active VGC level
  273. */
  274. int vgc_level;
  275. /*
  276. * Work structure for scheduling periodic link tuning.
  277. */
  278. struct delayed_work work;
  279. };
  280. /*
  281. * Small helper macro to work with moving/walking averages.
  282. */
  283. #define MOVING_AVERAGE(__avg, __val, __samples) \
  284. ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
  285. /*
  286. * When we lack RSSI information return something less then -80 to
  287. * tell the driver to tune the device to maximum sensitivity.
  288. */
  289. #define DEFAULT_RSSI ( -128 )
  290. /*
  291. * Link quality access functions.
  292. */
  293. static inline int rt2x00_get_link_rssi(struct link *link)
  294. {
  295. if (link->qual.avg_rssi && link->qual.rx_success)
  296. return link->qual.avg_rssi;
  297. return DEFAULT_RSSI;
  298. }
  299. static inline int rt2x00_get_link_ant_rssi(struct link *link)
  300. {
  301. if (link->ant.rssi_ant && link->qual.rx_success)
  302. return link->ant.rssi_ant;
  303. return DEFAULT_RSSI;
  304. }
  305. static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
  306. enum antenna ant)
  307. {
  308. if (link->ant.rssi_history[ant - ANTENNA_A])
  309. return link->ant.rssi_history[ant - ANTENNA_A];
  310. return DEFAULT_RSSI;
  311. }
  312. static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
  313. {
  314. int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
  315. link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
  316. return old_rssi;
  317. }
  318. /*
  319. * Interface structure
  320. * Configuration details about the current interface.
  321. */
  322. struct interface {
  323. /*
  324. * Interface identification. The value is assigned
  325. * to us by the 80211 stack, and is used to request
  326. * new beacons.
  327. */
  328. int id;
  329. /*
  330. * Current working type (IEEE80211_IF_TYPE_*).
  331. * When set to INVALID_INTERFACE, no interface is configured.
  332. */
  333. int type;
  334. #define INVALID_INTERFACE IEEE80211_IF_TYPE_INVALID
  335. /*
  336. * MAC of the device.
  337. */
  338. u8 mac[ETH_ALEN];
  339. /*
  340. * BBSID of the AP to associate with.
  341. */
  342. u8 bssid[ETH_ALEN];
  343. /*
  344. * Store the packet filter mode for the current interface.
  345. */
  346. unsigned int filter;
  347. };
  348. static inline int is_interface_present(struct interface *intf)
  349. {
  350. return !!intf->id;
  351. }
  352. static inline int is_interface_type(struct interface *intf, int type)
  353. {
  354. return intf->type == type;
  355. }
  356. /*
  357. * Details about the supported modes, rates and channels
  358. * of a particular chipset. This is used by rt2x00lib
  359. * to build the ieee80211_hw_mode array for mac80211.
  360. */
  361. struct hw_mode_spec {
  362. /*
  363. * Number of modes, rates and channels.
  364. */
  365. int num_modes;
  366. int num_rates;
  367. int num_channels;
  368. /*
  369. * txpower values.
  370. */
  371. const u8 *tx_power_a;
  372. const u8 *tx_power_bg;
  373. u8 tx_power_default;
  374. /*
  375. * Device/chipset specific value.
  376. */
  377. const struct rf_channel *channels;
  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. int phymode;
  391. int basic_rates;
  392. int slot_time;
  393. short sifs;
  394. short pifs;
  395. short difs;
  396. short eifs;
  397. };
  398. /*
  399. * rt2x00lib callback functions.
  400. */
  401. struct rt2x00lib_ops {
  402. /*
  403. * Interrupt handlers.
  404. */
  405. irq_handler_t irq_handler;
  406. /*
  407. * Device init handlers.
  408. */
  409. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  410. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  411. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
  412. const size_t len);
  413. /*
  414. * Device initialization/deinitialization handlers.
  415. */
  416. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  417. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  418. /*
  419. * Radio control handlers.
  420. */
  421. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  422. enum dev_state state);
  423. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  424. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  425. struct link_qual *qual);
  426. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
  427. void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
  428. /*
  429. * TX control handlers
  430. */
  431. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  432. __le32 *txd,
  433. struct txdata_entry_desc *desc,
  434. struct ieee80211_hdr *ieee80211hdr,
  435. unsigned int length,
  436. struct ieee80211_tx_control *control);
  437. int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
  438. struct data_ring *ring, struct sk_buff *skb,
  439. struct ieee80211_tx_control *control);
  440. int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
  441. struct sk_buff *skb);
  442. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  443. unsigned int queue);
  444. /*
  445. * RX control handlers
  446. */
  447. void (*fill_rxdone) (struct data_entry *entry,
  448. struct rxdata_entry_desc *desc);
  449. /*
  450. * Configuration handlers.
  451. */
  452. void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, __le32 *mac);
  453. void (*config_bssid) (struct rt2x00_dev *rt2x00dev, __le32 *bssid);
  454. void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type,
  455. const int tsf_sync);
  456. void (*config_preamble) (struct rt2x00_dev *rt2x00dev,
  457. const int short_preamble,
  458. const int ack_timeout,
  459. const int ack_consume_time);
  460. void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags,
  461. struct rt2x00lib_conf *libconf);
  462. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  463. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  464. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  465. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  466. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  467. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  468. #define CONFIG_UPDATE_ALL 0xffff
  469. };
  470. /*
  471. * rt2x00 driver callback operation structure.
  472. */
  473. struct rt2x00_ops {
  474. const char *name;
  475. const unsigned int rxd_size;
  476. const unsigned int txd_size;
  477. const unsigned int eeprom_size;
  478. const unsigned int rf_size;
  479. const struct rt2x00lib_ops *lib;
  480. const struct ieee80211_ops *hw;
  481. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  482. const struct rt2x00debug *debugfs;
  483. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  484. };
  485. /*
  486. * rt2x00 device flags
  487. */
  488. enum rt2x00_flags {
  489. /*
  490. * Device state flags
  491. */
  492. DEVICE_PRESENT,
  493. DEVICE_REGISTERED_HW,
  494. DEVICE_INITIALIZED,
  495. DEVICE_STARTED,
  496. DEVICE_STARTED_SUSPEND,
  497. DEVICE_ENABLED_RADIO,
  498. DEVICE_DISABLED_RADIO_HW,
  499. /*
  500. * Driver features
  501. */
  502. DRIVER_REQUIRE_FIRMWARE,
  503. DRIVER_REQUIRE_BEACON_RING,
  504. /*
  505. * Driver configuration
  506. */
  507. CONFIG_SUPPORT_HW_BUTTON,
  508. CONFIG_FRAME_TYPE,
  509. CONFIG_RF_SEQUENCE,
  510. CONFIG_EXTERNAL_LNA_A,
  511. CONFIG_EXTERNAL_LNA_BG,
  512. CONFIG_DOUBLE_ANTENNA,
  513. CONFIG_DISABLE_LINK_TUNING,
  514. CONFIG_SHORT_PREAMBLE,
  515. };
  516. /*
  517. * rt2x00 device structure.
  518. */
  519. struct rt2x00_dev {
  520. /*
  521. * Device structure.
  522. * The structure stored in here depends on the
  523. * system bus (PCI or USB).
  524. * When accessing this variable, the rt2x00dev_{pci,usb}
  525. * macro's should be used for correct typecasting.
  526. */
  527. void *dev;
  528. #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
  529. #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
  530. /*
  531. * Callback functions.
  532. */
  533. const struct rt2x00_ops *ops;
  534. /*
  535. * IEEE80211 control structure.
  536. */
  537. struct ieee80211_hw *hw;
  538. struct ieee80211_hw_mode *hwmodes;
  539. unsigned int curr_hwmode;
  540. #define HWMODE_B 0
  541. #define HWMODE_G 1
  542. #define HWMODE_A 2
  543. /*
  544. * rfkill structure for RF state switching support.
  545. * This will only be compiled in when required.
  546. */
  547. #ifdef CONFIG_RT2X00_LIB_RFKILL
  548. struct rfkill *rfkill;
  549. struct input_polled_dev *poll_dev;
  550. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  551. /*
  552. * If enabled, the debugfs interface structures
  553. * required for deregistration of debugfs.
  554. */
  555. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  556. const struct rt2x00debug_intf *debugfs_intf;
  557. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  558. /*
  559. * Device flags.
  560. * In these flags the current status and some
  561. * of the device capabilities are stored.
  562. */
  563. unsigned long flags;
  564. /*
  565. * Chipset identification.
  566. */
  567. struct rt2x00_chip chip;
  568. /*
  569. * hw capability specifications.
  570. */
  571. struct hw_mode_spec spec;
  572. /*
  573. * This is the default TX/RX antenna setup as indicated
  574. * by the device's EEPROM. When mac80211 sets its
  575. * antenna value to 0 we should be using these values.
  576. */
  577. struct antenna_setup default_ant;
  578. /*
  579. * Register pointers
  580. * csr_addr: Base register address. (PCI)
  581. * csr_cache: CSR cache for usb_control_msg. (USB)
  582. */
  583. void __iomem *csr_addr;
  584. void *csr_cache;
  585. /*
  586. * Mutex to protect register accesses on USB devices.
  587. * There are 2 reasons this is needed, one is to ensure
  588. * use of the csr_cache (for USB devices) by one thread
  589. * isn't corrupted by another thread trying to access it.
  590. * The other is that access to BBP and RF registers
  591. * require multiple BUS transactions and if another thread
  592. * attempted to access one of those registers at the same
  593. * time one of the writes could silently fail.
  594. */
  595. struct mutex usb_cache_mutex;
  596. /*
  597. * Interface configuration.
  598. */
  599. struct interface interface;
  600. /*
  601. * Link quality
  602. */
  603. struct link link;
  604. /*
  605. * EEPROM data.
  606. */
  607. __le16 *eeprom;
  608. /*
  609. * Active RF register values.
  610. * These are stored here so we don't need
  611. * to read the rf registers and can directly
  612. * use this value instead.
  613. * This field should be accessed by using
  614. * rt2x00_rf_read() and rt2x00_rf_write().
  615. */
  616. u32 *rf;
  617. /*
  618. * USB Max frame size (for rt2500usb & rt73usb).
  619. */
  620. u16 usb_maxpacket;
  621. /*
  622. * Current TX power value.
  623. */
  624. u16 tx_power;
  625. /*
  626. * LED register (for rt61pci & rt73usb).
  627. */
  628. u16 led_reg;
  629. /*
  630. * Led mode (LED_MODE_*)
  631. */
  632. u8 led_mode;
  633. /*
  634. * Rssi <-> Dbm offset
  635. */
  636. u8 rssi_offset;
  637. /*
  638. * Frequency offset (for rt61pci & rt73usb).
  639. */
  640. u8 freq_offset;
  641. /*
  642. * Low level statistics which will have
  643. * to be kept up to date while device is running.
  644. */
  645. struct ieee80211_low_level_stats low_level_stats;
  646. /*
  647. * RX configuration information.
  648. */
  649. struct ieee80211_rx_status rx_status;
  650. /*
  651. * Scheduled work.
  652. */
  653. struct work_struct beacon_work;
  654. struct work_struct filter_work;
  655. struct work_struct config_work;
  656. /*
  657. * Data ring arrays for RX, TX and Beacon.
  658. * The Beacon array also contains the Atim ring
  659. * if that is supported by the device.
  660. */
  661. int data_rings;
  662. struct data_ring *rx;
  663. struct data_ring *tx;
  664. struct data_ring *bcn;
  665. /*
  666. * Firmware image.
  667. */
  668. const struct firmware *fw;
  669. };
  670. /*
  671. * For-each loop for the ring array.
  672. * All rings have been allocated as a single array,
  673. * this means we can create a very simply loop macro
  674. * that is capable of looping through all rings.
  675. * ring_end(), txring_end() and ring_loop() are helper macro's which
  676. * should not be used directly. Instead the following should be used:
  677. * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim)
  678. * txring_for_each() - Loops through TX data rings (TX only)
  679. * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim)
  680. */
  681. #define ring_end(__dev) \
  682. &(__dev)->rx[(__dev)->data_rings]
  683. #define txring_end(__dev) \
  684. &(__dev)->tx[(__dev)->hw->queues]
  685. #define ring_loop(__entry, __start, __end) \
  686. for ((__entry) = (__start); \
  687. prefetch(&(__entry)[1]), (__entry) != (__end); \
  688. (__entry) = &(__entry)[1])
  689. #define ring_for_each(__dev, __entry) \
  690. ring_loop(__entry, (__dev)->rx, ring_end(__dev))
  691. #define txring_for_each(__dev, __entry) \
  692. ring_loop(__entry, (__dev)->tx, txring_end(__dev))
  693. #define txringall_for_each(__dev, __entry) \
  694. ring_loop(__entry, (__dev)->tx, ring_end(__dev))
  695. /*
  696. * Generic RF access.
  697. * The RF is being accessed by word index.
  698. */
  699. static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
  700. const unsigned int word, u32 *data)
  701. {
  702. *data = rt2x00dev->rf[word];
  703. }
  704. static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
  705. const unsigned int word, u32 data)
  706. {
  707. rt2x00dev->rf[word] = data;
  708. }
  709. /*
  710. * Generic EEPROM access.
  711. * The EEPROM is being accessed by word index.
  712. */
  713. static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
  714. const unsigned int word)
  715. {
  716. return (void *)&rt2x00dev->eeprom[word];
  717. }
  718. static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
  719. const unsigned int word, u16 *data)
  720. {
  721. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  722. }
  723. static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
  724. const unsigned int word, u16 data)
  725. {
  726. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  727. }
  728. /*
  729. * Chipset handlers
  730. */
  731. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  732. const u16 rt, const u16 rf, const u32 rev)
  733. {
  734. INFO(rt2x00dev,
  735. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  736. rt, rf, rev);
  737. rt2x00dev->chip.rt = rt;
  738. rt2x00dev->chip.rf = rf;
  739. rt2x00dev->chip.rev = rev;
  740. }
  741. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  742. {
  743. return (chipset->rt == chip);
  744. }
  745. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  746. {
  747. return (chipset->rf == chip);
  748. }
  749. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  750. {
  751. return chipset->rev;
  752. }
  753. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  754. const u32 rev)
  755. {
  756. return (((chipset->rev & 0xffff0) == rev) &&
  757. !!(chipset->rev & 0x0000f));
  758. }
  759. /*
  760. * Duration calculations
  761. * The rate variable passed is: 100kbs.
  762. * To convert from bytes to bits we multiply size with 8,
  763. * then the size is multiplied with 10 to make the
  764. * real rate -> rate argument correction.
  765. */
  766. static inline u16 get_duration(const unsigned int size, const u8 rate)
  767. {
  768. return ((size * 8 * 10) / rate);
  769. }
  770. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  771. {
  772. return ((size * 8 * 10) % rate);
  773. }
  774. /*
  775. * Library functions.
  776. */
  777. struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
  778. const unsigned int queue);
  779. /*
  780. * Interrupt context handlers.
  781. */
  782. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  783. void rt2x00lib_txdone(struct data_entry *entry,
  784. const int status, const int retry);
  785. void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
  786. struct rxdata_entry_desc *desc);
  787. /*
  788. * TX descriptor initializer
  789. */
  790. void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  791. __le32 *txd,
  792. struct ieee80211_hdr *ieee80211hdr,
  793. unsigned int length,
  794. struct ieee80211_tx_control *control);
  795. /*
  796. * mac80211 handlers.
  797. */
  798. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  799. struct ieee80211_tx_control *control);
  800. int rt2x00mac_start(struct ieee80211_hw *hw);
  801. void rt2x00mac_stop(struct ieee80211_hw *hw);
  802. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  803. struct ieee80211_if_init_conf *conf);
  804. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  805. struct ieee80211_if_init_conf *conf);
  806. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  807. int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id,
  808. struct ieee80211_if_conf *conf);
  809. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  810. struct ieee80211_low_level_stats *stats);
  811. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  812. struct ieee80211_tx_queue_stats *stats);
  813. void rt2x00mac_erp_ie_changed(struct ieee80211_hw *hw, u8 changes,
  814. int cts_protection, int preamble);
  815. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
  816. const struct ieee80211_tx_queue_params *params);
  817. /*
  818. * Driver allocation handlers.
  819. */
  820. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  821. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  822. #ifdef CONFIG_PM
  823. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  824. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  825. #endif /* CONFIG_PM */
  826. #endif /* RT2X00_H */