rt2x00: Move generic TX frame writing code into rt2x00queue
[deliverable/linux.git] / drivers / net / wireless / rt2x00 / rt2x00.h
CommitLineData
95ea3627 1/*
811aa9ca 2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
95ea3627
ID
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>
95ea3627
ID
30#include <linux/skbuff.h>
31#include <linux/workqueue.h>
32#include <linux/firmware.h>
a9450b70 33#include <linux/leds.h>
3d82346c 34#include <linux/mutex.h>
61af43c5 35#include <linux/etherdevice.h>
95ea3627
ID
36
37#include <net/mac80211.h>
38
39#include "rt2x00debug.h"
a9450b70 40#include "rt2x00leds.h"
95ea3627 41#include "rt2x00reg.h"
181d6902 42#include "rt2x00queue.h"
95ea3627
ID
43
44/*
45 * Module information.
95ea3627 46 */
1b92ad7a 47#define DRV_VERSION "2.1.7"
95ea3627
ID
48#define DRV_PROJECT "http://rt2x00.serialmonkey.com"
49
50/*
51 * Debug definitions.
52 * Debug output has to be enabled during compile time.
53 */
54#define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
55 printk(__kernlvl "%s -> %s: %s - " __msg, \
56 wiphy_name((__dev)->hw->wiphy), __FUNCTION__, __lvl, ##__args)
57
58#define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
59 printk(__kernlvl "%s -> %s: %s - " __msg, \
2360157c 60 KBUILD_MODNAME, __FUNCTION__, __lvl, ##__args)
95ea3627
ID
61
62#ifdef CONFIG_RT2X00_DEBUG
63#define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
64 DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
65#else
66#define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
67 do { } while (0)
68#endif /* CONFIG_RT2X00_DEBUG */
69
70/*
71 * Various debug levels.
72 * The debug levels PANIC and ERROR both indicate serious problems,
73 * for this reason they should never be ignored.
74 * The special ERROR_PROBE message is for messages that are generated
75 * when the rt2x00_dev is not yet initialized.
76 */
77#define PANIC(__dev, __msg, __args...) \
78 DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
79#define ERROR(__dev, __msg, __args...) \
80 DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
81#define ERROR_PROBE(__msg, __args...) \
82 DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
83#define WARNING(__dev, __msg, __args...) \
84 DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
85#define NOTICE(__dev, __msg, __args...) \
86 DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
87#define INFO(__dev, __msg, __args...) \
88 DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
89#define DEBUG(__dev, __msg, __args...) \
90 DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
91#define EEPROM(__dev, __msg, __args...) \
92 DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
93
95ea3627
ID
94/*
95 * Standard timing and size defines.
96 * These values should follow the ieee80211 specifications.
97 */
98#define ACK_SIZE 14
99#define IEEE80211_HEADER 24
100#define PLCP 48
101#define BEACON 100
102#define PREAMBLE 144
103#define SHORT_PREAMBLE 72
104#define SLOT_TIME 20
105#define SHORT_SLOT_TIME 9
106#define SIFS 10
107#define PIFS ( SIFS + SLOT_TIME )
108#define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
109#define DIFS ( PIFS + SLOT_TIME )
110#define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
111#define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
112
113/*
114 * IEEE802.11 header defines
115 */
116static inline int is_rts_frame(u16 fc)
117{
ddc827f9
ID
118 return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
119 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS));
95ea3627
ID
120}
121
122static inline int is_cts_frame(u16 fc)
123{
ddc827f9
ID
124 return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
125 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS));
95ea3627
ID
126}
127
128static inline int is_probe_resp(u16 fc)
129{
ddc827f9
ID
130 return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
131 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP));
95ea3627
ID
132}
133
61af43c5
MN
134static inline int is_beacon(u16 fc)
135{
136 return (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
137 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON));
138}
139
95ea3627
ID
140/*
141 * Chipset identification
142 * The chipset on the device is composed of a RT and RF chip.
143 * The chipset combination is important for determining device capabilities.
144 */
145struct rt2x00_chip {
146 u16 rt;
147#define RT2460 0x0101
148#define RT2560 0x0201
149#define RT2570 0x1201
12dadb90
ID
150#define RT2561s 0x0301 /* Turbo */
151#define RT2561 0x0302
95ea3627
ID
152#define RT2661 0x0401
153#define RT2571 0x1300
154
155 u16 rf;
156 u32 rev;
157};
158
159/*
160 * RF register values that belong to a particular channel.
161 */
162struct rf_channel {
163 int channel;
164 u32 rf1;
165 u32 rf2;
166 u32 rf3;
167 u32 rf4;
168};
169
addc81bd
ID
170/*
171 * Antenna setup values.
172 */
173struct antenna_setup {
174 enum antenna rx;
175 enum antenna tx;
176};
177
95ea3627 178/*
ebcf26da 179 * Quality statistics about the currently active link.
95ea3627 180 */
ebcf26da 181struct link_qual {
95ea3627
ID
182 /*
183 * Statistics required for Link tuning.
184 * For the average RSSI value we use the "Walking average" approach.
185 * When adding RSSI to the average value the following calculation
186 * is needed:
187 *
188 * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
189 *
190 * The advantage of this approach is that we only need 1 variable
191 * to store the average in (No need for a count and a total).
192 * But more importantly, normal average values will over time
193 * move less and less towards newly added values this results
194 * that with link tuning, the device can have a very good RSSI
195 * for a few minutes but when the device is moved away from the AP
196 * the average will not decrease fast enough to compensate.
197 * The walking average compensates this and will move towards
198 * the new values correctly allowing a effective link tuning.
199 */
200 int avg_rssi;
95ea3627
ID
201 int false_cca;
202
203 /*
204 * Statistics required for Signal quality calculation.
205 * For calculating the Signal quality we have to determine
206 * the total number of success and failed RX and TX frames.
207 * After that we also use the average RSSI value to help
208 * determining the signal quality.
209 * For the calculation we will use the following algorithm:
210 *
211 * rssi_percentage = (avg_rssi * 100) / rssi_offset
212 * rx_percentage = (rx_success * 100) / rx_total
213 * tx_percentage = (tx_success * 100) / tx_total
214 * avg_signal = ((WEIGHT_RSSI * avg_rssi) +
215 * (WEIGHT_TX * tx_percentage) +
216 * (WEIGHT_RX * rx_percentage)) / 100
217 *
218 * This value should then be checked to not be greated then 100.
219 */
220 int rx_percentage;
221 int rx_success;
222 int rx_failed;
223 int tx_percentage;
224 int tx_success;
225 int tx_failed;
226#define WEIGHT_RSSI 20
227#define WEIGHT_RX 40
228#define WEIGHT_TX 40
ebcf26da
ID
229};
230
69f81a2c
ID
231/*
232 * Antenna settings about the currently active link.
233 */
234struct link_ant {
235 /*
236 * Antenna flags
237 */
238 unsigned int flags;
239#define ANTENNA_RX_DIVERSITY 0x00000001
240#define ANTENNA_TX_DIVERSITY 0x00000002
241#define ANTENNA_MODE_SAMPLE 0x00000004
242
243 /*
244 * Currently active TX/RX antenna setup.
245 * When software diversity is used, this will indicate
246 * which antenna is actually used at this time.
247 */
248 struct antenna_setup active;
249
250 /*
251 * RSSI information for the different antenna's.
252 * These statistics are used to determine when
253 * to switch antenna when using software diversity.
254 *
255 * rssi[0] -> Antenna A RSSI
256 * rssi[1] -> Antenna B RSSI
257 */
258 int rssi_history[2];
259
260 /*
261 * Current RSSI average of the currently active antenna.
262 * Similar to the avg_rssi in the link_qual structure
263 * this value is updated by using the walking average.
264 */
265 int rssi_ant;
266};
267
ebcf26da
ID
268/*
269 * To optimize the quality of the link we need to store
270 * the quality of received frames and periodically
271 * optimize the link.
272 */
273struct link {
274 /*
275 * Link tuner counter
276 * The number of times the link has been tuned
277 * since the radio has been switched on.
278 */
279 u32 count;
280
281 /*
282 * Quality measurement values.
283 */
284 struct link_qual qual;
285
addc81bd 286 /*
69f81a2c 287 * TX/RX antenna setup.
addc81bd 288 */
69f81a2c 289 struct link_ant ant;
addc81bd 290
ebcf26da
ID
291 /*
292 * Active VGC level
293 */
294 int vgc_level;
95ea3627
ID
295
296 /*
297 * Work structure for scheduling periodic link tuning.
298 */
299 struct delayed_work work;
300};
301
95ea3627 302/*
69f81a2c 303 * Small helper macro to work with moving/walking averages.
95ea3627 304 */
69f81a2c
ID
305#define MOVING_AVERAGE(__avg, __val, __samples) \
306 ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
307
308/*
309 * When we lack RSSI information return something less then -80 to
310 * tell the driver to tune the device to maximum sensitivity.
311 */
312#define DEFAULT_RSSI ( -128 )
95ea3627
ID
313
314/*
69f81a2c 315 * Link quality access functions.
95ea3627
ID
316 */
317static inline int rt2x00_get_link_rssi(struct link *link)
318{
ebcf26da
ID
319 if (link->qual.avg_rssi && link->qual.rx_success)
320 return link->qual.avg_rssi;
69f81a2c
ID
321 return DEFAULT_RSSI;
322}
323
324static inline int rt2x00_get_link_ant_rssi(struct link *link)
325{
326 if (link->ant.rssi_ant && link->qual.rx_success)
327 return link->ant.rssi_ant;
328 return DEFAULT_RSSI;
329}
330
f06a0f48
ID
331static inline void rt2x00_reset_link_ant_rssi(struct link *link)
332{
333 link->ant.rssi_ant = 0;
334}
335
69f81a2c
ID
336static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
337 enum antenna ant)
338{
339 if (link->ant.rssi_history[ant - ANTENNA_A])
340 return link->ant.rssi_history[ant - ANTENNA_A];
341 return DEFAULT_RSSI;
342}
343
344static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
345{
346 int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
347 link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
348 return old_rssi;
95ea3627
ID
349}
350
351/*
352 * Interface structure
6bb40dd1
ID
353 * Per interface configuration details, this structure
354 * is allocated as the private data for ieee80211_vif.
95ea3627 355 */
6bb40dd1 356struct rt2x00_intf {
95ea3627 357 /*
6bb40dd1
ID
358 * All fields within the rt2x00_intf structure
359 * must be protected with a spinlock.
95ea3627 360 */
6bb40dd1 361 spinlock_t lock;
95ea3627
ID
362
363 /*
6bb40dd1
ID
364 * BSS configuration. Copied from the structure
365 * passed to us through the bss_info_changed()
366 * callback funtion.
95ea3627 367 */
6bb40dd1 368 struct ieee80211_bss_conf conf;
95ea3627
ID
369
370 /*
371 * MAC of the device.
372 */
373 u8 mac[ETH_ALEN];
374
375 /*
376 * BBSID of the AP to associate with.
377 */
378 u8 bssid[ETH_ALEN];
95ea3627 379
6bb40dd1
ID
380 /*
381 * Entry in the beacon queue which belongs to
382 * this interface. Each interface has its own
383 * dedicated beacon entry.
384 */
385 struct queue_entry *beacon;
95ea3627 386
6bb40dd1
ID
387 /*
388 * Actions that needed rescheduling.
389 */
390 unsigned int delayed_flags;
391#define DELAYED_UPDATE_BEACON 0x00000001
72810379 392#define DELAYED_CONFIG_ERP 0x00000002
a2e1d52a 393#define DELAYED_LED_ASSOC 0x00000004
6bb40dd1
ID
394};
395
396static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
95ea3627 397{
6bb40dd1 398 return (struct rt2x00_intf *)vif->drv_priv;
95ea3627
ID
399}
400
31562e80
ID
401/**
402 * struct hw_mode_spec: Hardware specifications structure
403 *
95ea3627
ID
404 * Details about the supported modes, rates and channels
405 * of a particular chipset. This is used by rt2x00lib
406 * to build the ieee80211_hw_mode array for mac80211.
31562e80
ID
407 *
408 * @supported_bands: Bitmask contained the supported bands (2.4GHz, 5.2GHz).
409 * @supported_rates: Rate types which are supported (CCK, OFDM).
410 * @num_channels: Number of supported channels. This is used as array size
411 * for @tx_power_a, @tx_power_bg and @channels.
9a46d44e 412 * @channels: Device/chipset specific channel values (See &struct rf_channel).
31562e80
ID
413 * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
414 * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
415 * @tx_power_default: Default TX power value to use when either
416 * @tx_power_a or @tx_power_bg is missing.
95ea3627
ID
417 */
418struct hw_mode_spec {
31562e80
ID
419 unsigned int supported_bands;
420#define SUPPORT_BAND_2GHZ 0x00000001
421#define SUPPORT_BAND_5GHZ 0x00000002
422
423 unsigned int supported_rates;
424#define SUPPORT_RATE_CCK 0x00000001
425#define SUPPORT_RATE_OFDM 0x00000002
426
427 unsigned int num_channels;
428 const struct rf_channel *channels;
95ea3627 429
95ea3627
ID
430 const u8 *tx_power_a;
431 const u8 *tx_power_bg;
432 u8 tx_power_default;
95ea3627
ID
433};
434
5c58ee51
ID
435/*
436 * Configuration structure wrapper around the
437 * mac80211 configuration structure.
438 * When mac80211 configures the driver, rt2x00lib
439 * can precalculate values which are equal for all
440 * rt2x00 drivers. Those values can be stored in here.
441 */
442struct rt2x00lib_conf {
443 struct ieee80211_conf *conf;
444 struct rf_channel rf;
445
addc81bd
ID
446 struct antenna_setup ant;
447
f5507ce9 448 enum ieee80211_band band;
5c58ee51 449
aa776721
ID
450 u32 basic_rates;
451 u32 slot_time;
5c58ee51
ID
452
453 short sifs;
454 short pifs;
455 short difs;
456 short eifs;
457};
458
72810379
ID
459/*
460 * Configuration structure for erp settings.
461 */
462struct rt2x00lib_erp {
463 int short_preamble;
464
465 int ack_timeout;
466 int ack_consume_time;
467};
468
6bb40dd1
ID
469/*
470 * Configuration structure wrapper around the
471 * rt2x00 interface configuration handler.
472 */
473struct rt2x00intf_conf {
474 /*
475 * Interface type
476 */
477 enum ieee80211_if_types type;
478
479 /*
480 * TSF sync value, this is dependant on the operation type.
481 */
482 enum tsf_sync sync;
483
484 /*
485 * The MAC and BSSID addressess are simple array of bytes,
486 * these arrays are little endian, so when sending the addressess
487 * to the drivers, copy the it into a endian-signed variable.
488 *
489 * Note that all devices (except rt2500usb) have 32 bits
490 * register word sizes. This means that whatever variable we
491 * pass _must_ be a multiple of 32 bits. Otherwise the device
492 * might not accept what we are sending to it.
493 * This will also make it easier for the driver to write
494 * the data to the device.
495 */
496 __le32 mac[2];
497 __le32 bssid[2];
498};
499
95ea3627
ID
500/*
501 * rt2x00lib callback functions.
502 */
503struct rt2x00lib_ops {
504 /*
505 * Interrupt handlers.
506 */
507 irq_handler_t irq_handler;
508
509 /*
510 * Device init handlers.
511 */
512 int (*probe_hw) (struct rt2x00_dev *rt2x00dev);
513 char *(*get_firmware_name) (struct rt2x00_dev *rt2x00dev);
a7f3a06c 514 u16 (*get_firmware_crc) (void *data, const size_t len);
95ea3627
ID
515 int (*load_firmware) (struct rt2x00_dev *rt2x00dev, void *data,
516 const size_t len);
517
518 /*
519 * Device initialization/deinitialization handlers.
520 */
521 int (*initialize) (struct rt2x00_dev *rt2x00dev);
522 void (*uninitialize) (struct rt2x00_dev *rt2x00dev);
523
837e7f24 524 /*
181d6902 525 * queue initialization handlers
837e7f24
ID
526 */
527 void (*init_rxentry) (struct rt2x00_dev *rt2x00dev,
181d6902 528 struct queue_entry *entry);
837e7f24 529 void (*init_txentry) (struct rt2x00_dev *rt2x00dev,
181d6902 530 struct queue_entry *entry);
837e7f24 531
95ea3627
ID
532 /*
533 * Radio control handlers.
534 */
535 int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
536 enum dev_state state);
537 int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
ebcf26da
ID
538 void (*link_stats) (struct rt2x00_dev *rt2x00dev,
539 struct link_qual *qual);
95ea3627
ID
540 void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
541 void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
542
543 /*
544 * TX control handlers
545 */
546 void (*write_tx_desc) (struct rt2x00_dev *rt2x00dev,
dd3193e1 547 struct sk_buff *skb,
61486e0f 548 struct txentry_desc *txdesc);
6db3786a 549 int (*write_tx_data) (struct queue_entry *entry);
b242e891 550 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
dd9fa2d2 551 struct sk_buff *skb);
95ea3627 552 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
e58c6aca 553 const enum data_queue_qid queue);
95ea3627
ID
554
555 /*
556 * RX control handlers
557 */
181d6902
ID
558 void (*fill_rxdone) (struct queue_entry *entry,
559 struct rxdone_entry_desc *rxdesc);
95ea3627
ID
560
561 /*
562 * Configuration handlers.
563 */
3a643d24
ID
564 void (*config_filter) (struct rt2x00_dev *rt2x00dev,
565 const unsigned int filter_flags);
6bb40dd1
ID
566 void (*config_intf) (struct rt2x00_dev *rt2x00dev,
567 struct rt2x00_intf *intf,
568 struct rt2x00intf_conf *conf,
569 const unsigned int flags);
570#define CONFIG_UPDATE_TYPE ( 1 << 1 )
571#define CONFIG_UPDATE_MAC ( 1 << 2 )
572#define CONFIG_UPDATE_BSSID ( 1 << 3 )
573
3a643d24
ID
574 void (*config_erp) (struct rt2x00_dev *rt2x00dev,
575 struct rt2x00lib_erp *erp);
6bb40dd1
ID
576 void (*config) (struct rt2x00_dev *rt2x00dev,
577 struct rt2x00lib_conf *libconf,
578 const unsigned int flags);
95ea3627
ID
579#define CONFIG_UPDATE_PHYMODE ( 1 << 1 )
580#define CONFIG_UPDATE_CHANNEL ( 1 << 2 )
581#define CONFIG_UPDATE_TXPOWER ( 1 << 3 )
582#define CONFIG_UPDATE_ANTENNA ( 1 << 4 )
583#define CONFIG_UPDATE_SLOT_TIME ( 1 << 5 )
584#define CONFIG_UPDATE_BEACON_INT ( 1 << 6 )
585#define CONFIG_UPDATE_ALL 0xffff
586};
587
588/*
589 * rt2x00 driver callback operation structure.
590 */
591struct rt2x00_ops {
592 const char *name;
6bb40dd1
ID
593 const unsigned int max_sta_intf;
594 const unsigned int max_ap_intf;
95ea3627
ID
595 const unsigned int eeprom_size;
596 const unsigned int rf_size;
61448f88 597 const unsigned int tx_queues;
181d6902
ID
598 const struct data_queue_desc *rx;
599 const struct data_queue_desc *tx;
600 const struct data_queue_desc *bcn;
601 const struct data_queue_desc *atim;
95ea3627
ID
602 const struct rt2x00lib_ops *lib;
603 const struct ieee80211_ops *hw;
604#ifdef CONFIG_RT2X00_LIB_DEBUGFS
605 const struct rt2x00debug *debugfs;
606#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
607};
608
483272f5
ID
609/*
610 * rt2x00 device flags
611 */
612enum rt2x00_flags {
613 /*
614 * Device state flags
615 */
616 DEVICE_PRESENT,
617 DEVICE_REGISTERED_HW,
618 DEVICE_INITIALIZED,
619 DEVICE_STARTED,
620 DEVICE_STARTED_SUSPEND,
621 DEVICE_ENABLED_RADIO,
81873e9c 622 DEVICE_DISABLED_RADIO_HW,
483272f5
ID
623
624 /*
625 * Driver features
626 */
627 DRIVER_REQUIRE_FIRMWARE,
181d6902
ID
628 DRIVER_REQUIRE_BEACON_GUARD,
629 DRIVER_REQUIRE_ATIM_QUEUE,
3a643d24 630 DRIVER_REQUIRE_SCHEDULED,
483272f5
ID
631
632 /*
633 * Driver configuration
634 */
635 CONFIG_SUPPORT_HW_BUTTON,
636 CONFIG_FRAME_TYPE,
637 CONFIG_RF_SEQUENCE,
638 CONFIG_EXTERNAL_LNA_A,
639 CONFIG_EXTERNAL_LNA_BG,
640 CONFIG_DOUBLE_ANTENNA,
641 CONFIG_DISABLE_LINK_TUNING,
642};
643
95ea3627
ID
644/*
645 * rt2x00 device structure.
646 */
647struct rt2x00_dev {
648 /*
649 * Device structure.
650 * The structure stored in here depends on the
651 * system bus (PCI or USB).
652 * When accessing this variable, the rt2x00dev_{pci,usb}
653 * macro's should be used for correct typecasting.
654 */
655 void *dev;
181d6902
ID
656#define rt2x00dev_pci(__dev) ( (struct pci_dev *)(__dev)->dev )
657#define rt2x00dev_usb(__dev) ( (struct usb_interface *)(__dev)->dev )
658#define rt2x00dev_usb_dev(__dev)\
659 ( (struct usb_device *)interface_to_usbdev(rt2x00dev_usb(__dev)) )
95ea3627
ID
660
661 /*
662 * Callback functions.
663 */
664 const struct rt2x00_ops *ops;
665
666 /*
667 * IEEE80211 control structure.
668 */
669 struct ieee80211_hw *hw;
8318d78a
JB
670 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
671 enum ieee80211_band curr_band;
95ea3627
ID
672
673 /*
674 * rfkill structure for RF state switching support.
675 * This will only be compiled in when required.
676 */
677#ifdef CONFIG_RT2X00_LIB_RFKILL
3480a58a 678 unsigned long rfkill_state;
1682fe6d
ID
679#define RFKILL_STATE_ALLOCATED 1
680#define RFKILL_STATE_REGISTERED 2
95ea3627
ID
681 struct rfkill *rfkill;
682 struct input_polled_dev *poll_dev;
683#endif /* CONFIG_RT2X00_LIB_RFKILL */
684
685 /*
686 * If enabled, the debugfs interface structures
687 * required for deregistration of debugfs.
688 */
689#ifdef CONFIG_RT2X00_LIB_DEBUGFS
4d8dd66c 690 struct rt2x00debug_intf *debugfs_intf;
95ea3627
ID
691#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
692
a9450b70
ID
693 /*
694 * LED structure for changing the LED status
695 * by mac8011 or the kernel.
696 */
697#ifdef CONFIG_RT2X00_LIB_LEDS
a9450b70
ID
698 struct rt2x00_led led_radio;
699 struct rt2x00_led led_assoc;
700 struct rt2x00_led led_qual;
701 u16 led_mcu_reg;
702#endif /* CONFIG_RT2X00_LIB_LEDS */
703
95ea3627
ID
704 /*
705 * Device flags.
706 * In these flags the current status and some
707 * of the device capabilities are stored.
708 */
709 unsigned long flags;
95ea3627
ID
710
711 /*
712 * Chipset identification.
713 */
714 struct rt2x00_chip chip;
715
716 /*
717 * hw capability specifications.
718 */
719 struct hw_mode_spec spec;
720
addc81bd
ID
721 /*
722 * This is the default TX/RX antenna setup as indicated
723 * by the device's EEPROM. When mac80211 sets its
724 * antenna value to 0 we should be using these values.
725 */
726 struct antenna_setup default_ant;
727
95ea3627
ID
728 /*
729 * Register pointers
21795094
ID
730 * csr.base: CSR base register address. (PCI)
731 * csr.cache: CSR cache for usb_control_msg. (USB)
95ea3627 732 */
21795094
ID
733 union csr {
734 void __iomem *base;
735 void *cache;
736 } csr;
95ea3627 737
3d82346c
AB
738 /*
739 * Mutex to protect register accesses on USB devices.
740 * There are 2 reasons this is needed, one is to ensure
741 * use of the csr_cache (for USB devices) by one thread
742 * isn't corrupted by another thread trying to access it.
743 * The other is that access to BBP and RF registers
744 * require multiple BUS transactions and if another thread
745 * attempted to access one of those registers at the same
746 * time one of the writes could silently fail.
747 */
748 struct mutex usb_cache_mutex;
749
3c4f2085
ID
750 /*
751 * Current packet filter configuration for the device.
752 * This contains all currently active FIF_* flags send
753 * to us by mac80211 during configure_filter().
754 */
755 unsigned int packet_filter;
756
95ea3627 757 /*
6bb40dd1
ID
758 * Interface details:
759 * - Open ap interface count.
760 * - Open sta interface count.
761 * - Association count.
95ea3627 762 */
6bb40dd1
ID
763 unsigned int intf_ap_count;
764 unsigned int intf_sta_count;
765 unsigned int intf_associated;
95ea3627
ID
766
767 /*
768 * Link quality
769 */
770 struct link link;
771
772 /*
773 * EEPROM data.
774 */
775 __le16 *eeprom;
776
777 /*
778 * Active RF register values.
779 * These are stored here so we don't need
780 * to read the rf registers and can directly
781 * use this value instead.
782 * This field should be accessed by using
783 * rt2x00_rf_read() and rt2x00_rf_write().
784 */
785 u32 *rf;
786
b242e891
ID
787 /*
788 * USB Max frame size (for rt2500usb & rt73usb).
789 */
790 u16 usb_maxpacket;
791
95ea3627
ID
792 /*
793 * Current TX power value.
794 */
795 u16 tx_power;
796
95ea3627
ID
797 /*
798 * Rssi <-> Dbm offset
799 */
800 u8 rssi_offset;
801
802 /*
803 * Frequency offset (for rt61pci & rt73usb).
804 */
805 u8 freq_offset;
806
807 /*
808 * Low level statistics which will have
809 * to be kept up to date while device is running.
810 */
811 struct ieee80211_low_level_stats low_level_stats;
812
813 /*
814 * RX configuration information.
815 */
816 struct ieee80211_rx_status rx_status;
817
818 /*
4150c572 819 * Scheduled work.
95ea3627 820 */
6bb40dd1 821 struct work_struct intf_work;
4150c572 822 struct work_struct filter_work;
95ea3627
ID
823
824 /*
181d6902
ID
825 * Data queue arrays for RX, TX and Beacon.
826 * The Beacon array also contains the Atim queue
95ea3627
ID
827 * if that is supported by the device.
828 */
181d6902
ID
829 int data_queues;
830 struct data_queue *rx;
831 struct data_queue *tx;
832 struct data_queue *bcn;
95ea3627
ID
833
834 /*
835 * Firmware image.
836 */
837 const struct firmware *fw;
838};
839
95ea3627
ID
840/*
841 * Generic RF access.
842 * The RF is being accessed by word index.
843 */
0e14f6d3 844static inline void rt2x00_rf_read(struct rt2x00_dev *rt2x00dev,
95ea3627
ID
845 const unsigned int word, u32 *data)
846{
847 *data = rt2x00dev->rf[word];
848}
849
0e14f6d3 850static inline void rt2x00_rf_write(struct rt2x00_dev *rt2x00dev,
95ea3627
ID
851 const unsigned int word, u32 data)
852{
853 rt2x00dev->rf[word] = data;
854}
855
856/*
857 * Generic EEPROM access.
858 * The EEPROM is being accessed by word index.
859 */
0e14f6d3 860static inline void *rt2x00_eeprom_addr(struct rt2x00_dev *rt2x00dev,
95ea3627
ID
861 const unsigned int word)
862{
863 return (void *)&rt2x00dev->eeprom[word];
864}
865
0e14f6d3 866static inline void rt2x00_eeprom_read(struct rt2x00_dev *rt2x00dev,
95ea3627
ID
867 const unsigned int word, u16 *data)
868{
869 *data = le16_to_cpu(rt2x00dev->eeprom[word]);
870}
871
0e14f6d3 872static inline void rt2x00_eeprom_write(struct rt2x00_dev *rt2x00dev,
95ea3627
ID
873 const unsigned int word, u16 data)
874{
875 rt2x00dev->eeprom[word] = cpu_to_le16(data);
876}
877
878/*
879 * Chipset handlers
880 */
881static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
882 const u16 rt, const u16 rf, const u32 rev)
883{
884 INFO(rt2x00dev,
885 "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
886 rt, rf, rev);
887
888 rt2x00dev->chip.rt = rt;
889 rt2x00dev->chip.rf = rf;
890 rt2x00dev->chip.rev = rev;
891}
892
893static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
894{
895 return (chipset->rt == chip);
896}
897
898static inline char rt2x00_rf(const struct rt2x00_chip *chipset, const u16 chip)
899{
900 return (chipset->rf == chip);
901}
902
755a957d 903static inline u16 rt2x00_rev(const struct rt2x00_chip *chipset)
95ea3627
ID
904{
905 return chipset->rev;
906}
907
755a957d
ID
908static inline u16 rt2x00_check_rev(const struct rt2x00_chip *chipset,
909 const u32 rev)
95ea3627 910{
755a957d
ID
911 return (((chipset->rev & 0xffff0) == rev) &&
912 !!(chipset->rev & 0x0000f));
95ea3627
ID
913}
914
915/*
916 * Duration calculations
917 * The rate variable passed is: 100kbs.
918 * To convert from bytes to bits we multiply size with 8,
919 * then the size is multiplied with 10 to make the
920 * real rate -> rate argument correction.
921 */
922static inline u16 get_duration(const unsigned int size, const u8 rate)
923{
924 return ((size * 8 * 10) / rate);
925}
926
927static inline u16 get_duration_res(const unsigned int size, const u8 rate)
928{
929 return ((size * 8 * 10) % rate);
930}
931
7050ec82
ID
932/**
933 * rt2x00queue_create_tx_descriptor - Create TX descriptor from mac80211 input
934 * @entry: The entry which will be used to transfer the TX frame.
935 * @txdesc: rt2x00 TX descriptor which will be initialized by this function.
7050ec82
ID
936 *
937 * This function will initialize the &struct txentry_desc based on information
938 * from mac80211. This descriptor can then be used by rt2x00lib and the drivers
939 * to correctly initialize the hardware descriptor.
940 * Note that before calling this function the skb->cb array must be untouched
941 * by rt2x00lib. Only after this function completes will it be save to
942 * overwrite the skb->cb information.
943 * The reason for this is that mac80211 writes its own tx information into
944 * the skb->cb array, and this function will use that information to initialize
945 * the &struct txentry_desc structure.
946 */
947void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
e039fa4a 948 struct txentry_desc *txdesc);
7050ec82
ID
949
950/**
951 * rt2x00queue_write_tx_descriptor - Write TX descriptor to hardware
952 * @entry: The entry which will be used to transfer the TX frame.
953 * @txdesc: TX descriptor which will be used to write hardware descriptor
954 *
955 * This function will write a TX descriptor initialized by
956 * &rt2x00queue_create_tx_descriptor to the hardware. After this call
957 * has completed the frame is now owned by the hardware, the hardware
958 * queue will have automatically be kicked unless this frame was generated
959 * by rt2x00lib, in which case the frame is "special" and must be kicked
960 * by the caller.
961 */
962void rt2x00queue_write_tx_descriptor(struct queue_entry *entry,
963 struct txentry_desc *txdesc);
964
181d6902 965/**
e58c6aca 966 * rt2x00queue_get_queue - Convert queue index to queue pointer
181d6902 967 * @rt2x00dev: Pointer to &struct rt2x00_dev.
e58c6aca 968 * @queue: rt2x00 queue index (see &enum data_queue_qid).
95ea3627 969 */
181d6902 970struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
e58c6aca 971 const enum data_queue_qid queue);
181d6902
ID
972
973/**
974 * rt2x00queue_get_entry - Get queue entry where the given index points to.
9a46d44e 975 * @queue: Pointer to &struct data_queue from where we obtain the entry.
181d6902
ID
976 * @index: Index identifier for obtaining the correct index.
977 */
978struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
979 enum queue_index index);
980
981/**
982 * rt2x00queue_index_inc - Index incrementation function
983 * @queue: Queue (&struct data_queue) to perform the action on.
9a46d44e 984 * @index: Index type (&enum queue_index) to perform the action on.
181d6902
ID
985 *
986 * This function will increase the requested index on the queue,
987 * it will grab the appropriate locks and handle queue overflow events by
988 * resetting the index to the start of the queue.
989 */
990void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
991
95ea3627
ID
992
993/*
994 * Interrupt context handlers.
995 */
996void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev);
181d6902
ID
997void rt2x00lib_txdone(struct queue_entry *entry,
998 struct txdone_entry_desc *txdesc);
999void rt2x00lib_rxdone(struct queue_entry *entry,
1000 struct rxdone_entry_desc *rxdesc);
95ea3627 1001
95ea3627
ID
1002/*
1003 * mac80211 handlers.
1004 */
e039fa4a 1005int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
95ea3627
ID
1006int rt2x00mac_start(struct ieee80211_hw *hw);
1007void rt2x00mac_stop(struct ieee80211_hw *hw);
1008int rt2x00mac_add_interface(struct ieee80211_hw *hw,
1009 struct ieee80211_if_init_conf *conf);
1010void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
1011 struct ieee80211_if_init_conf *conf);
1012int rt2x00mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
32bfd35d
JB
1013int rt2x00mac_config_interface(struct ieee80211_hw *hw,
1014 struct ieee80211_vif *vif,
95ea3627 1015 struct ieee80211_if_conf *conf);
3a643d24
ID
1016void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
1017 unsigned int changed_flags,
1018 unsigned int *total_flags,
1019 int mc_count, struct dev_addr_list *mc_list);
95ea3627
ID
1020int rt2x00mac_get_stats(struct ieee80211_hw *hw,
1021 struct ieee80211_low_level_stats *stats);
1022int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
1023 struct ieee80211_tx_queue_stats *stats);
471b3efd
JB
1024void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
1025 struct ieee80211_vif *vif,
1026 struct ieee80211_bss_conf *bss_conf,
1027 u32 changes);
e100bb64 1028int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
95ea3627
ID
1029 const struct ieee80211_tx_queue_params *params);
1030
1031/*
1032 * Driver allocation handlers.
1033 */
1034int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
1035void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
1036#ifdef CONFIG_PM
1037int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
1038int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
1039#endif /* CONFIG_PM */
1040
1041#endif /* RT2X00_H */
This page took 0.211079 seconds and 5 git commands to generate.