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/prefetch.h>
33 #include <linux/skbuff.h>
34 #include <linux/workqueue.h>
36 #include <net/mac80211.h>
40 * DRV_NAME should be set within the individual module source files.
42 #define DRV_VERSION "2.0.2"
43 #define DRV_PROJECT "http://rt2x00.serialmonkey.com"
47 * Debug output has to be enabled during compile time.
49 #define DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, __args...) \
50 printk(__kernlvl "%s -> %s: %s - " __msg, \
51 wiphy_name(rt2x00dev->hw->wiphy), \
52 __FUNCTION__, __lvl, ##__args)
54 #define DEBUG_PRINTK_PROBE(__kernlvl, __lvl, __msg, __args...) \
55 printk(__kernlvl "%s -> %s: %s - " __msg, \
56 DRV_NAME, __FUNCTION__, __lvl, ##__args)
58 #ifdef CONFIG_RT2X00_DEBUG
59 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
60 DEBUG_PRINTK_MSG(__dev, __kernlvl, __lvl, __msg, ##__args);
61 #else /* CONFIG_RT2X00_DEBUG */
62 #define DEBUG_PRINTK(__dev, __kernlvl, __lvl, __msg, __args...) \
64 #endif /* CONFIG_RT2X00_DEBUG */
67 * Various debug levels.
68 * The debug levels PANIC and ERROR both indicate serious problems,
69 * for this reason they should never be ignored.
70 * The special ERROR_PROBE message is for messages that are generated
71 * when the rt2x00_dev is not yet initialized.
73 #define PANIC(__dev, __msg, __args...) \
74 DEBUG_PRINTK_MSG(__dev, KERN_CRIT, "Panic", __msg, ##__args)
75 #define ERROR(__dev, __msg, __args...) \
76 DEBUG_PRINTK_MSG(__dev, KERN_ERR, "Error", __msg, ##__args)
77 #define ERROR_PROBE(__msg, __args...) \
78 DEBUG_PRINTK_PROBE(KERN_ERR, "Error", __msg, ##__args)
79 #define WARNING(__dev, __msg, __args...) \
80 DEBUG_PRINTK(__dev, KERN_WARNING, "Warning", __msg, ##__args)
81 #define NOTICE(__dev, __msg, __args...) \
82 DEBUG_PRINTK(__dev, KERN_NOTICE, "Notice", __msg, ##__args)
83 #define INFO(__dev, __msg, __args...) \
84 DEBUG_PRINTK(__dev, KERN_INFO, "Info", __msg, ##__args)
85 #define DEBUG(__dev, __msg, __args...) \
86 DEBUG_PRINTK(__dev, KERN_DEBUG, "Debug", __msg, ##__args)
87 #define EEPROM(__dev, __msg, __args...) \
88 DEBUG_PRINTK(__dev, KERN_DEBUG, "EEPROM recovery", __msg, ##__args)
92 * Ralink PCI devices demand the Frame size to be a multiple of 128 bytes.
93 * DATA_FRAME_SIZE is used for TX, RX, ATIM and PRIO rings.
94 * MGMT_FRAME_SIZE is used for the BEACON ring.
96 #define DATA_FRAME_SIZE 2432
97 #define MGMT_FRAME_SIZE 256
100 * Number of entries in a packet ring.
102 #define RX_ENTRIES 12
103 #define TX_ENTRIES 12
104 #define ATIM_ENTRIES 1
105 #define BEACON_ENTRIES 1
108 * Standard timing and size defines.
111 #define IEEE80211_HEADER 24
115 #define SHORT_PREAMBLE 72
117 #define SHORT_SLOT_TIME 9
119 #define PIFS ( SIFS + SLOT_TIME )
120 #define SHORT_PIFS ( SIFS + SHORT_SLOT_TIME )
121 #define DIFS ( PIFS + SLOT_TIME )
122 #define SHORT_DIFS ( SHORT_PIFS + SHORT_SLOT_TIME )
123 #define EIFS ( SIFS + (8 * (IEEE80211_HEADER + ACK_SIZE)) )
126 * IEEE802.11 header defines
128 #define is_rts_frame(__fc) \
129 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
130 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_RTS)) )
131 #define is_cts_frame(__fc) \
132 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && \
133 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_CTS)) )
134 #define is_probe_resp(__fc) \
135 ( !!((((__fc) & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) && \
136 (((__fc) & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)) )
141 #define LINK_TUNE_INTERVAL ( round_jiffies(HZ) )
142 #define RFKILL_POLL_INTERVAL ( HZ / 4 )
149 TX_SUCCESS_RETRY
= 1,
159 ANTENNA_DIVERSITY
= 0,
168 LED_MODE_DEFAULT
= 0,
169 LED_MODE_TXRX_ACTIVITY
= 1,
170 LED_MODE_SIGNAL_STRENGTH
= 2,
179 STATE_DEEP_SLEEP
= 0,
185 * Additional device states, these values are
186 * not strict since they are not directly passed
206 * Cipher types for hardware encryption
215 * The following fields were added by rt61pci and rt73usb.
219 CIPHER_TKIP_NO_MIC
= 7,
224 * We store the position of a register field inside a field structure,
225 * This will simplify the process of setting and reading a certain field
226 * inside the register while making sure the process remains byte order safe.
228 struct rt2x00_field8
{
233 struct rt2x00_field16
{
238 struct rt2x00_field32
{
244 * Power of two check from Linus Torvalds,
245 * this will check if the mask that has been
246 * given contains and contiguous set of bits.
248 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
249 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
250 #define is_valid_mask(x) is_power_of_two(1 + (x) + low_bit_mask(x))
252 #define FIELD8(__mask) \
254 BUILD_BUG_ON(!(__mask) || \
255 !is_valid_mask(__mask) || \
256 (__mask) != (u8)(__mask)); \
257 (struct rt2x00_field8) { \
258 __ffs(__mask), (__mask) \
262 #define FIELD16(__mask) \
264 BUILD_BUG_ON(!(__mask) || \
265 !is_valid_mask(__mask) || \
266 (__mask) != (u16)(__mask));\
267 (struct rt2x00_field16) { \
268 __ffs(__mask), (__mask) \
272 #define FIELD32(__mask) \
274 BUILD_BUG_ON(!(__mask) || \
275 !is_valid_mask(__mask) || \
276 (__mask) != (u32)(__mask));\
277 (struct rt2x00_field32) { \
278 __ffs(__mask), (__mask) \
282 static inline void rt2x00_set_field32(u32
*reg
,
283 const struct rt2x00_field32 field
, const u32 value
)
285 *reg
&= ~(field
.bit_mask
);
286 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
289 static inline u32
rt2x00_get_field32(const u32 reg
,
290 const struct rt2x00_field32 field
)
292 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
295 static inline void rt2x00_set_field16(u16
*reg
,
296 const struct rt2x00_field16 field
, const u16 value
)
298 *reg
&= ~(field
.bit_mask
);
299 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
302 static inline u16
rt2x00_get_field16(const u16 reg
,
303 const struct rt2x00_field16 field
)
305 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
308 static inline void rt2x00_set_field8(u8
*reg
,
309 const struct rt2x00_field8 field
, const u8 value
)
311 *reg
&= ~(field
.bit_mask
);
312 *reg
|= (value
<< field
.bit_offset
) & field
.bit_mask
;
315 static inline u8
rt2x00_get_field8(const u8 reg
,
316 const struct rt2x00_field8 field
)
318 return (reg
& field
.bit_mask
) >> field
.bit_offset
;
322 * Chipset identification
323 * The chipset on the device is composed of a RT and RF chip.
324 * The chipset combination is important for determining device capabilities.
328 #define RT2460 0x0101
329 #define RT2560 0x0201
330 #define RT2570 0x1201
331 #define RT2561 0x0301
332 #define RT2561s 0x0302
333 #define RT2661 0x0401
334 #define RT2571 0x1300
342 * Each data entry also contains a descriptor which is used by the
343 * device to determine what should be done with the packet and
344 * what the current status is.
345 * This structure is greatly simplified, but the descriptors
346 * are basically a list of little endian 32 bit values.
347 * Make the array by default 1 word big, this will allow us
348 * to use sizeof() correctly.
356 * Summary of information that should be written into the
357 * descriptor for sending a TX frame.
359 struct data_entry_desc
{
374 * The data ring is a list of data entries.
375 * Each entry holds a reference to the descriptor
376 * and the data buffer. For TX rings the reference to the
377 * sk_buff of the packet being transmitted is also stored here.
384 #define ENTRY_OWNER_NIC 1
385 #define ENTRY_TXDONE 2
386 #define ENTRY_TXD_RTS_FRAME 3
387 #define ENTRY_TXD_OFDM_RATE 4
388 #define ENTRY_TXD_MORE_FRAG 5
389 #define ENTRY_TXD_REQ_TIMESTAMP 6
390 #define ENTRY_TXD_REQ_ACK 7
395 struct data_ring
*ring
;
398 * sk_buff for the packet which is being transmitted
399 * in this entry (Only used with TX related rings).
404 * Store a ieee80211_tx_status structure in each
405 * ring entry, this will optimize the txdone
408 struct ieee80211_tx_status tx_status
;
411 * private pointer specific to driver.
416 * Data address for this entry.
424 * Data rings are used by the device to send and receive packets.
425 * The data_addr is the base address of the data memory.
426 * To determine at which point in the ring we are,
427 * have to use the rt2x00_ring_index_*() functions.
431 * Pointer to main rt2x00dev structure where this
434 struct rt2x00_dev
*rt2x00dev
;
437 * Base address for the device specific data entries.
439 struct data_entry
*entry
;
442 * TX queue statistic info.
444 struct ieee80211_tx_queue_stats_data stats
;
447 * TX Queue parameters.
449 struct ieee80211_tx_queue_params tx_params
;
452 * Base address for data ring.
464 * Size of packet and descriptor in bytes.
471 * Handlers to determine the address of the current device specific
472 * data entry, where either index or index_done points to.
474 static inline struct data_entry
* rt2x00_get_data_entry(
475 struct data_ring
*ring
)
477 return &ring
->entry
[ring
->index
];
480 static inline struct data_entry
* rt2x00_get_data_entry_done(
481 struct data_ring
*ring
)
483 return &ring
->entry
[ring
->index_done
];
489 static inline int rt2x00_get_ring_size(struct data_ring
*ring
)
491 return ring
->stats
.limit
* (ring
->desc_size
+ ring
->data_size
);
495 * Ring index manipulation functions.
497 static inline void rt2x00_ring_index_inc(struct data_ring
*ring
)
500 if (ring
->index
>= ring
->stats
.limit
)
505 static inline void rt2x00_ring_index_done_inc(struct data_ring
*ring
)
508 if (ring
->index_done
>= ring
->stats
.limit
)
509 ring
->index_done
= 0;
514 static inline void rt2x00_ring_index_clear(struct data_ring
*ring
)
517 ring
->index_done
= 0;
519 ring
->stats
.count
= 0;
522 static inline int rt2x00_ring_empty(struct data_ring
*ring
)
524 return ring
->stats
.len
== 0;
527 static inline int rt2x00_ring_full(struct data_ring
*ring
)
529 return ring
->stats
.len
== ring
->stats
.limit
;
532 static inline int rt2x00_ring_free(struct data_ring
*ring
)
534 if (ring
->index_done
>= ring
->index
)
535 return ring
->index_done
- ring
->index
;
536 return ring
->stats
.len
- (ring
->index
- ring
->index_done
);
540 * TX/RX Descriptor access functions.
542 static inline void rt2x00_desc_read(struct data_desc
*desc
,
543 const u8 word
, u32
*value
)
545 *value
= le32_to_cpu(desc
->word
[word
]);
548 static inline void rt2x00_desc_write(struct data_desc
*desc
,
549 const u8 word
, const u32 value
)
551 desc
->word
[word
] = cpu_to_le32(value
);
555 * To optimize the quality of the link we need to store
556 * the quality of received frames and periodically
562 * The number of times the link has been tuned
563 * since the radio has been switched on.
569 * For the average RSSI value we use the "Walking average" approach.
570 * When adding RSSI to the average value the following calculation
573 * avg_rssi = ((avg_rssi * 7) + rssi) / 8;
575 * The advantage of this approach is that we only need 1 variable
576 * to store the average in (No need for a count and a total).
577 * But more importantly, normal average values will over time
578 * move less and less towards newly added values.
579 * This means that with link tuning, the device can have a very
580 * good RSSI for a few minutes but when the device is moved away
581 * from the AP the average will not decrease fast enough to
582 * compensate. The walking average compensates this and will
583 * move towards the new values correctly.
589 * Work structure for scheduling periodic link tuning.
591 struct delayed_work work
;
595 * Interface structure
596 * Configuration details about the current interface.
600 * Interface identification. The value is assigned
601 * to us by the 80211 stack, and is used to request
607 * Current working type (IEEE80211_IF_TYPE_*).
608 * This excludes the type IEEE80211_IF_TYPE_MNTR
609 * since that is counted seperately in the monitor_count
615 * BBSID of the AP to associate with.
620 * Store the promisc mode for the current interface.
621 * monitor mode always forces promisc mode to be enabled,
622 * so we need to store the promisc mode seperately.
627 * Monitor mode count, the number of interfaces
628 * in monitor mode that that have been added.
633 static inline int is_interface_present(struct interface
*intf
)
638 static inline int is_monitor_present(struct interface
*intf
)
640 return !!intf
->monitor_count
;
644 * Details about the supported modes, rates and channels
645 * of a particular chipset. This is used by rt2x00lib
646 * to build the ieee80211_hw_mode array for mac80211.
648 struct hw_mode_spec
{
650 * Number of modes, rates and channels.
659 const u8
*tx_power_a
;
660 const u8
*tx_power_bg
;
664 * Device/chipset specific value.
666 const u32
*chan_val_a
;
667 const u32
*chan_val_bg
;
671 * rt2x00lib callback functions.
673 struct rt2x00lib_ops
{
675 * Interrupt handlers.
677 irq_handler_t irq_handler
;
680 * Device init handlers.
682 int (*init_hw
)(struct rt2x00_dev
*rt2x00dev
);
683 char* (*get_fw_name
)(struct rt2x00_dev
*rt2x00dev
);
684 int (*load_firmware
)(struct rt2x00_dev
*rt2x00dev
, void *data
,
688 * Device initialization/deinitialization handlers.
690 int (*initialize
)(struct rt2x00_dev
*rt2x00dev
);
691 void (*uninitialize
)(struct rt2x00_dev
*rt2x00dev
);
694 * Radio control handlers.
696 int (*set_device_state
)(struct rt2x00_dev
*rt2x00dev
,
697 enum dev_state state
);
698 int (*rfkill_poll
)(struct rt2x00_dev
*rt2x00dev
);
699 void (*link_tuner
)(struct rt2x00_dev
*rt2x00dev
);
702 * TX control handlers
704 void (*write_tx_desc
)(struct rt2x00_dev
*rt2x00dev
,
705 struct data_entry
*entry
, struct data_desc
*txd
,
706 struct data_entry_desc
*desc
,
707 struct ieee80211_hdr
*ieee80211hdr
, unsigned int length
,
708 struct ieee80211_tx_control
*control
);
709 int (*write_tx_data
)(struct rt2x00_dev
*rt2x00dev
,
710 struct data_ring
*ring
, struct sk_buff
*skb
,
711 struct ieee80211_tx_control
*control
);
712 void (*kick_tx_queue
)(struct rt2x00_dev
*rt2x00dev
, int queue
);
715 * RX control handlers
717 int (*fill_rxdone
)(struct data_entry
*entry
,
718 int *signal
, int *rssi
, int *ofdm
);
721 * Configuration handlers.
723 void (*config_type
)(struct rt2x00_dev
*rt2x00dev
, const int type
);
724 void (*config_phymode
)(struct rt2x00_dev
*rt2x00dev
, const int phy
);
725 void (*config_channel
)(struct rt2x00_dev
*rt2x00dev
, const int value
,
726 const int channel
, const int txpower
);
727 void (*config_mac_addr
)(struct rt2x00_dev
*rt2x00dev
, u8
*mac
);
728 void (*config_bssid
)(struct rt2x00_dev
*rt2x00dev
, u8
*bssid
);
729 void (*config_promisc
)(struct rt2x00_dev
*rt2x00dev
, const int promisc
);
730 void (*config_txpower
)(struct rt2x00_dev
*rt2x00dev
, const int txpower
);
731 void (*config_antenna
)(struct rt2x00_dev
*rt2x00dev
,
732 const int antenna_tx
, const int antenna_rx
);
733 void (*config_duration
)(struct rt2x00_dev
*rt2x00dev
,
734 const int short_slot_time
, const int beacon_int
);
738 * rt2x00 driver callback operation structure.
742 const unsigned int rxd_size
;
743 const unsigned int txd_size
;
744 const struct rt2x00lib_ops
*lib
;
745 const struct ieee80211_ops
*hw
;
746 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
747 const struct rt2x00debug
*debugfs
;
748 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
752 * rt2x00 device structure.
757 * The structure stored in here depends on the
758 * system bus (PCI or USB).
759 * When accessing this variable, the rt2x00dev_{pci,usb}
760 * macro's should be used for correct typecasting.
763 #define rt2x00dev_pci(__dev) ( (struct pci_dev*)(__dev)->dev )
764 #define rt2x00dev_usb(__dev) ( (struct usb_interface*)(__dev)->dev )
767 * Callback functions.
769 const struct rt2x00_ops
*ops
;
772 * IEEE80211 control structure.
774 struct ieee80211_hw
*hw
;
775 struct ieee80211_hw_mode
*hwmodes
;
776 unsigned int curr_hwmode
;
782 * rfkill structure for RF state switching support.
783 * This will only be compiled in when required.
785 #ifdef CONFIG_RT2X00_LIB_RFKILL
786 struct rfkill
*rfkill
;
787 struct delayed_work rfkill_work
;
788 #endif /* CONFIG_RT2X00_LIB_RFKILL */
792 * In these flags the current status and some
793 * of the device capabilities are stored.
796 #define DEVICE_ENABLED_RADIO 1
797 #define DEVICE_ENABLED_RADIO_HW 2
798 #define DEVICE_INITIALIZED 3
799 #define DEVICE_INITIALIZED_HW 4
800 #define FIRMWARE_REQUIRED 5
801 #define FIRMWARE_LOADED 6
802 #define FIRMWARE_FAILED 7
803 #define INTERFACE_ENABLED 8
804 #define INTERFACE_ENABLED_MONITOR 9
805 #define INTERFACE_ENABLED_PROMISC 10
806 #define DEVICE_SUPPORT_ATIM 11
807 #define DEVICE_SUPPORT_HW_BUTTON 12
808 #define CONFIG_FRAME_TYPE 13
809 #define CONFIG_RF_SEQUENCE 14
810 #define CONFIG_EXTERNAL_LNA 15
811 #define CONFIG_EXTERNAL_LNA_A 16
812 #define CONFIG_EXTERNAL_LNA_BG 17
813 #define CONFIG_DOUBLE_ANTENNA 18
814 #define CONFIG_DISABLE_LINK_TUNING 19
817 * Chipset identification.
819 struct rt2x00_chip chip
;
822 * hw capability specifications.
824 struct hw_mode_spec spec
;
827 * Base address of device registers (PCI devices only).
829 void __iomem
*csr_addr
;
832 * If enabled, the debugfs interface structures
833 * required for deregistration of debugfs.
835 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
836 const struct rt2x00debug_intf
*debugfs_intf
;
837 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
840 * Interface configuration.
842 struct interface interface
;
855 * Active RF register values.
856 * These are stored here for easier working
857 * with the rf registers.
865 * Current TX power value.
870 * LED register (for rt61pci & rt73usb).
875 * Led mode (LED_MODE_*)
880 * Rssi <-> Dbm offset
885 * Frequency offset (for rt61pci & rt73usb).
890 * Low level statistics which will have
891 * to be kept up to date while device is running.
893 struct ieee80211_low_level_stats low_level_stats
;
896 * RX configuration information.
898 struct ieee80211_rx_status rx_status
;
901 * Data ring arrays for RX, TX and Beacon.
902 * The Beacon array also contains the Atim ring
903 * if that is supported by the device.
905 struct data_ring
*rx
;
906 struct data_ring
*tx
;
907 struct data_ring
*bcn
;
910 static inline struct data_ring
* rt2x00_get_ring(
911 struct rt2x00_dev
*rt2x00dev
, const unsigned int queue
)
913 int atim
= test_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
916 * Check if the rings have been allocated.
918 if (!rt2x00dev
->tx
|| !rt2x00dev
->bcn
)
922 * Check if we are requesting a reqular TX ring,
923 * or if we are requesting a Beacon or Atim ring.
924 * For Atim rings, we should check if it is supported.
926 if (queue
< rt2x00dev
->hw
->queues
)
927 return &rt2x00dev
->tx
[queue
];
928 else if (queue
== IEEE80211_TX_QUEUE_BEACON
)
929 return &rt2x00dev
->bcn
[0];
930 else if (queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
&& atim
)
931 return &rt2x00dev
->bcn
[1];
937 * For-each loop for the ring array.
938 * Since the all rings are allocated as a single array,
939 * we can start at the rx pointer and move forward to the tx rings.
940 * The 1 + Atim check will assure that the address directly after
941 * the ring array is obtained and the for-each loop exits correctly.
943 #define ring_end(__dev) \
944 &(__dev)->bcn[1 + test_bit(DEVICE_SUPPORT_ATIM, &rt2x00dev->flags)]
946 #define ring_loop(__entry, __start, __end) \
947 for ((__entry) = (__start); \
948 prefetch(&(__entry)[1]), (__entry) != (__end); \
949 (__entry) = &(__entry)[1])
951 #define ring_for_each(__dev, __entry) \
952 ring_loop(__entry, (__dev)->rx, ring_end(__dev))
954 #define txring_for_each(__dev, __entry) \
955 ring_loop(__entry, (__dev)->tx, (__dev)->bcn)
957 #define txringall_for_each(__dev, __entry) \
958 ring_loop(__entry, (__dev)->tx, ring_end(__dev))
962 * The EEPROM is being accessed by word index.
964 static inline void* rt2x00_eeprom_addr(const struct rt2x00_dev
*rt2x00dev
,
967 return (void*)&rt2x00dev
->eeprom
[word
];
970 static inline void rt2x00_eeprom_read(const struct rt2x00_dev
*rt2x00dev
,
971 const u8 word
, u16
*data
)
973 *data
= le16_to_cpu(rt2x00dev
->eeprom
[word
]);
976 static inline void rt2x00_eeprom_write(const struct rt2x00_dev
*rt2x00dev
,
977 const u8 word
, u16 data
)
979 rt2x00dev
->eeprom
[word
] = cpu_to_le16(data
);
983 * Link tuning handlers
985 static inline void rt2x00_start_link_tune(struct rt2x00_dev
*rt2x00dev
)
987 rt2x00dev
->link
.count
= 0;
988 rt2x00dev
->link
.avg_rssi
= 0;
989 rt2x00dev
->link
.false_cca
= 0;
991 queue_delayed_work(rt2x00dev
->hw
->workqueue
,
992 &rt2x00dev
->link
.work
, LINK_TUNE_INTERVAL
);
995 static inline void rt2x00_stop_link_tune(struct rt2x00_dev
*rt2x00dev
)
997 if (work_pending(&rt2x00dev
->link
.work
.work
))
998 cancel_rearming_delayed_workqueue(
999 rt2x00dev
->hw
->workqueue
, &rt2x00dev
->link
.work
);
1002 static inline void rt2x00_update_link_rssi(struct link
*link
, int rssi
)
1004 if (!link
->avg_rssi
)
1005 link
->avg_rssi
= rssi
;
1007 link
->avg_rssi
= ((link
->avg_rssi
* 7) + rssi
) / 8;
1010 static inline int rt2x00_get_link_rssi(struct link
*link
)
1012 return link
->avg_rssi
;
1018 static inline void rt2x00_set_chip(struct rt2x00_dev
*rt2x00dev
,
1019 const u16 rt
, const u16 rf
, const u32 rev
)
1022 "Chipset detected - rt: %04x, rf: %04x, rev: %08x.\n",
1025 rt2x00dev
->chip
.rt
= rt
;
1026 rt2x00dev
->chip
.rf
= rf
;
1027 rt2x00dev
->chip
.rev
= rev
;
1030 static inline char rt2x00_rt(const struct rt2x00_chip
*chipset
, const u16 chip
)
1032 return (chipset
->rt
== chip
);
1035 static inline char rt2x00_rf(const struct rt2x00_chip
*chipset
, const u16 chip
)
1037 return (chipset
->rf
== chip
);
1040 static inline u16
rt2x00_rev(const struct rt2x00_chip
*chipset
)
1042 return chipset
->rev
;
1046 * Device specific rate value.
1047 * We will have to create the device specific rate value
1048 * passed to the ieee80211 kernel. We need to make it a consist of
1049 * multiple fields because we want to store more then 1 device specific
1050 * values inside the value.
1051 * 1 - rate, stored as 100 kbit/s.
1052 * 2 - preamble, short_preamble enabled flag.
1053 * 3 - MASK_RATE, which rates are enabled in this mode, this mask
1054 * corresponds with the TX register format for the current device.
1055 * 4 - plcp, 802.11b rates are device specific,
1056 * 802.11g rates are set according to the ieee802.11a-1999 p.14.
1057 * The bit to enable preamble is set in a seperate define.
1059 #define DEV_RATE FIELD32(0x000007ff)
1060 #define DEV_PREAMBLE FIELD32(0x00000800)
1061 #define DEV_RATEMASK FIELD32(0x00fff000)
1062 #define DEV_PLCP FIELD32(0xff000000)
1065 * Bitmask for MASK_RATE
1067 #define DEV_RATE_1MB 0x00000001
1068 #define DEV_RATE_2MB 0x00000002
1069 #define DEV_RATE_5_5MB 0x00000004
1070 #define DEV_RATE_11MB 0x00000008
1071 #define DEV_RATE_6MB 0x00000010
1072 #define DEV_RATE_9MB 0x00000020
1073 #define DEV_RATE_12MB 0x00000040
1074 #define DEV_RATE_18MB 0x00000080
1075 #define DEV_RATE_24MB 0x00000100
1076 #define DEV_RATE_36MB 0x00000200
1077 #define DEV_RATE_48MB 0x00000400
1078 #define DEV_RATE_54MB 0x00000800
1081 * Bitmask groups of bitrates
1083 #define DEV_BASIC_RATE \
1084 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB | \
1085 DEV_RATE_6MB | DEV_RATE_12MB | DEV_RATE_24MB )
1087 #define DEV_CCK_RATE \
1088 ( DEV_RATE_1MB | DEV_RATE_2MB | DEV_RATE_5_5MB | DEV_RATE_11MB )
1090 #define DEV_OFDM_RATE \
1091 ( DEV_RATE_6MB | DEV_RATE_9MB | DEV_RATE_12MB | DEV_RATE_18MB | \
1092 DEV_RATE_24MB | DEV_RATE_36MB | DEV_RATE_48MB | DEV_RATE_54MB )
1095 * Macro's to set and get specific fields from the device specific val and val2
1096 * fields inside the ieee80211_rate entry.
1098 #define DEVICE_SET_RATE_FIELD(__value, __mask) \
1099 (int)( ((__value) << DEV_##__mask.bit_offset) & DEV_##__mask.bit_mask )
1101 #define DEVICE_GET_RATE_FIELD(__value, __mask) \
1102 (int)( ((__value) & DEV_##__mask.bit_mask) >> DEV_##__mask.bit_offset )
1105 * Duration calculations
1106 * The rate variable passed is: 100kbs.
1107 * To convert from bytes to bits we multiply size with 8,
1108 * then the size is multiplied with 10 to make the
1109 * real rate -> rate argument correction.
1111 static inline u16
get_duration(const unsigned int size
, const u8 rate
)
1113 return ((size
* 8 * 10) / rate
);
1116 static inline u16
get_duration_res(const unsigned int size
, const u8 rate
)
1118 return ((size
* 8 * 10) % rate
);
1121 #endif /* RT2X00_H */