rt2x00.h 24 KB

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