add updated mac80211 - this no longer relies on patching includes in the kernel trees...
[openwrt/staging/yousong.git] / package / bcm43xx-mac80211 / src / bcm43xx / bcm43xx_main.h
1 /*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mb@bu3sch.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29 */
30
31 #ifndef BCM43xx_MAIN_H_
32 #define BCM43xx_MAIN_H_
33
34 #include "bcm43xx.h"
35
36
37 #define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
38 #define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
39 /* Magic helper macro to pad structures. Ignore those above. It's magic. */
40 #define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
41
42
43 /* Lightweight function to convert a frequency (in Mhz) to a channel number. */
44 static inline
45 u8 bcm43xx_freq_to_channel_a(int freq)
46 {
47 return ((freq - 5000) / 5);
48 }
49 static inline
50 u8 bcm43xx_freq_to_channel_bg(int freq)
51 {
52 u8 channel;
53
54 if (freq == 2484)
55 channel = 14;
56 else
57 channel = (freq - 2407) / 5;
58
59 return channel;
60 }
61 static inline
62 u8 bcm43xx_freq_to_channel(struct bcm43xx_wldev *dev,
63 int freq)
64 {
65 if (dev->phy.type == BCM43xx_PHYTYPE_A)
66 return bcm43xx_freq_to_channel_a(freq);
67 return bcm43xx_freq_to_channel_bg(freq);
68 }
69
70 /* Lightweight function to convert a channel number to a frequency (in Mhz). */
71 static inline
72 int bcm43xx_channel_to_freq_a(u8 channel)
73 {
74 return (5000 + (5 * channel));
75 }
76 static inline
77 int bcm43xx_channel_to_freq_bg(u8 channel)
78 {
79 int freq;
80
81 if (channel == 14)
82 freq = 2484;
83 else
84 freq = 2407 + (5 * channel);
85
86 return freq;
87 }
88 static inline
89 int bcm43xx_channel_to_freq(struct bcm43xx_wldev *dev,
90 u8 channel)
91 {
92 if (dev->phy.type == BCM43xx_PHYTYPE_A)
93 return bcm43xx_channel_to_freq_a(channel);
94 return bcm43xx_channel_to_freq_bg(channel);
95 }
96
97 static inline
98 int bcm43xx_is_cck_rate(int rate)
99 {
100 return (rate == BCM43xx_CCK_RATE_1MB ||
101 rate == BCM43xx_CCK_RATE_2MB ||
102 rate == BCM43xx_CCK_RATE_5MB ||
103 rate == BCM43xx_CCK_RATE_11MB);
104 }
105
106 static inline
107 int bcm43xx_is_ofdm_rate(int rate)
108 {
109 return !bcm43xx_is_cck_rate(rate);
110 }
111
112 static inline
113 int bcm43xx_is_hw_radio_enabled(struct bcm43xx_wldev *dev)
114 {
115 /* function to return state of hardware enable of radio
116 * returns 0 if radio disabled, 1 if radio enabled
117 */
118 struct bcm43xx_phy *phy = &dev->phy;
119
120 if (phy->rev >= 3)
121 return ((bcm43xx_read32(dev, BCM43xx_MMIO_RADIO_HWENABLED_HI)
122 & BCM43xx_MMIO_RADIO_HWENABLED_HI_MASK)
123 == 0) ? 1 : 0;
124 else
125 return ((bcm43xx_read16(dev, BCM43xx_MMIO_RADIO_HWENABLED_LO)
126 & BCM43xx_MMIO_RADIO_HWENABLED_LO_MASK)
127 == 0) ? 0 : 1;
128 }
129
130 void bcm43xx_tsf_read(struct bcm43xx_wldev *dev, u64 *tsf);
131 void bcm43xx_tsf_write(struct bcm43xx_wldev *dev, u64 tsf);
132
133 u32 bcm43xx_shm_read32(struct bcm43xx_wldev *dev,
134 u16 routing, u16 offset);
135 u16 bcm43xx_shm_read16(struct bcm43xx_wldev *dev,
136 u16 routing, u16 offset);
137 void bcm43xx_shm_write32(struct bcm43xx_wldev *dev,
138 u16 routing, u16 offset,
139 u32 value);
140 void bcm43xx_shm_write16(struct bcm43xx_wldev *dev,
141 u16 routing, u16 offset,
142 u16 value);
143
144 u32 bcm43xx_hf_read(struct bcm43xx_wldev *dev);
145 void bcm43xx_hf_write(struct bcm43xx_wldev *dev, u32 value);
146
147 void bcm43xx_dummy_transmission(struct bcm43xx_wldev *dev);
148
149 void bcm43xx_wireless_core_reset(struct bcm43xx_wldev *dev, u32 flags);
150
151 void bcm43xx_mac_suspend(struct bcm43xx_wldev *dev);
152 void bcm43xx_mac_enable(struct bcm43xx_wldev *dev);
153
154 void bcm43xx_controller_restart(struct bcm43xx_wldev *dev, const char *reason);
155
156 #endif /* BCM43xx_MAIN_H_ */