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