blob: 7d696d257f7aa162926c7bd8f6db278dd22ffb13 [file] [log] [blame]
John W. Linvillef2223132006-01-23 16:59:58 -05001/*
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 <mbuesch@freenet.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#ifdef CONFIG_BCM947XX
37#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
38
39static inline void e_aton(char *str, char *dest)
40{
41 int i = 0;
42 u16 *d = (u16 *) dest;
43
44 for (;;) {
45 dest[i++] = (char) simple_strtoul(str, NULL, 16);
46 str += 2;
47 if (!*str++ || i == 6)
48 break;
49 }
50 for (i = 0; i < 3; i++)
51 d[i] = cpu_to_be16(d[i]);
52}
53#endif
54
55
56#define _bcm43xx_declare_plcp_hdr(size) \
57 struct bcm43xx_plcp_hdr##size { \
58 union { \
59 __le32 data; \
60 __u8 raw[size]; \
61 } __attribute__((__packed__)); \
62 } __attribute__((__packed__))
63
64/* struct bcm43xx_plcp_hdr4 */
65_bcm43xx_declare_plcp_hdr(4);
66/* struct bcm430c_plcp_hdr6 */
67_bcm43xx_declare_plcp_hdr(6);
68
69#undef _bcm43xx_declare_plcp_hdr
70
71
72#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
73#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
74/* Magic helper macro to pad structures. Ignore those above. It's magic. */
75#define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
76
77
78/* Device specific TX header. To be prepended to TX frames. */
79struct bcm43xx_txhdr {
80 union {
81 struct {
82 u16 flags;
83 u16 wsec_rate;
84 u16 frame_control;
85 u16 unknown_zeroed_0;
86 u16 control;
87 unsigned char wep_iv[10];
88 unsigned char unknown_wsec_tkip_data[3]; //FIXME
89 PAD_BYTES(3);
90 unsigned char mac1[6];
91 u16 unknown_zeroed_1;
92 struct bcm43xx_plcp_hdr4 rts_cts_fallback_plcp;
93 u16 rts_cts_dur_fallback;
94 struct bcm43xx_plcp_hdr4 fallback_plcp;
95 u16 fallback_dur_id;
96 PAD_BYTES(2);
97 u16 cookie;
98 u16 unknown_scb_stuff; //FIXME
99 struct bcm43xx_plcp_hdr6 rts_cts_plcp;
100 u16 rts_cts_frame_type;
101 u16 rts_cts_dur;
102 unsigned char rts_cts_mac1[6];
103 unsigned char rts_cts_mac2[6];
104 PAD_BYTES(2);
105 struct bcm43xx_plcp_hdr6 plcp;
106 } __attribute__((__packed__));
107
108 unsigned char raw[82];
109 } __attribute__((__packed__));
110} __attribute__((__packed__));
111
112struct sk_buff;
113
Michael Buesch489423c2006-02-13 00:11:07 +0100114void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
115 struct bcm43xx_txhdr *txhdr,
116 const unsigned char *fragment_data,
117 const unsigned int fragment_len,
118 const int is_first_fragment,
119 const u16 cookie);
John W. Linvillef2223132006-01-23 16:59:58 -0500120
121/* RX header as received from the hardware. */
122struct bcm43xx_rxhdr {
123 /* Frame Length. Must be generated explicitely in PIO mode. */
124 __le16 frame_length;
125 PAD_BYTES(2);
126 /* Flags field 1 */
127 __le16 flags1;
128 u8 rssi;
129 u8 signal_quality;
130 PAD_BYTES(2);
131 /* Flags field 3 */
132 __le16 flags3;
133 /* Flags field 2 */
134 __le16 flags2;
135 /* Lower 16bits of the TSF at the time the frame started. */
136 __le16 mactime;
137 PAD_BYTES(14);
138} __attribute__((__packed__));
139
140#define BCM43xx_RXHDR_FLAGS1_OFDM (1 << 0)
141/*#define BCM43xx_RXHDR_FLAGS1_SIGNAL??? (1 << 3) FIXME */
142#define BCM43xx_RXHDR_FLAGS1_SHORTPREAMBLE (1 << 7)
143#define BCM43xx_RXHDR_FLAGS1_2053RSSIADJ (1 << 14)
144
145#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
146#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
147/*FIXME: WEP related flags */
148
149#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
150
151/* Transmit Status as received from the hardware. */
152struct bcm43xx_hwxmitstatus {
153 PAD_BYTES(4);
154 __le16 cookie;
155 u8 flags;
156 u8 cnt1:4,
157 cnt2:4;
158 PAD_BYTES(2);
159 __le16 seq;
160 __le16 unknown; //FIXME
161} __attribute__((__packed__));
162
163/* Transmit Status in CPU byteorder. */
164struct bcm43xx_xmitstatus {
165 u16 cookie;
166 u8 flags;
167 u8 cnt1:4,
168 cnt2:4;
169 u16 seq;
170 u16 unknown; //FIXME
171};
172
173#define BCM43xx_TXSTAT_FLAG_ACK 0x01
174//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x02
175//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x04
176//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x08
177//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x10
178#define BCM43xx_TXSTAT_FLAG_IGNORE 0x20
179//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x40
180//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x80
181
182struct bcm43xx_xmitstatus_queue {
183 struct list_head list;
184 struct bcm43xx_hwxmitstatus status;
185};
186
187
188/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
189static inline
Michael Buesch10d8dd82006-02-19 22:08:48 +0100190u8 bcm43xx_freq_to_channel_a(int freq)
191{
192 return ((freq - 5000) / 5);
193}
194static inline
195u8 bcm43xx_freq_to_channel_bg(int freq)
John W. Linvillef2223132006-01-23 16:59:58 -0500196{
197 u8 channel;
198
Michael Buesch10d8dd82006-02-19 22:08:48 +0100199 if (freq == 2484)
200 channel = 14;
201 else
202 channel = (freq - 2407) / 5;
John W. Linvillef2223132006-01-23 16:59:58 -0500203
204 return channel;
205}
Michael Buesch10d8dd82006-02-19 22:08:48 +0100206static inline
207u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
208 int freq)
209{
210 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
211 return bcm43xx_freq_to_channel_a(freq);
212 return bcm43xx_freq_to_channel_bg(freq);
213}
John W. Linvillef2223132006-01-23 16:59:58 -0500214
215/* Lightweight function to convert a channel number to a frequency (in Mhz). */
216static inline
Michael Buesch10d8dd82006-02-19 22:08:48 +0100217int bcm43xx_channel_to_freq_a(u8 channel)
218{
219 return (5000 + (5 * channel));
220}
221static inline
222int bcm43xx_channel_to_freq_bg(u8 channel)
John W. Linvillef2223132006-01-23 16:59:58 -0500223{
224 int freq;
225
Michael Buesch10d8dd82006-02-19 22:08:48 +0100226 if (channel == 14)
227 freq = 2484;
228 else
229 freq = 2407 + (5 * channel);
John W. Linvillef2223132006-01-23 16:59:58 -0500230
231 return freq;
232}
Michael Buesch10d8dd82006-02-19 22:08:48 +0100233static inline
234int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
235 u8 channel)
236{
237 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
238 return bcm43xx_channel_to_freq_a(channel);
239 return bcm43xx_channel_to_freq_bg(channel);
240}
John W. Linvillef2223132006-01-23 16:59:58 -0500241
242/* Lightweight function to check if a channel number is valid.
243 * Note that this does _NOT_ check for geographical restrictions!
244 */
245static inline
Michael Buesch10d8dd82006-02-19 22:08:48 +0100246int bcm43xx_is_valid_channel_a(u8 channel)
John W. Linvillef2223132006-01-23 16:59:58 -0500247{
Michael Buesch10d8dd82006-02-19 22:08:48 +0100248 return (channel <= 200);
249}
250static inline
251int bcm43xx_is_valid_channel_bg(u8 channel)
252{
253 return (channel >= 1 && channel <= 14);
254}
255static inline
256int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
257 u8 channel)
258{
259 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A)
260 return bcm43xx_is_valid_channel_a(channel);
261 return bcm43xx_is_valid_channel_bg(channel);
John W. Linvillef2223132006-01-23 16:59:58 -0500262}
263
264void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
265void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
266
Michael Buesch489423c2006-02-13 00:11:07 +0100267int bcm43xx_rx(struct bcm43xx_private *bcm,
268 struct sk_buff *skb,
269 struct bcm43xx_rxhdr *rxhdr);
John W. Linvillef2223132006-01-23 16:59:58 -0500270
271void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
272 int iw_mode);
273
274u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
275 u16 routing, u16 offset);
276u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
277 u16 routing, u16 offset);
278void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
279 u16 routing, u16 offset,
280 u32 value);
281void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
282 u16 routing, u16 offset,
283 u16 value);
284
285void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
286
287int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
288
289void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
290
291int bcm43xx_pci_read_config_16(struct pci_dev *pdev, u16 offset, u16 *val);
292int bcm43xx_pci_read_config_32(struct pci_dev *pdev, u16 offset, u32 *val);
293int bcm43xx_pci_write_config_16(struct pci_dev *pdev, int offset, u16 val);
294int bcm43xx_pci_write_config_32(struct pci_dev *pdev, int offset, u32 val);
295
296void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
297void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
298
John W. Linvillef2223132006-01-23 16:59:58 -0500299void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
300
Michael Bueschea0922b2006-02-19 14:09:20 +0100301int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
302int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
303
John W. Linvillef2223132006-01-23 16:59:58 -0500304#endif /* BCM43xx_MAIN_H_ */