blob: d6f0a72b7a0cd748a0a93fbae7da57c1c7453d6a [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
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 */
Ivo van Doorn515ea242007-10-06 14:18:41 +020045#define DRV_VERSION "2.0.10"
Ivo van Doorn95ea3622007-09-25 17:57:13 -070046#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 */
134static 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
140static 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
146static 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 */
157struct rt2x00_chip {
158 u16 rt;
159#define RT2460 0x0101
160#define RT2560 0x0201
161#define RT2570 0x1201
Ivo van Doorn12dadb92007-09-25 20:54:44 +0200162#define RT2561s 0x0301 /* Turbo */
163#define RT2561 0x0302
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700164#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 */
174struct rf_channel {
175 int channel;
176 u32 rf1;
177 u32 rf2;
178 u32 rf3;
179 u32 rf4;
180};
181
182/*
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200183 * Antenna setup values.
184 */
185struct antenna_setup {
186 enum antenna rx;
187 enum antenna tx;
188};
189
190/*
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200191 * Quality statistics about the currently active link.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700192 */
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200193struct link_qual {
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700194 /*
195 * Statistics required for Link tuning.
196 * For the average RSSI value we use the "Walking average" approach.
197 * When adding RSSI to the average value the following calculation
198 * is needed:
199 *
200 * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
201 *
202 * The advantage of this approach is that we only need 1 variable
203 * to store the average in (No need for a count and a total).
204 * But more importantly, normal average values will over time
205 * move less and less towards newly added values this results
206 * that with link tuning, the device can have a very good RSSI
207 * for a few minutes but when the device is moved away from the AP
208 * the average will not decrease fast enough to compensate.
209 * The walking average compensates this and will move towards
210 * the new values correctly allowing a effective link tuning.
211 */
212 int avg_rssi;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700213 int false_cca;
214
215 /*
216 * Statistics required for Signal quality calculation.
217 * For calculating the Signal quality we have to determine
218 * the total number of success and failed RX and TX frames.
219 * After that we also use the average RSSI value to help
220 * determining the signal quality.
221 * For the calculation we will use the following algorithm:
222 *
223 * rssi_percentage = (avg_rssi * 100) / rssi_offset
224 * rx_percentage = (rx_success * 100) / rx_total
225 * tx_percentage = (tx_success * 100) / tx_total
226 * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
227 * (WEIGHT_TX * tx_percentage) +
228 * (WEIGHT_RX * rx_percentage)) / 100
229 *
230 * This value should then be checked to not be greated then 100.
231 */
232 int rx_percentage;
233 int rx_success;
234 int rx_failed;
235 int tx_percentage;
236 int tx_success;
237 int tx_failed;
238#define WEIGHT_RSSI 20
239#define WEIGHT_RX 40
240#define WEIGHT_TX 40
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200241};
242
243/*
244 * To optimize the quality of the link we need to store
245 * the quality of received frames and periodically
246 * optimize the link.
247 */
248struct link {
249 /*
250 * Link tuner counter
251 * The number of times the link has been tuned
252 * since the radio has been switched on.
253 */
254 u32 count;
255
256 /*
257 * Quality measurement values.
258 */
259 struct link_qual qual;
260
261 /*
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200262 * Currently active TX/RX antenna setup.
263 * When software diversity is used, this will indicate
264 * which antenna is actually used at this time.
265 */
266 struct antenna_setup active_ant;
267
268 /*
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200269 * Active VGC level
270 */
271 int vgc_level;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700272
273 /*
274 * Work structure for scheduling periodic link tuning.
275 */
276 struct delayed_work work;
277};
278
279/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700280 * Update the rssi using the walking average approach.
281 */
282static inline void rt2x00_update_link_rssi(struct link *link, int rssi)
283{
Ivo van Doorn8de8c512007-10-13 16:26:32 +0200284 if (link->qual.avg_rssi)
285 rssi = ((link->qual.avg_rssi * 7) + rssi) / 8;
286 link->qual.avg_rssi = rssi;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700287}
288
289/*
290 * When the avg_rssi is unset or no frames have been received),
291 * we need to return the default value which needs to be less
292 * than -80 so the device will select the maximum sensitivity.
293 */
294static inline int rt2x00_get_link_rssi(struct link *link)
295{
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200296 if (link->qual.avg_rssi && link->qual.rx_success)
297 return link->qual.avg_rssi;
298 return -128;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700299}
300
301/*
302 * Interface structure
303 * Configuration details about the current interface.
304 */
305struct interface {
306 /*
307 * Interface identification. The value is assigned
308 * to us by the 80211 stack, and is used to request
309 * new beacons.
310 */
311 int id;
312
313 /*
314 * Current working type (IEEE80211_IF_TYPE_*).
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700315 * When set to INVALID_INTERFACE, no interface is configured.
316 */
317 int type;
Johannes Berga2897552007-09-28 14:01:25 +0200318#define INVALID_INTERFACE IEEE80211_IF_TYPE_INVALID
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700319
320 /*
321 * MAC of the device.
322 */
323 u8 mac[ETH_ALEN];
324
325 /*
326 * BBSID of the AP to associate with.
327 */
328 u8 bssid[ETH_ALEN];
329
330 /*
331 * Store the packet filter mode for the current interface.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700332 */
Johannes Berg4150c572007-09-17 01:29:23 -0400333 unsigned int filter;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700334};
335
336static inline int is_interface_present(struct interface *intf)
337{
338 return !!intf->id;
339}
340
Johannes Berg4150c572007-09-17 01:29:23 -0400341static inline int is_interface_type(struct interface *intf, int type)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700342{
Johannes Berg4150c572007-09-17 01:29:23 -0400343 return intf->type == type;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700344}
345
346/*
347 * Details about the supported modes, rates and channels
348 * of a particular chipset. This is used by rt2x00lib
349 * to build the ieee80211_hw_mode array for mac80211.
350 */
351struct hw_mode_spec {
352 /*
353 * Number of modes, rates and channels.
354 */
355 int num_modes;
356 int num_rates;
357 int num_channels;
358
359 /*
360 * txpower values.
361 */
362 const u8 *tx_power_a;
363 const u8 *tx_power_bg;
364 u8 tx_power_default;
365
366 /*
367 * Device/chipset specific value.
368 */
369 const struct rf_channel *channels;
370};
371
372/*
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200373 * Configuration structure wrapper around the
374 * mac80211 configuration structure.
375 * When mac80211 configures the driver, rt2x00lib
376 * can precalculate values which are equal for all
377 * rt2x00 drivers. Those values can be stored in here.
378 */
379struct rt2x00lib_conf {
380 struct ieee80211_conf *conf;
381 struct rf_channel rf;
382
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200383 struct antenna_setup ant;
384
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200385 int phymode;
386
387 int basic_rates;
388 int slot_time;
389
390 short sifs;
391 short pifs;
392 short difs;
393 short eifs;
394};
395
396/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700397 * rt2x00lib callback functions.
398 */
399struct rt2x00lib_ops {
400 /*
401 * Interrupt handlers.
402 */
403 irq_handler_t irq_handler;
404
405 /*
406 * Device init handlers.
407 */
408 int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
409 char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
410 int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
411 const size_t len);
412
413 /*
414 * Device initialization/deinitialization handlers.
415 */
416 int (*initialize) (struct rt2x00_dev *rt2x00dev);
417 void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
418
419 /*
420 * Radio control handlers.
421 */
422 int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
423 enum dev_state state);
424 int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
Ivo van Doornebcf26d2007-10-13 16:26:12 +0200425 void (*link_stats) (struct rt2x00_dev *rt2x00dev,
426 struct link_qual *qual);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700427 void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
428 void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
429
430 /*
431 * TX control handlers
432 */
433 void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
434 struct data_desc *txd,
Johannes Berg4150c572007-09-17 01:29:23 -0400435 struct txdata_entry_desc *desc,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700436 struct ieee80211_hdr *ieee80211hdr,
437 unsigned int length,
438 struct ieee80211_tx_control *control);
439 int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
440 struct data_ring *ring, struct sk_buff *skb,
441 struct ieee80211_tx_control *control);
Ivo van Doornb242e892007-11-15 23:41:31 +0100442 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
Ivo van Doorndd9fa2d2007-10-06 14:15:46 +0200443 struct sk_buff *skb);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700444 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
445 unsigned int queue);
446
447 /*
448 * RX control handlers
449 */
Johannes Berg4150c572007-09-17 01:29:23 -0400450 void (*fill_rxdone) (struct data_entry *entry,
451 struct rxdata_entry_desc *desc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700452
453 /*
454 * Configuration handlers.
455 */
Ivo van Doorn4abee4b2007-10-06 14:11:46 +0200456 void (*config_mac_addr) (struct rt2x00_dev *rt2x00dev, __le32 *mac);
457 void (*config_bssid) (struct rt2x00_dev *rt2x00dev, __le32 *bssid);
Ivo van Doornfeb24692007-10-06 14:14:29 +0200458 void (*config_type) (struct rt2x00_dev *rt2x00dev, const int type,
459 const int tsf_sync);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200460 void (*config_preamble) (struct rt2x00_dev *rt2x00dev,
461 const int short_preamble,
462 const int ack_timeout,
463 const int ack_consume_time);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700464 void (*config) (struct rt2x00_dev *rt2x00dev, const unsigned int flags,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200465 struct rt2x00lib_conf *libconf);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700466#define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
467#define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
468#define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
469#define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
470#define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
471#define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
472#define CONFIG_UPDATE_ALL 0xffff
473};
474
475/*
476 * rt2x00 driver callback operation structure.
477 */
478struct rt2x00_ops {
479 const char *name;
480 const unsigned int rxd_size;
481 const unsigned int txd_size;
482 const unsigned int eeprom_size;
483 const unsigned int rf_size;
484 const struct rt2x00lib_ops *lib;
485 const struct ieee80211_ops *hw;
486#ifdef CONFIG_RT2X00_LIB_DEBUGFS
487 const struct rt2x00debug *debugfs;
488#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
489};
490
491/*
Ivo van Doorn483272f2007-10-06 14:13:06 +0200492 * rt2x00 device flags
493 */
494enum rt2x00_flags {
495 /*
496 * Device state flags
497 */
498 DEVICE_PRESENT,
499 DEVICE_REGISTERED_HW,
500 DEVICE_INITIALIZED,
501 DEVICE_STARTED,
502 DEVICE_STARTED_SUSPEND,
503 DEVICE_ENABLED_RADIO,
Ivo van Doorn81873e92007-10-06 14:14:06 +0200504 DEVICE_DISABLED_RADIO_HW,
Ivo van Doorn483272f2007-10-06 14:13:06 +0200505
506 /*
507 * Driver features
508 */
509 DRIVER_REQUIRE_FIRMWARE,
510 DRIVER_REQUIRE_BEACON_RING,
511
512 /*
513 * Driver configuration
514 */
515 CONFIG_SUPPORT_HW_BUTTON,
516 CONFIG_FRAME_TYPE,
517 CONFIG_RF_SEQUENCE,
518 CONFIG_EXTERNAL_LNA_A,
519 CONFIG_EXTERNAL_LNA_BG,
520 CONFIG_DOUBLE_ANTENNA,
521 CONFIG_DISABLE_LINK_TUNING,
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200522 CONFIG_SHORT_PREAMBLE,
Ivo van Doorn483272f2007-10-06 14:13:06 +0200523};
524
525/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700526 * rt2x00 device structure.
527 */
528struct rt2x00_dev {
529 /*
530 * Device structure.
531 * The structure stored in here depends on the
532 * system bus (PCI or USB).
533 * When accessing this variable, the rt2x00dev_{pci,usb}
534 * macro's should be used for correct typecasting.
535 */
536 void *dev;
537#define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
538#define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
539
540 /*
541 * Callback functions.
542 */
543 const struct rt2x00_ops *ops;
544
545 /*
546 * IEEE80211 control structure.
547 */
548 struct ieee80211_hw *hw;
549 struct ieee80211_hw_mode *hwmodes;
550 unsigned int curr_hwmode;
551#define HWMODE_B 0
552#define HWMODE_G 1
553#define HWMODE_A 2
554
555 /*
556 * rfkill structure for RF state switching support.
557 * This will only be compiled in when required.
558 */
559#ifdef CONFIG_RT2X00_LIB_RFKILL
560 struct rfkill *rfkill;
561 struct input_polled_dev *poll_dev;
562#endif /* CONFIG_RT2X00_LIB_RFKILL */
563
564 /*
565 * If enabled, the debugfs interface structures
566 * required for deregistration of debugfs.
567 */
568#ifdef CONFIG_RT2X00_LIB_DEBUGFS
569 const struct rt2x00debug_intf *debugfs_intf;
570#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
571
572 /*
573 * Device flags.
574 * In these flags the current status and some
575 * of the device capabilities are stored.
576 */
577 unsigned long flags;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700578
579 /*
580 * Chipset identification.
581 */
582 struct rt2x00_chip chip;
583
584 /*
585 * hw capability specifications.
586 */
587 struct hw_mode_spec spec;
588
589 /*
Ivo van Doornaddc81b2007-10-13 16:26:23 +0200590 * This is the default TX/RX antenna setup as indicated
591 * by the device's EEPROM. When mac80211 sets its
592 * antenna value to 0 we should be using these values.
593 */
594 struct antenna_setup default_ant;
595
596 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700597 * Register pointers
598 * csr_addr: Base register address. (PCI)
599 * csr_cache: CSR cache for usb_control_msg. (USB)
600 */
601 void __iomem *csr_addr;
602 void *csr_cache;
603
604 /*
605 * Interface configuration.
606 */
607 struct interface interface;
608
609 /*
610 * Link quality
611 */
612 struct link link;
613
614 /*
615 * EEPROM data.
616 */
617 __le16 *eeprom;
618
619 /*
620 * Active RF register values.
621 * These are stored here so we don't need
622 * to read the rf registers and can directly
623 * use this value instead.
624 * This field should be accessed by using
625 * rt2x00_rf_read() and rt2x00_rf_write().
626 */
627 u32 *rf;
628
629 /*
Ivo van Doornb242e892007-11-15 23:41:31 +0100630 * USB Max frame size (for rt2500usb & rt73usb).
631 */
632 u16 usb_maxpacket;
633
634 /*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700635 * Current TX power value.
636 */
637 u16 tx_power;
638
639 /*
640 * LED register (for rt61pci & rt73usb).
641 */
642 u16 led_reg;
643
644 /*
645 * Led mode (LED_MODE_*)
646 */
647 u8 led_mode;
648
649 /*
650 * Rssi <-> Dbm offset
651 */
652 u8 rssi_offset;
653
654 /*
655 * Frequency offset (for rt61pci & rt73usb).
656 */
657 u8 freq_offset;
658
659 /*
660 * Low level statistics which will have
661 * to be kept up to date while device is running.
662 */
663 struct ieee80211_low_level_stats low_level_stats;
664
665 /*
666 * RX configuration information.
667 */
668 struct ieee80211_rx_status rx_status;
669
670 /*
Johannes Berg4150c572007-09-17 01:29:23 -0400671 * Scheduled work.
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700672 */
673 struct work_struct beacon_work;
Johannes Berg4150c572007-09-17 01:29:23 -0400674 struct work_struct filter_work;
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200675 struct work_struct config_work;
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700676
677 /*
678 * Data ring arrays for RX, TX and Beacon.
679 * The Beacon array also contains the Atim ring
680 * if that is supported by the device.
681 */
682 int data_rings;
683 struct data_ring *rx;
684 struct data_ring *tx;
685 struct data_ring *bcn;
686
687 /*
688 * Firmware image.
689 */
690 const struct firmware *fw;
691};
692
693/*
694 * For-each loop for the ring array.
695 * All rings have been allocated as a single array,
696 * this means we can create a very simply loop macro
697 * that is capable of looping through all rings.
698 * ring_end(), txring_end() and ring_loop() are helper macro's which
699 * should not be used directly. Instead the following should be used:
700 * ring_for_each() - Loops through all rings (RX, TX, Beacon & Atim)
701 * txring_for_each() - Loops through TX data rings (TX only)
702 * txringall_for_each() - Loops through all TX rings (TX, Beacon & Atim)
703 */
704#define ring_end(__dev) \
705 &(__dev)->rx[(__dev)->data_rings]
706
707#define txring_end(__dev) \
708 &(__dev)->tx[(__dev)->hw->queues]
709
710#define ring_loop(__entry, __start, __end) \
711 for ((__entry) = (__start); \
712 prefetch(&(__entry)[1]), (__entry) != (__end); \
713 (__entry) = &(__entry)[1])
714
715#define ring_for_each(__dev, __entry) \
716 ring_loop(__entry, (__dev)->rx, ring_end(__dev))
717
718#define txring_for_each(__dev, __entry) \
719 ring_loop(__entry, (__dev)->tx, txring_end(__dev))
720
721#define txringall_for_each(__dev, __entry) \
722 ring_loop(__entry, (__dev)->tx, ring_end(__dev))
723
724/*
725 * Generic RF access.
726 * The RF is being accessed by word index.
727 */
728static inline void rt2x00_rf_read(const struct rt2x00_dev *rt2x00dev,
729 const unsigned int word, u32 *data)
730{
731 *data = rt2x00dev->rf[word];
732}
733
734static inline void rt2x00_rf_write(const struct rt2x00_dev *rt2x00dev,
735 const unsigned int word, u32 data)
736{
737 rt2x00dev->rf[word] = data;
738}
739
740/*
741 * Generic EEPROM access.
742 * The EEPROM is being accessed by word index.
743 */
744static inline void *rt2x00_eeprom_addr(const struct rt2x00_dev *rt2x00dev,
745 const unsigned int word)
746{
747 return (void *)&rt2x00dev->eeprom[word];
748}
749
750static inline void rt2x00_eeprom_read(const struct rt2x00_dev *rt2x00dev,
751 const unsigned int word, u16 *data)
752{
753 *data = le16_to_cpu(rt2x00dev->eeprom[word]);
754}
755
756static inline void rt2x00_eeprom_write(const struct rt2x00_dev *rt2x00dev,
757 const unsigned int word, u16 data)
758{
759 rt2x00dev->eeprom[word] = cpu_to_le16(data);
760}
761
762/*
763 * Chipset handlers
764 */
765static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
766 const u16 rt, const u16 rf, const u32 rev)
767{
768 INFO(rt2x00dev,
769 "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
770 rt, rf, rev);
771
772 rt2x00dev->chip.rt = rt;
773 rt2x00dev->chip.rf = rf;
774 rt2x00dev->chip.rev = rev;
775}
776
777static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
778{
779 return (chipset->rt == chip);
780}
781
782static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
783{
784 return (chipset->rf == chip);
785}
786
Ivo van Doorn755a9572007-11-12 15:02:22 +0100787static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700788{
789 return chipset->rev;
790}
791
Ivo van Doorn755a9572007-11-12 15:02:22 +0100792static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
793 const u32 rev)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700794{
Ivo van Doorn755a9572007-11-12 15:02:22 +0100795 return (((chipset->rev & 0xffff0) == rev) &&
796 !!(chipset->rev & 0x0000f));
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700797}
798
799/*
800 * Duration calculations
801 * The rate variable passed is: 100kbs.
802 * To convert from bytes to bits we multiply size with 8,
803 * then the size is multiplied with 10 to make the
804 * real rate -> rate argument correction.
805 */
806static inline u16 get_duration(const unsigned int size, const u8 rate)
807{
808 return ((size * 8 * 10) / rate);
809}
810
811static inline u16 get_duration_res(const unsigned int size, const u8 rate)
812{
813 return ((size * 8 * 10) % rate);
814}
815
816/*
817 * Library functions.
818 */
819struct data_ring *rt2x00lib_get_ring(struct rt2x00_dev *rt2x00dev,
820 const unsigned int queue);
821
822/*
823 * Interrupt context handlers.
824 */
825void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
826void rt2x00lib_txdone(struct data_entry *entry,
827 const int status, const int retry);
828void rt2x00lib_rxdone(struct data_entry *entry, struct sk_buff *skb,
Johannes Berg4150c572007-09-17 01:29:23 -0400829 struct rxdata_entry_desc *desc);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700830
831/*
832 * TX descriptor initializer
833 */
834void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
835 struct data_desc *txd,
836 struct ieee80211_hdr *ieee80211hdr,
837 unsigned int length,
838 struct ieee80211_tx_control *control);
839
840/*
841 * mac80211 handlers.
842 */
843int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
844 struct ieee80211_tx_control *control);
845int rt2x00mac_start(struct ieee80211_hw *hw);
846void rt2x00mac_stop(struct ieee80211_hw *hw);
847int rt2x00mac_add_interface(struct ieee80211_hw *hw,
848 struct ieee80211_if_init_conf *conf);
849void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
850 struct ieee80211_if_init_conf *conf);
851int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
852int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id,
853 struct ieee80211_if_conf *conf);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700854int rt2x00mac_get_stats(struct ieee80211_hw *hw,
855 struct ieee80211_low_level_stats *stats);
856int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
857 struct ieee80211_tx_queue_stats *stats);
Ivo van Doorn5c58ee52007-10-06 13:34:52 +0200858void rt2x00mac_erp_ie_changed(struct ieee80211_hw *hw, u8 changes,
859 int cts_protection, int preamble);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700860int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
861 const struct ieee80211_tx_queue_params *params);
862
863/*
864 * Driver allocation handlers.
865 */
866int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
867void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
868#ifdef CONFIG_PM
869int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
870int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
871#endif /* CONFIG_PM */
872
873#endif /* RT2X00_H */