rt2x00.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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. * To optimize the quality of the link we need to store
  219. * the quality of received frames and periodically
  220. * optimize the link.
  221. */
  222. struct link {
  223. /*
  224. * Link tuner counter
  225. * The number of times the link has been tuned
  226. * since the radio has been switched on.
  227. */
  228. u32 count;
  229. /*
  230. * Quality measurement values.
  231. */
  232. struct link_qual qual;
  233. /*
  234. * Currently active TX/RX antenna setup.
  235. * When software diversity is used, this will indicate
  236. * which antenna is actually used at this time.
  237. */
  238. struct antenna_setup active_ant;
  239. /*
  240. * Active VGC level
  241. */
  242. int vgc_level;
  243. /*
  244. * Work structure for scheduling periodic link tuning.
  245. */
  246. struct delayed_work work;
  247. };
  248. /*
  249. * Update the rssi using the walking average approach.
  250. */
  251. static inline void rt2x00_update_link_rssi(struct link *link, int rssi)
  252. {
  253. if (link->qual.avg_rssi)
  254. rssi = ((link->qual.avg_rssi * 7) + rssi) / 8;
  255. link->qual.avg_rssi = rssi;
  256. }
  257. /*
  258. * When the avg_rssi is unset or no frames have been received),
  259. * we need to return the default value which needs to be less
  260. * than -80 so the device will select the maximum sensitivity.
  261. */
  262. static inline int rt2x00_get_link_rssi(struct link *link)
  263. {
  264. if (link->qual.avg_rssi && link->qual.rx_success)
  265. return link->qual.avg_rssi;
  266. return -128;
  267. }
  268. /*
  269. * Interface structure
  270. * Configuration details about the current interface.
  271. */
  272. struct interface {
  273. /*
  274. * Interface identification. The value is assigned
  275. * to us by the 80211 stack, and is used to request
  276. * new beacons.
  277. */
  278. int id;
  279. /*
  280. * Current working type (IEEE80211_IF_TYPE_*).
  281. * When set to INVALID_INTERFACE, no interface is configured.
  282. */
  283. int type;
  284. #define INVALID_INTERFACE IEEE80211_IF_TYPE_INVALID
  285. /*
  286. * MAC of the device.
  287. */
  288. u8 mac[ETH_ALEN];
  289. /*
  290. * BBSID of the AP to associate with.
  291. */
  292. u8 bssid[ETH_ALEN];
  293. /*
  294. * Store the packet filter mode for the current interface.
  295. */
  296. unsigned int filter;
  297. };
  298. static inline int is_interface_present(struct interface *intf)
  299. {
  300. return !!intf->id;
  301. }
  302. static inline int is_interface_type(struct interface *intf, int type)
  303. {
  304. return intf->type == type;
  305. }
  306. /*
  307. * Details about the supported modes, rates and channels
  308. * of a particular chipset. This is used by rt2x00lib
  309. * to build the ieee80211_hw_mode array for mac80211.
  310. */
  311. struct hw_mode_spec {
  312. /*
  313. * Number of modes, rates and channels.
  314. */
  315. int num_modes;
  316. int num_rates;
  317. int num_channels;
  318. /*
  319. * txpower values.
  320. */
  321. const u8 *tx_power_a;
  322. const u8 *tx_power_bg;
  323. u8 tx_power_default;
  324. /*
  325. * Device/chipset specific value.
  326. */
  327. const struct rf_channel *channels;
  328. };
  329. /*
  330. * Configuration structure wrapper around the
  331. * mac80211 configuration structure.
  332. * When mac80211 configures the driver, rt2x00lib
  333. * can precalculate values which are equal for all
  334. * rt2x00 drivers. Those values can be stored in here.
  335. */
  336. struct rt2x00lib_conf {
  337. struct ieee80211_conf *conf;
  338. struct rf_channel rf;
  339. struct antenna_setup ant;
  340. int phymode;
  341. int basic_rates;
  342. int slot_time;
  343. short sifs;
  344. short pifs;
  345. short difs;
  346. short eifs;
  347. };
  348. /*
  349. * rt2x00lib callback functions.
  350. */
  351. struct rt2x00lib_ops {
  352. /*
  353. * Interrupt handlers.
  354. */
  355. irq_handler_t irq_handler;
  356. /*
  357. * Device init handlers.
  358. */
  359. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  360. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  361. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
  362. const size_t len);
  363. /*
  364. * Device initialization/deinitialization handlers.
  365. */
  366. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  367. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  368. /*
  369. * Radio control handlers.
  370. */
  371. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  372. enum dev_state state);
  373. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  374. void (*link_stats) (struct rt2x00_dev *rt2x00dev,
  375. struct link_qual *qual);
  376. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
  377. void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
  378. /*
  379. * TX control handlers
  380. */
  381. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  382. struct data_desc *txd,
  383. struct txdata_entry_desc *desc,
  384. struct ieee80211_hdr *ieee80211hdr,
  385. unsigned int length,
  386. struct ieee80211_tx_control *control);
  387. int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
  388. struct data_ring *ring, struct sk_buff *skb,
  389. struct ieee80211_tx_control *control);
  390. int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
  391. struct sk_buff *skb);
  392. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  393. unsigned int queue);
  394. /*
  395. * RX control handlers
  396. */
  397. void (*fill_rxdone) (struct data_entry *entry,
  398. struct rxdata_entry_desc *desc);
  399. /*
  400. * Configuration handlers.
  401. */
  402. void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, __le32 *mac);
  403. void (*config_bssid) (struct rt2x00_dev *rt2x00dev, __le32 *bssid);
  404. void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type,
  405. const int tsf_sync);
  406. void (*config_preamble) (struct rt2x00_dev *rt2x00dev,
  407. const int short_preamble,
  408. const int ack_timeout,
  409. const int ack_consume_time);
  410. void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags,
  411. struct rt2x00lib_conf *libconf);
  412. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  413. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  414. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  415. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  416. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  417. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  418. #define CONFIG_UPDATE_ALL 0xffff
  419. };
  420. /*
  421. * rt2x00 driver callback operation structure.
  422. */
  423. struct rt2x00_ops {
  424. const char *name;
  425. const unsigned int rxd_size;
  426. const unsigned int txd_size;
  427. const unsigned int eeprom_size;
  428. const unsigned int rf_size;
  429. const struct rt2x00lib_ops *lib;
  430. const struct ieee80211_ops *hw;
  431. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  432. const struct rt2x00debug *debugfs;
  433. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  434. };
  435. /*
  436. * rt2x00 device flags
  437. */
  438. enum rt2x00_flags {
  439. /*
  440. * Device state flags
  441. */
  442. DEVICE_PRESENT,
  443. DEVICE_REGISTERED_HW,
  444. DEVICE_INITIALIZED,
  445. DEVICE_STARTED,
  446. DEVICE_STARTED_SUSPEND,
  447. DEVICE_ENABLED_RADIO,
  448. DEVICE_DISABLED_RADIO_HW,
  449. /*
  450. * Driver features
  451. */
  452. DRIVER_REQUIRE_FIRMWARE,
  453. DRIVER_REQUIRE_BEACON_RING,
  454. /*
  455. * Driver configuration
  456. */
  457. CONFIG_SUPPORT_HW_BUTTON,
  458. CONFIG_FRAME_TYPE,
  459. CONFIG_RF_SEQUENCE,
  460. CONFIG_EXTERNAL_LNA_A,
  461. CONFIG_EXTERNAL_LNA_BG,
  462. CONFIG_DOUBLE_ANTENNA,
  463. CONFIG_DISABLE_LINK_TUNING,
  464. CONFIG_SHORT_PREAMBLE,
  465. };
  466. /*
  467. * rt2x00 device structure.
  468. */
  469. struct rt2x00_dev {
  470. /*
  471. * Device structure.
  472. * The structure stored in here depends on the
  473. * system bus (PCI or USB).
  474. * When accessing this variable, the rt2x00dev_{pci,usb}
  475. * macro's should be used for correct typecasting.
  476. */
  477. void *dev;
  478. #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
  479. #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
  480. /*
  481. * Callback functions.
  482. */
  483. const struct rt2x00_ops *ops;
  484. /*
  485. * IEEE80211 control structure.
  486. */
  487. struct ieee80211_hw *hw;
  488. struct ieee80211_hw_mode *hwmodes;
  489. unsigned int curr_hwmode;
  490. #define HWMODE_B 0
  491. #define HWMODE_G 1
  492. #define HWMODE_A 2
  493. /*
  494. * rfkill structure for RF state switching support.
  495. * This will only be compiled in when required.
  496. */
  497. #ifdef CONFIG_RT2X00_LIB_RFKILL
  498. struct rfkill *rfkill;
  499. struct input_polled_dev *poll_dev;
  500. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  501. /*
  502. * If enabled, the debugfs interface structures
  503. * required for deregistration of debugfs.
  504. */
  505. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  506. const struct rt2x00debug_intf *debugfs_intf;
  507. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  508. /*
  509. * Device flags.
  510. * In these flags the current status and some
  511. * of the device capabilities are stored.
  512. */
  513. unsigned long flags;
  514. /*
  515. * Chipset identification.
  516. */
  517. struct rt2x00_chip chip;
  518. /*
  519. * hw capability specifications.
  520. */
  521. struct hw_mode_spec spec;
  522. /*
  523. * This is the default TX/RX antenna setup as indicated
  524. * by the device's EEPROM. When mac80211 sets its
  525. * antenna value to 0 we should be using these values.
  526. */
  527. struct antenna_setup default_ant;
  528. /*
  529. * Register pointers
  530. * csr_addr: Base register address. (PCI)
  531. * csr_cache: CSR cache for usb_control_msg. (USB)
  532. */
  533. void __iomem *csr_addr;
  534. void *csr_cache;
  535. /*
  536. * Interface configuration.
  537. */
  538. struct interface interface;
  539. /*
  540. * Link quality
  541. */
  542. struct link link;
  543. /*
  544. * EEPROM data.
  545. */
  546. __le16 *eeprom;
  547. /*
  548. * Active RF register values.
  549. * These are stored here so we don't need
  550. * to read the rf registers and can directly
  551. * use this value instead.
  552. * This field should be accessed by using
  553. * rt2x00_rf_read() and rt2x00_rf_write().
  554. */
  555. u32 *rf;
  556. /*
  557. * USB Max frame size (for rt2500usb & rt73usb).
  558. */
  559. u16 usb_maxpacket;
  560. /*
  561. * Current TX power value.
  562. */
  563. u16 tx_power;
  564. /*
  565. * LED register (for rt61pci & rt73usb).
  566. */
  567. u16 led_reg;
  568. /*
  569. * Led mode (LED_MODE_*)
  570. */
  571. u8 led_mode;
  572. /*
  573. * Rssi <-> Dbm offset
  574. */
  575. u8 rssi_offset;
  576. /*
  577. * Frequency offset (for rt61pci & rt73usb).
  578. */
  579. u8 freq_offset;
  580. /*
  581. * Low level statistics which will have
  582. * to be kept up to date while device is running.
  583. */
  584. struct ieee80211_low_level_stats low_level_stats;
  585. /*
  586. * RX configuration information.
  587. */
  588. struct ieee80211_rx_status rx_status;
  589. /*
  590. * Scheduled work.
  591. */
  592. struct work_struct beacon_work;
  593. struct work_struct filter_work;
  594. struct work_struct config_work;
  595. /*
  596. * Data ring arrays for RX, TX and Beacon.
  597. * The Beacon array also contains the Atim ring
  598. * if that is supported by the device.
  599. */
  600. int data_rings;
  601. struct data_ring *rx;
  602. struct data_ring *tx;
  603. struct data_ring *bcn;
  604. /*
  605. * Firmware image.
  606. */
  607. const struct firmware *fw;
  608. };
  609. /*
  610. * For-each loop for the ring array.
  611. * All rings have been allocated as a single array,
  612. * this means we can create a very simply loop macro
  613. * that is capable of looping through all rings.
  614. * ring_end(), txring_end() and ring_loop() are helper macro's which
  615. * should not be used directly. Instead the following should be used:
  616. * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim)
  617. * txring_for_each() - Loops through TX data rings (TX only)
  618. * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim)
  619. */
  620. #define ring_end(__dev) \
  621. &(__dev)->rx[(__dev)->data_rings]
  622. #define txring_end(__dev) \
  623. &(__dev)->tx[(__dev)->hw->queues]
  624. #define ring_loop(__entry, __start, __end) \
  625. for ((__entry) = (__start); \
  626. prefetch(&(__entry)[1]), (__entry) != (__end); \
  627. (__entry) = &(__entry)[1])
  628. #define ring_for_each(__dev, __entry) \
  629. ring_loop(__entry, (__dev)->rx, ring_end(__dev))
  630. #define txring_for_each(__dev, __entry) \
  631. ring_loop(__entry, (__dev)->tx, txring_end(__dev))
  632. #define txringall_for_each(__dev, __entry) \
  633. ring_loop(__entry, (__dev)->tx, ring_end(__dev))
  634. /*
  635. * Generic RF access.
  636. * The RF is being accessed by word index.
  637. */
  638. static inline void rt2x00_rf_read(const struct rt2x00_dev *rt2x00dev,
  639. const unsigned int word, u32 *data)
  640. {
  641. *data = rt2x00dev->rf[word];
  642. }
  643. static inline void rt2x00_rf_write(const struct rt2x00_dev *rt2x00dev,
  644. const unsigned int word, u32 data)
  645. {
  646. rt2x00dev->rf[word] = data;
  647. }
  648. /*
  649. * Generic EEPROM access.
  650. * The EEPROM is being accessed by word index.
  651. */
  652. static inline void *rt2x00_eeprom_addr(const struct rt2x00_dev *rt2x00dev,
  653. const unsigned int word)
  654. {
  655. return (void *)&rt2x00dev->eeprom[word];
  656. }
  657. static inline void rt2x00_eeprom_read(const struct rt2x00_dev *rt2x00dev,
  658. const unsigned int word, u16 *data)
  659. {
  660. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  661. }
  662. static inline void rt2x00_eeprom_write(const struct rt2x00_dev *rt2x00dev,
  663. const unsigned int word, u16 data)
  664. {
  665. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  666. }
  667. /*
  668. * Chipset handlers
  669. */
  670. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  671. const u16 rt, const u16 rf, const u32 rev)
  672. {
  673. INFO(rt2x00dev,
  674. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  675. rt, rf, rev);
  676. rt2x00dev->chip.rt = rt;
  677. rt2x00dev->chip.rf = rf;
  678. rt2x00dev->chip.rev = rev;
  679. }
  680. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  681. {
  682. return (chipset->rt == chip);
  683. }
  684. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  685. {
  686. return (chipset->rf == chip);
  687. }
  688. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
  689. {
  690. return chipset->rev;
  691. }
  692. static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
  693. const u32 rev)
  694. {
  695. return (((chipset->rev & 0xffff0) == rev) &&
  696. !!(chipset->rev & 0x0000f));
  697. }
  698. /*
  699. * Duration calculations
  700. * The rate variable passed is: 100kbs.
  701. * To convert from bytes to bits we multiply size with 8,
  702. * then the size is multiplied with 10 to make the
  703. * real rate -> rate argument correction.
  704. */
  705. static inline u16 get_duration(const unsigned int size, const u8 rate)
  706. {
  707. return ((size * 8 * 10) / rate);
  708. }
  709. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  710. {
  711. return ((size * 8 * 10) % rate);
  712. }
  713. /*
  714. * Library functions.
  715. */
  716. struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
  717. const unsigned int queue);
  718. /*
  719. * Interrupt context handlers.
  720. */
  721. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  722. void rt2x00lib_txdone(struct data_entry *entry,
  723. const int status, const int retry);
  724. void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
  725. struct rxdata_entry_desc *desc);
  726. /*
  727. * TX descriptor initializer
  728. */
  729. void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  730. struct data_desc *txd,
  731. struct ieee80211_hdr *ieee80211hdr,
  732. unsigned int length,
  733. struct ieee80211_tx_control *control);
  734. /*
  735. * mac80211 handlers.
  736. */
  737. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  738. struct ieee80211_tx_control *control);
  739. int rt2x00mac_start(struct ieee80211_hw *hw);
  740. void rt2x00mac_stop(struct ieee80211_hw *hw);
  741. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  742. struct ieee80211_if_init_conf *conf);
  743. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  744. struct ieee80211_if_init_conf *conf);
  745. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  746. int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id,
  747. struct ieee80211_if_conf *conf);
  748. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  749. struct ieee80211_low_level_stats *stats);
  750. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  751. struct ieee80211_tx_queue_stats *stats);
  752. void rt2x00mac_erp_ie_changed(struct ieee80211_hw *hw, u8 changes,
  753. int cts_protection, int preamble);
  754. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
  755. const struct ieee80211_tx_queue_params *params);
  756. /*
  757. * Driver allocation handlers.
  758. */
  759. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  760. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  761. #ifdef CONFIG_PM
  762. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  763. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  764. #endif /* CONFIG_PM */
  765. #endif /* RT2X00_H */