rt2x00.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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.9"
  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_MGMT
  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. * rt2x00lib callback functions.
  316. */
  317. struct rt2x00lib_ops {
  318. /*
  319. * Interrupt handlers.
  320. */
  321. irq_handler_t irq_handler;
  322. /*
  323. * Device init handlers.
  324. */
  325. int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
  326. char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
  327. int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
  328. const size_t len);
  329. /*
  330. * Device initialization/deinitialization handlers.
  331. */
  332. int (*initialize) (struct rt2x00_dev *rt2x00dev);
  333. void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
  334. /*
  335. * Radio control handlers.
  336. */
  337. int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
  338. enum dev_state state);
  339. int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
  340. void (*link_stats) (struct rt2x00_dev *rt2x00dev);
  341. void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
  342. void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
  343. /*
  344. * TX control handlers
  345. */
  346. void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
  347. struct data_desc *txd,
  348. struct txdata_entry_desc *desc,
  349. struct ieee80211_hdr *ieee80211hdr,
  350. unsigned int length,
  351. struct ieee80211_tx_control *control);
  352. int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
  353. struct data_ring *ring, struct sk_buff *skb,
  354. struct ieee80211_tx_control *control);
  355. void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
  356. unsigned int queue);
  357. /*
  358. * RX control handlers
  359. */
  360. void (*fill_rxdone) (struct data_entry *entry,
  361. struct rxdata_entry_desc *desc);
  362. /*
  363. * Configuration handlers.
  364. */
  365. void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, u8 *mac);
  366. void (*config_bssid) (struct rt2x00_dev *rt2x00dev, u8 *bssid);
  367. void (*config_packet_filter) (struct rt2x00_dev *rt2x00dev,
  368. const unsigned int filter);
  369. void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type);
  370. void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags,
  371. struct ieee80211_conf *conf);
  372. #define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
  373. #define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
  374. #define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
  375. #define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
  376. #define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
  377. #define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
  378. #define CONFIG_UPDATE_ALL 0xffff
  379. };
  380. /*
  381. * rt2x00 driver callback operation structure.
  382. */
  383. struct rt2x00_ops {
  384. const char *name;
  385. const unsigned int rxd_size;
  386. const unsigned int txd_size;
  387. const unsigned int eeprom_size;
  388. const unsigned int rf_size;
  389. const struct rt2x00lib_ops *lib;
  390. const struct ieee80211_ops *hw;
  391. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  392. const struct rt2x00debug *debugfs;
  393. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  394. };
  395. /*
  396. * rt2x00 device structure.
  397. */
  398. struct rt2x00_dev {
  399. /*
  400. * Device structure.
  401. * The structure stored in here depends on the
  402. * system bus (PCI or USB).
  403. * When accessing this variable, the rt2x00dev_{pci,usb}
  404. * macro's should be used for correct typecasting.
  405. */
  406. void *dev;
  407. #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
  408. #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
  409. /*
  410. * Callback functions.
  411. */
  412. const struct rt2x00_ops *ops;
  413. /*
  414. * IEEE80211 control structure.
  415. */
  416. struct ieee80211_hw *hw;
  417. struct ieee80211_hw_mode *hwmodes;
  418. unsigned int curr_hwmode;
  419. #define HWMODE_B 0
  420. #define HWMODE_G 1
  421. #define HWMODE_A 2
  422. /*
  423. * rfkill structure for RF state switching support.
  424. * This will only be compiled in when required.
  425. */
  426. #ifdef CONFIG_RT2X00_LIB_RFKILL
  427. struct rfkill *rfkill;
  428. struct input_polled_dev *poll_dev;
  429. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  430. /*
  431. * If enabled, the debugfs interface structures
  432. * required for deregistration of debugfs.
  433. */
  434. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  435. const struct rt2x00debug_intf *debugfs_intf;
  436. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  437. /*
  438. * Device flags.
  439. * In these flags the current status and some
  440. * of the device capabilities are stored.
  441. */
  442. unsigned long flags;
  443. #define DEVICE_PRESENT 1
  444. #define DEVICE_REGISTERED_HW 2
  445. #define DEVICE_INITIALIZED 3
  446. #define DEVICE_STARTED 4
  447. #define DEVICE_ENABLED_RADIO 5
  448. #define DEVICE_ENABLED_RADIO_HW 6
  449. #define DRIVER_REQUIRE_FIRMWARE 7
  450. #define DRIVER_REQUIRE_BEACON_RING 8
  451. #define CONFIG_SUPPORT_HW_BUTTON 9
  452. #define CONFIG_FRAME_TYPE 10
  453. #define CONFIG_RF_SEQUENCE 11
  454. #define CONFIG_EXTERNAL_LNA_A 12
  455. #define CONFIG_EXTERNAL_LNA_BG 13
  456. #define CONFIG_DOUBLE_ANTENNA 14
  457. #define CONFIG_DISABLE_LINK_TUNING 15
  458. /*
  459. * Chipset identification.
  460. */
  461. struct rt2x00_chip chip;
  462. /*
  463. * hw capability specifications.
  464. */
  465. struct hw_mode_spec spec;
  466. /*
  467. * Register pointers
  468. * csr_addr: Base register address. (PCI)
  469. * csr_cache: CSR cache for usb_control_msg. (USB)
  470. */
  471. void __iomem *csr_addr;
  472. void *csr_cache;
  473. /*
  474. * Interface configuration.
  475. */
  476. struct interface interface;
  477. /*
  478. * Link quality
  479. */
  480. struct link link;
  481. /*
  482. * EEPROM data.
  483. */
  484. __le16 *eeprom;
  485. /*
  486. * Active RF register values.
  487. * These are stored here so we don't need
  488. * to read the rf registers and can directly
  489. * use this value instead.
  490. * This field should be accessed by using
  491. * rt2x00_rf_read() and rt2x00_rf_write().
  492. */
  493. u32 *rf;
  494. /*
  495. * Current TX power value.
  496. */
  497. u16 tx_power;
  498. /*
  499. * LED register (for rt61pci & rt73usb).
  500. */
  501. u16 led_reg;
  502. /*
  503. * Led mode (LED_MODE_*)
  504. */
  505. u8 led_mode;
  506. /*
  507. * Rssi <-> Dbm offset
  508. */
  509. u8 rssi_offset;
  510. /*
  511. * Frequency offset (for rt61pci & rt73usb).
  512. */
  513. u8 freq_offset;
  514. /*
  515. * Low level statistics which will have
  516. * to be kept up to date while device is running.
  517. */
  518. struct ieee80211_low_level_stats low_level_stats;
  519. /*
  520. * RX configuration information.
  521. */
  522. struct ieee80211_rx_status rx_status;
  523. /*
  524. * Scheduled work.
  525. */
  526. struct work_struct beacon_work;
  527. struct work_struct filter_work;
  528. /*
  529. * Data ring arrays for RX, TX and Beacon.
  530. * The Beacon array also contains the Atim ring
  531. * if that is supported by the device.
  532. */
  533. int data_rings;
  534. struct data_ring *rx;
  535. struct data_ring *tx;
  536. struct data_ring *bcn;
  537. /*
  538. * Firmware image.
  539. */
  540. const struct firmware *fw;
  541. };
  542. /*
  543. * For-each loop for the ring array.
  544. * All rings have been allocated as a single array,
  545. * this means we can create a very simply loop macro
  546. * that is capable of looping through all rings.
  547. * ring_end(), txring_end() and ring_loop() are helper macro's which
  548. * should not be used directly. Instead the following should be used:
  549. * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim)
  550. * txring_for_each() - Loops through TX data rings (TX only)
  551. * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim)
  552. */
  553. #define ring_end(__dev) \
  554. &(__dev)->rx[(__dev)->data_rings]
  555. #define txring_end(__dev) \
  556. &(__dev)->tx[(__dev)->hw->queues]
  557. #define ring_loop(__entry, __start, __end) \
  558. for ((__entry) = (__start); \
  559. prefetch(&(__entry)[1]), (__entry) != (__end); \
  560. (__entry) = &(__entry)[1])
  561. #define ring_for_each(__dev, __entry) \
  562. ring_loop(__entry, (__dev)->rx, ring_end(__dev))
  563. #define txring_for_each(__dev, __entry) \
  564. ring_loop(__entry, (__dev)->tx, txring_end(__dev))
  565. #define txringall_for_each(__dev, __entry) \
  566. ring_loop(__entry, (__dev)->tx, ring_end(__dev))
  567. /*
  568. * Generic RF access.
  569. * The RF is being accessed by word index.
  570. */
  571. static inline void rt2x00_rf_read(const struct rt2x00_dev *rt2x00dev,
  572. const unsigned int word, u32 *data)
  573. {
  574. *data = rt2x00dev->rf[word];
  575. }
  576. static inline void rt2x00_rf_write(const struct rt2x00_dev *rt2x00dev,
  577. const unsigned int word, u32 data)
  578. {
  579. rt2x00dev->rf[word] = data;
  580. }
  581. /*
  582. * Generic EEPROM access.
  583. * The EEPROM is being accessed by word index.
  584. */
  585. static inline void *rt2x00_eeprom_addr(const struct rt2x00_dev *rt2x00dev,
  586. const unsigned int word)
  587. {
  588. return (void *)&rt2x00dev->eeprom[word];
  589. }
  590. static inline void rt2x00_eeprom_read(const struct rt2x00_dev *rt2x00dev,
  591. const unsigned int word, u16 *data)
  592. {
  593. *data = le16_to_cpu(rt2x00dev->eeprom[word]);
  594. }
  595. static inline void rt2x00_eeprom_write(const struct rt2x00_dev *rt2x00dev,
  596. const unsigned int word, u16 data)
  597. {
  598. rt2x00dev->eeprom[word] = cpu_to_le16(data);
  599. }
  600. /*
  601. * Chipset handlers
  602. */
  603. static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
  604. const u16 rt, const u16 rf, const u32 rev)
  605. {
  606. INFO(rt2x00dev,
  607. "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
  608. rt, rf, rev);
  609. rt2x00dev->chip.rt = rt;
  610. rt2x00dev->chip.rf = rf;
  611. rt2x00dev->chip.rev = rev;
  612. }
  613. static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
  614. {
  615. return (chipset->rt == chip);
  616. }
  617. static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
  618. {
  619. return (chipset->rf == chip);
  620. }
  621. static inline u16 rt2x00_get_rev(const struct rt2x00_chip *chipset)
  622. {
  623. return chipset->rev;
  624. }
  625. static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset, const u32 mask)
  626. {
  627. return chipset->rev & mask;
  628. }
  629. /*
  630. * Duration calculations
  631. * The rate variable passed is: 100kbs.
  632. * To convert from bytes to bits we multiply size with 8,
  633. * then the size is multiplied with 10 to make the
  634. * real rate -> rate argument correction.
  635. */
  636. static inline u16 get_duration(const unsigned int size, const u8 rate)
  637. {
  638. return ((size * 8 * 10) / rate);
  639. }
  640. static inline u16 get_duration_res(const unsigned int size, const u8 rate)
  641. {
  642. return ((size * 8 * 10) % rate);
  643. }
  644. /*
  645. * Library functions.
  646. */
  647. struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
  648. const unsigned int queue);
  649. /*
  650. * Interrupt context handlers.
  651. */
  652. void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
  653. void rt2x00lib_txdone(struct data_entry *entry,
  654. const int status, const int retry);
  655. void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
  656. struct rxdata_entry_desc *desc);
  657. /*
  658. * TX descriptor initializer
  659. */
  660. void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  661. struct data_desc *txd,
  662. struct ieee80211_hdr *ieee80211hdr,
  663. unsigned int length,
  664. struct ieee80211_tx_control *control);
  665. /*
  666. * mac80211 handlers.
  667. */
  668. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  669. struct ieee80211_tx_control *control);
  670. int rt2x00mac_start(struct ieee80211_hw *hw);
  671. void rt2x00mac_stop(struct ieee80211_hw *hw);
  672. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  673. struct ieee80211_if_init_conf *conf);
  674. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  675. struct ieee80211_if_init_conf *conf);
  676. int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  677. int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id,
  678. struct ieee80211_if_conf *conf);
  679. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  680. struct ieee80211_low_level_stats *stats);
  681. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  682. struct ieee80211_tx_queue_stats *stats);
  683. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
  684. const struct ieee80211_tx_queue_params *params);
  685. /*
  686. * Driver allocation handlers.
  687. */
  688. int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
  689. void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
  690. #ifdef CONFIG_PM
  691. int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
  692. int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
  693. #endif /* CONFIG_PM */
  694. #endif /* RT2X00_H */