2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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.
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.
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.
23 Abstract: rt2x00 global information.
24 Supported chipsets: RT2460, RT2560, RT2570,
25 rt2561, rt2561s, rt2661, rt2571W & rt2671.
31 #include <linux/bitops.h>
32 #include <linux/skbuff.h>
33 #include <linux/workqueue.h>
35 #include <net/mac80211.h>
37 #include "rt2x00lib.h"
38 #include "rt2x00debug.h"
44 #define DRV_NAME "rt2x00"
46 #define DRV_VERSION "2.0.1"
47 #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
51 * Debug output has to be enabled during compile time.
53 #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
54 printk(__kernlvl "%s -> %s: %s - " __msg, \
55 wiphy_name(rt2x00dev->hw->wiphy), \
56 __FUNCTION__, __lvl, ##__args)
58 #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
59 printk(__kernlvl "%s -> %s: %s - " __msg, \
60 DRV_NAME, __FUNCTION__, __lvl, ##__args)
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 /* CONFIG_RT2X00_DEBUG */
66 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
68 #endif /* CONFIG_RT2X00_DEBUG */
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.
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)
96 * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes.
97 * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings.
98 * MGMT_FRAME_SIZE is used for the BEACON ring.
100 #define DATA_FRAME_SIZE 2432
101 #define MGMT_FRAME_SIZE 256
104 * Number of entries in a packet ring.
106 #define RX_ENTRIES 12
107 #define TX_ENTRIES 12
108 #define ATIM_ENTRIES 1
109 #define BEACON_ENTRIES 1
112 * Standard timing and size defines.
115 #define IEEE80211_HEADER 24
119 #define SHORT_PREAMBLE 72
121 #define SHORT_SLOT_TIME 9
123 #define PIFS ( SIFS + SLOT_TIME )
124 #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
125 #define DIFS ( PIFS + SLOT_TIME )
126 #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
127 #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
130 * IEEE802.11 header defines
132 #define is_rts_frame(__fc) \
133 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
134 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS)) )
135 #define is_cts_frame(__fc) \
136 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
137 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS)) )
138 #define is_probe_resp(__fc) \
139 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) && \
140 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)) )
145 #define LINK_TUNE_INTERVAL ( 1 * HZ )
146 #define RFKILL_POLL_INTERVAL ( HZ / 4 )
153 TX_SUCCESS_RETRY
= 1,
163 ANTENNA_DIVERSITY
= 0,
172 LED_MODE_DEFAULT
= 0,
173 LED_MODE_TXRX_ACTIVITY
= 1,
174 LED_MODE_SIGNAL_STRENGTH
= 2,
183 STATE_DEEP_SLEEP
= 0,
189 * Additional device states, these values are
190 * not strict since they are not directly passed
210 * Cipher types for hardware encryption
219 * The following fields were added by rt61pci and rt73usb.
223 CIPHER_TKIP_NO_MIC
= 7,
228 * We store the position of a register field inside a field structure,
229 * This will simplify the process of setting and reading a certain field
230 * inside the register while making sure the process remains byte order safe.
232 struct rt2x00_field8
{
237 struct rt2x00_field16
{
242 struct rt2x00_field32
{
248 * Power of two check from Linus Torvalds,
249 * this will check if the mask that has been
250 * given contains and contiguous set of bits.
252 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
253 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
254 #define is_valid_mask(x) is_power_of_two(1 + (x) + low_bit_mask(x))
256 #define FIELD8(__mask) \
258 BUILD_BUG_ON(!(__mask) || \
259 !is_valid_mask(__mask) || \
260 (__mask) != (u8)(__mask)); \
261 (struct rt2x00_field8) { \
262 __ffs(__mask), (__mask) \
266 #define FIELD16(__mask) \
268 BUILD_BUG_ON(!(__mask) || \
269 !is_valid_mask(__mask) || \
270 (__mask) != (u16)(__mask));\
271 (struct rt2x00_field16) { \
272 __ffs(__mask), (__mask) \
276 #define FIELD32(__mask) \
278 BUILD_BUG_ON(!(__mask) || \
279 !is_valid_mask(__mask) || \
280 (__mask) != (u32)(__mask));\
281 (struct rt2x00_field32) { \
282 __ffs(__mask), (__mask) \
286 static inline void rt2x00_set_field32(u32
*reg
,
287 const struct rt2x00_field32 field
, const u32 value
)
289 *reg
&= ~(field
.bit_mask
);
290 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
293 static inline u32
rt2x00_get_field32(const u32 reg
,
294 const struct rt2x00_field32 field
)
296 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
299 static inline void rt2x00_set_field16(u16
*reg
,
300 const struct rt2x00_field16 field
, const u16 value
)
302 *reg
&= ~(field
.bit_mask
);
303 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
306 static inline u16
rt2x00_get_field16(const u16 reg
,
307 const struct rt2x00_field16 field
)
309 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
312 static inline void rt2x00_set_field8(u8
*reg
,
313 const struct rt2x00_field8 field
, const u8 value
)
315 *reg
&= ~(field
.bit_mask
);
316 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
319 static inline u8
rt2x00_get_field8(const u8 reg
,
320 const struct rt2x00_field8 field
)
322 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
326 * Chipset identification
327 * The chipset on the device is composed of a RT and RF chip.
328 * The chipset combination is important for determining device capabilities.
332 #define RT2460 0x0101
333 #define RT2560 0x0201
334 #define RT2570 0x1201
335 #define RT2561 0x0301
336 #define RT2561s 0x0302
337 #define RT2661 0x0401
338 #define RT2571 0x1300
346 * Each data entry also contains a descriptor which is used by the
347 * device to determine what should be done with the packet and
348 * what the current status is.
349 * This structure is greatly simplified, but the descriptors
350 * are basically a list of little endian 32 bit values.
351 * Make the array by default 1 word big, this will allow us
352 * to use sizeof() correctly.
360 * Summary of information that should be written into the
361 * descriptor for sending a TX frame.
363 struct data_entry_desc
{
378 * The data ring is a list of data entries.
379 * Each entry holds a reference to the descriptor
380 * and the data buffer. For TX rings the reference to the
381 * sk_buff of the packet being transmitted is also stored here.
388 #define ENTRY_OWNER_NIC 1
389 #define ENTRY_TXDONE 2
390 #define ENTRY_TXD_RTS_FRAME 3
391 #define ENTRY_TXD_OFDM_RATE 4
392 #define ENTRY_TXD_MORE_FRAG 5
393 #define ENTRY_TXD_REQ_TIMESTAMP 6
394 #define ENTRY_TXD_REQ_ACK 7
395 #define ENTRY_TXD_NEW_SEQ 8
400 struct data_ring
*ring
;
403 * sk_buff for the packet which is being transmitted
404 * in this entry (Only used with TX related rings).
409 * Store a ieee80211_tx_status structure in each
410 * ring entry, this will optimize the txdone
413 struct ieee80211_tx_status tx_status
;
416 * private pointer specific to driver.
421 * Data address for this entry.
429 * Data rings are used by the device to send and receive packets.
430 * The data_addr is the base address of the data memory.
431 * To determine at which point in the ring we are,
432 * have to use the rt2x00_ring_index_*() functions.
436 * Pointer to main rt2x00dev structure where this
439 struct rt2x00_dev
*rt2x00dev
;
442 * Base address for the device specific data entries.
444 struct data_entry
*entry
;
447 * TX queue statistic info.
449 struct ieee80211_tx_queue_stats_data stats
;
452 * TX Queue parameters.
454 struct ieee80211_tx_queue_params tx_params
;
457 * Base address for data ring.
469 * Size of packet and descriptor in bytes.
476 * Handlers to determine the address of the current device specific
477 * data entry, where either index or index_done points to.
479 static inline struct data_entry
* rt2x00_get_data_entry(
480 struct data_ring
*ring
)
482 return &ring
->entry
[ring
->index
];
485 static inline struct data_entry
* rt2x00_get_data_entry_done(
486 struct data_ring
*ring
)
488 return &ring
->entry
[ring
->index_done
];
494 static inline int rt2x00_get_ring_size(struct data_ring
*ring
)
496 return ring
->stats
.limit
* (ring
->desc_size
+ ring
->data_size
);
500 * Ring index manipulation functions.
502 static inline void rt2x00_ring_index_inc(struct data_ring
*ring
)
505 if (ring
->index
>= ring
->stats
.limit
)
510 static inline void rt2x00_ring_index_done_inc(struct data_ring
*ring
)
513 if (ring
->index_done
>= ring
->stats
.limit
)
514 ring
->index_done
= 0;
519 static inline void rt2x00_ring_index_clear(struct data_ring
*ring
)
522 ring
->index_done
= 0;
524 ring
->stats
.count
= 0;
527 static inline int rt2x00_ring_empty(struct data_ring
*ring
)
529 return ring
->stats
.len
== 0;
532 static inline int rt2x00_ring_full(struct data_ring
*ring
)
534 return ring
->stats
.len
== ring
->stats
.limit
;
537 static inline int rt2x00_ring_free(struct data_ring
*ring
)
539 if (ring
->index_done
>= ring
->index
)
540 return ring
->index_done
- ring
->index
;
541 return ring
->stats
.len
- (ring
->index
- ring
->index_done
);
545 * TX/RX Descriptor access functions.
547 static inline void rt2x00_desc_read(struct data_desc
*desc
,
548 const u8 word
, u32
*value
)
550 *value
= le32_to_cpu(desc
->word
[word
]);
553 static inline void rt2x00_desc_write(struct data_desc
*desc
,
554 const u8 word
, const u32 value
)
556 desc
->word
[word
] = cpu_to_le32(value
);
560 * To optimize the quality of the link we need to store
561 * the quality of received frames and periodically
567 * The number of times the link has been tuned
568 * since the radio has been switched on.
585 * Work structure for scheduling periodic link tuning.
587 struct delayed_work work
;
591 * Interface structure
592 * Configuration details about the current interface.
596 * Interface identification. The value is assigned
597 * to us by the 80211 stack, and is used to request
603 * Current working type (IEEE80211_IF_TYPE_*).
604 * This excludes the type IEEE80211_IF_TYPE_MNTR
605 * since that is counted seperately in the monitor_count
611 * BBSID of the AP to associate with.
616 * Store the promisc mode for the current interface.
617 * monitor mode always forces promisc mode to be enabled,
618 * so we need to store the promisc mode seperately.
623 * Monitor mode count, the number of interfaces
624 * in monitor mode that that have been added.
629 static inline int is_interface_present(struct interface
*intf
)
634 static inline int is_monitor_present(struct interface
*intf
)
636 return !!intf
->monitor_count
;
640 * rt2x00lib callback functions.
642 struct rt2x00lib_ops
{
644 * Interrupt handlers.
646 irq_handler_t irq_handler
;
649 * Device init handlers.
651 int (*init_hw
)(struct rt2x00_dev
*rt2x00dev
);
652 char* (*get_fw_name
)(struct rt2x00_dev
*rt2x00dev
);
653 int (*load_firmware
)(struct rt2x00_dev
*rt2x00dev
, void *data
,
657 * Device initialization/deinitialization handlers.
659 int (*initialize
)(struct rt2x00_dev
*rt2x00dev
);
660 void (*uninitialize
)(struct rt2x00_dev
*rt2x00dev
);
663 * Radio control handlers.
665 int (*set_device_state
)(struct rt2x00_dev
*rt2x00dev
,
666 enum dev_state state
);
667 int (*rfkill_poll
)(struct rt2x00_dev
*rt2x00dev
);
668 void (*link_tuner
)(struct rt2x00_dev
*rt2x00dev
, int rssi
);
671 * TX control handlers
673 void (*write_tx_desc
)(struct rt2x00_dev
*rt2x00dev
,
674 struct data_entry
*entry
, struct data_desc
*txd
,
675 struct data_entry_desc
*desc
,
676 struct ieee80211_hdr
*ieee80211hdr
, unsigned int length
,
677 struct ieee80211_tx_control
*control
);
678 int (*write_tx_data
)(struct rt2x00_dev
*rt2x00dev
,
679 struct data_ring
*ring
, struct sk_buff
*skb
,
680 struct ieee80211_tx_control
*control
);
681 void (*kick_tx_queue
)(struct rt2x00_dev
*rt2x00dev
, int queue
);
684 * Configuration handlers.
686 void (*config_type
)(struct rt2x00_dev
*rt2x00dev
, const int type
);
687 void (*config_phymode
)(struct rt2x00_dev
*rt2x00dev
, const int phy
);
688 void (*config_channel
)(struct rt2x00_dev
*rt2x00dev
, const int value
,
689 const int channel
, const int txpower
);
690 void (*config_mac_addr
)(struct rt2x00_dev
*rt2x00dev
, u8
*mac
);
691 void (*config_bssid
)(struct rt2x00_dev
*rt2x00dev
, u8
*bssid
);
692 void (*config_promisc
)(struct rt2x00_dev
*rt2x00dev
, const int promisc
);
693 void (*config_txpower
)(struct rt2x00_dev
*rt2x00dev
, const int txpower
);
694 void (*config_antenna
)(struct rt2x00_dev
*rt2x00dev
,
695 const int antenna_tx
, const int antenna_rx
);
696 void (*config_duration
)(struct rt2x00_dev
*rt2x00dev
,
697 const int short_slot_time
, const int beacon_int
);
701 * rt2x00 driver callback operation structure.
705 const unsigned int rxd_size
;
706 const unsigned int txd_size
;
707 const struct rt2x00lib_ops
*lib
;
708 const struct ieee80211_ops
*hw
;
709 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
710 const struct rt2x00debug
*debugfs
;
711 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
715 * rt2x00 device structure.
720 * The structure stored in here depends on the
721 * system bus (PCI or USB).
722 * When accessing this variable, the rt2x00dev_{pci,usb}
723 * macro's should be used for correct typecasting.
726 struct device
*device
;
727 #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
728 #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
731 * Callback functions.
733 const struct rt2x00_ops
*ops
;
736 * IEEE80211 control structure.
738 struct ieee80211_hw
*hw
;
739 struct ieee80211_hw_mode
*hwmodes
;
740 unsigned int curr_hwmode
;
746 * rfkill structure for RF state switching support.
747 * This will only be compiled in when required.
749 #ifdef CONFIG_RT2X00_LIB_RFKILL
750 struct rfkill
*rfkill
;
751 struct delayed_work rfkill_work
;
752 #endif /* CONFIG_RT2X00_LIB_RFKILL */
756 * In these flags the current status and some
757 * of the device capabilities are stored.
760 #define DEVICE_ENABLED_RADIO 1
761 #define DEVICE_ENABLED_RADIO_HW 2
762 #define DEVICE_INITIALIZED 3
763 #define DEVICE_INITIALIZED_HW 4
764 #define FIRMWARE_REQUIRED 5
765 #define FIRMWARE_LOADED 6
766 #define FIRMWARE_FAILED 7
767 #define INTERFACE_ENABLED 8
768 #define INTERFACE_ENABLED_MONITOR 9
769 #define INTERFACE_ENABLED_PROMISC 10
770 #define DEVICE_SUPPORT_ATIM 11
771 #define DEVICE_SUPPORT_HW_BUTTON 12
772 #define CONFIG_FRAME_TYPE 13
773 #define CONFIG_RF_SEQUENCE 14
774 #define CONFIG_EXTERNAL_LNA 15
775 #define CONFIG_EXTERNAL_LNA_A 16
776 #define CONFIG_EXTERNAL_LNA_BG 17
777 #define CONFIG_DOUBLE_ANTENNA 18
778 #define CONFIG_DISABLE_LINK_TUNING 19
781 * Chipset identification.
783 struct rt2x00_chip chip
;
786 * hw capability specifications.
788 struct hw_mode_spec spec
;
791 * Base address of device registers (PCI devices only).
793 void __iomem
*csr_addr
;
796 * If enabled, the debugfs interface structures
797 * required for deregistration of debugfs.
799 const struct rt2x00debug_intf
*debugfs_intf
;
802 * Queue for deferred work.
804 struct workqueue_struct
*workqueue
;
807 * Interface configuration.
809 struct interface interface
;
822 * Active RF register values.
823 * These are stored here for easier working
824 * with the rf registers.
832 * Current TX power value.
837 * LED register (for rt61pci & rt73usb).
842 * Led mode (LED_MODE_*)
847 * EEPROM bus width (PCI devices only).
852 * Frequency offset (for rt61pci & rt73usb).
857 * Low level statistics which will have
858 * to be kept up to date while device is running.
860 struct ieee80211_low_level_stats low_level_stats
;
863 * RX configuration information.
865 struct ieee80211_rx_status rx_status
;
868 * Data ring arrays for RX, TX and Beacon.
869 * The Beacon array also contains the Atim ring
870 * if that is supported by the device.
872 struct data_ring
*rx
;
873 struct data_ring
*tx
;
874 struct data_ring
*bcn
;
877 static inline struct data_ring
* rt2x00_get_ring(
878 struct rt2x00_dev
*rt2x00dev
, const unsigned int queue
)
880 int atim
= test_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
883 * Check if the rings have been allocated.
885 if (!rt2x00dev
->tx
|| !rt2x00dev
->bcn
)
889 * Check if we are requesting a reqular TX ring,
890 * or if we are requesting a Beacon or Atim ring.
891 * For Atim rings, we should check if it is supported.
893 if (queue
< rt2x00dev
->hw
->queues
)
894 return &rt2x00dev
->tx
[queue
];
895 else if (queue
== IEEE80211_TX_QUEUE_BEACON
)
896 return &rt2x00dev
->bcn
[0];
897 else if (queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
&& atim
)
898 return &rt2x00dev
->bcn
[1];
904 * For-each loop for the ring array.
905 * Since the all rings are allocated as a single array,
906 * we can start at the rx pointer and move forward to the tx rings.
907 * The 1 + Atim check will assure that the address directly after
908 * the ring array is obtained and the for-each loop exits correctly.
910 #define ring_for_each(__dev, __entry) \
911 for ((__entry) = (__dev)->rx; \
912 (__entry) != &(__dev)->bcn[1 + \
913 test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags)]; \
916 #define txring_for_each(__dev, __entry) \
917 for ((__entry) = (__dev)->tx; (__entry) != (__dev)->bcn; (__entry)++)
921 * The EEPROM is being accessed by word index.
923 static inline void* rt2x00_eeprom_addr(const struct rt2x00_dev
*rt2x00dev
,
926 return (void*)&rt2x00dev
->eeprom
[word
];
929 static inline void rt2x00_eeprom_read(const struct rt2x00_dev
*rt2x00dev
,
930 const u8 word
, u16
*data
)
932 *data
= le16_to_cpu(rt2x00dev
->eeprom
[word
]);
935 static inline void rt2x00_eeprom_write(const struct rt2x00_dev
*rt2x00dev
,
936 const u8 word
, u16 data
)
938 rt2x00dev
->eeprom
[word
] = cpu_to_le16(data
);
942 * Link tuning handlers
944 static inline void rt2x00_start_link_tune(struct rt2x00_dev
*rt2x00dev
)
946 rt2x00dev
->link
.count
= 0;
947 rt2x00dev
->link
.count_rssi
= 0;
948 rt2x00dev
->link
.total_rssi
= 0;
949 rt2x00dev
->link
.curr_noise
= 0;
951 queue_delayed_work(rt2x00dev
->workqueue
,
952 &rt2x00dev
->link
.work
, LINK_TUNE_INTERVAL
);
955 static inline void rt2x00_stop_link_tune(struct rt2x00_dev
*rt2x00dev
)
957 if (work_pending(&rt2x00dev
->link
.work
.work
))
958 cancel_rearming_delayed_workqueue(
959 rt2x00dev
->workqueue
, &rt2x00dev
->link
.work
);
962 static inline void rt2x00_update_link_rssi(struct link
*link
, u32 rssi
)
965 link
->total_rssi
+= rssi
;
968 static inline u32
rt2x00_get_link_rssi(struct link
*link
)
972 if (link
->count_rssi
&& link
->total_rssi
)
973 average
= link
->total_rssi
/ link
->count_rssi
;
975 link
->count_rssi
= 0;
976 link
->total_rssi
= 0;
984 static inline void rt2x00_set_chip(struct rt2x00_dev
*rt2x00dev
,
985 const u16 rt
, const u16 rf
, const u32 rev
)
988 "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
991 rt2x00dev
->chip
.rt
= rt
;
992 rt2x00dev
->chip
.rf
= rf
;
993 rt2x00dev
->chip
.rev
= rev
;
996 static inline char rt2x00_rt(const struct rt2x00_chip
*chipset
, const u16 chip
)
998 return (chipset
->rt
== chip
);
1001 static inline char rt2x00_rf(const struct rt2x00_chip
*chipset
, const u16 chip
)
1003 return (chipset
->rf
== chip
);
1006 static inline u16
rt2x00_rev(const struct rt2x00_chip
*chipset
)
1008 return chipset
->rev
;
1012 * Device specific rate value.
1013 * We will have to create the device specific rate value
1014 * passed to the ieee80211 kernel. We need to make it a consist of
1015 * multiple fields because we want to store more then 1 device specific
1016 * values inside the value.
1017 * 1 - rate, stored as 100 kbit/s.
1018 * 2 - preamble, short_preamble enabled flag.
1019 * 3 - MASK_RATE, which rates are enabled in this mode, this mask
1020 * corresponds with the TX register format for the current device.
1021 * 4 - plcp, 802.11b rates are device specific,
1022 * 802.11g rates are set according to the ieee802.11a-1999 p.14.
1023 * The bit to enable preamble is set in a seperate define.
1025 #define DEV_RATE FIELD32(0x000007ff)
1026 #define DEV_PREAMBLE FIELD32(0x00000800)
1027 #define DEV_RATEMASK FIELD32(0x00fff000)
1028 #define DEV_PLCP FIELD32(0xff000000)
1031 * Bitmask for MASK_RATE
1033 #define DEV_RATE_1MB 0x00000001
1034 #define DEV_RATE_2MB 0x00000002
1035 #define DEV_RATE_5_5MB 0x00000004
1036 #define DEV_RATE_11MB 0x00000008
1037 #define DEV_RATE_6MB 0x00000010
1038 #define DEV_RATE_9MB 0x00000020
1039 #define DEV_RATE_12MB 0x00000040
1040 #define DEV_RATE_18MB 0x00000080
1041 #define DEV_RATE_24MB 0x00000100
1042 #define DEV_RATE_36MB 0x00000200
1043 #define DEV_RATE_48MB 0x00000400
1044 #define DEV_RATE_54MB 0x00000800
1047 * Bitmask groups of bitrates
1049 #define DEV_BASIC_RATE \
1050 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB | \
1051 DEV_RATE_6MB | DEV_RATE_12MB | DEV_RATE_24MB )
1053 #define DEV_CCK_RATE \
1054 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB )
1056 #define DEV_OFDM_RATE \
1057 ( DEV_RATE_6MB | DEV_RATE_9MB | DEV_RATE_12MB | DEV_RATE_18MB | \
1058 DEV_RATE_24MB | DEV_RATE_36MB | DEV_RATE_48MB | DEV_RATE_54MB )
1061 * Macro's to set and get specific fields from the device specific val and val2
1062 * fields inside the ieee80211_rate entry.
1064 #define DEVICE_SET_RATE_FIELD(__value, __mask) \
1065 (int)( ((__value) << DEV_##__mask.bit_offset) & DEV_##__mask.bit_mask )
1067 #define DEVICE_GET_RATE_FIELD(__value, __mask) \
1068 (int)( ((__value) & DEV_##__mask.bit_mask) >> DEV_##__mask.bit_offset )
1071 * Duration calculations
1072 * The rate variable passed is: 100kbs.
1073 * To convert from bytes to bits we multiply size with 8,
1074 * then the size is multiplied with 10 to make the
1075 * real rate -> rate argument correction.
1077 static inline u16
get_duration(const unsigned int size
, const u8 rate
)
1079 return ((size
* 8 * 10) / rate
);
1082 static inline u16
get_duration_res(const unsigned int size
, const u8 rate
)
1084 return ((size
* 8 * 10) % rate
);
1087 #endif /* RT2X00_H */