rt2x00.h 23 KB

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