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