rt2x00.h 21 KB

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