blob: 298e24b4ab6475a4371f3178563192fff1792aa6 [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
190u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
191 int freq)
192{
193 u8 channel;
194
195 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) {
196 channel = (freq - 5000) / 5;
197 } else {
198 if (freq == 2484)
199 channel = 14;
200 else
201 channel = (freq - 2407) / 5;
202 }
203
204 return channel;
205}
206
207/* Lightweight function to convert a channel number to a frequency (in Mhz). */
208static inline
209int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
210 u8 channel)
211{
212 int freq;
213
214 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) {
215 freq = 5000 + (5 * channel);
216 } else {
217 if (channel == 14)
218 freq = 2484;
219 else
220 freq = 2407 + (5 * channel);
221 }
222
223 return freq;
224}
225
226/* Lightweight function to check if a channel number is valid.
227 * Note that this does _NOT_ check for geographical restrictions!
228 */
229static inline
230int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
231 u8 channel)
232{
233 if (bcm->current_core->phy->type == BCM43xx_PHYTYPE_A) {
234 if (channel <= 200)
235 return 1;
236 } else {
237 if (channel >= 1 && channel <= 14)
238 return 1;
239 }
240
241 return 0;
242}
243
244void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
245void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
246
Michael Buesch489423c2006-02-13 00:11:07 +0100247int bcm43xx_rx(struct bcm43xx_private *bcm,
248 struct sk_buff *skb,
249 struct bcm43xx_rxhdr *rxhdr);
John W. Linvillef2223132006-01-23 16:59:58 -0500250
251void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
252 int iw_mode);
253
254u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
255 u16 routing, u16 offset);
256u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
257 u16 routing, u16 offset);
258void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
259 u16 routing, u16 offset,
260 u32 value);
261void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
262 u16 routing, u16 offset,
263 u16 value);
264
265void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
266
267int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
268
269void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
270
271int bcm43xx_pci_read_config_16(struct pci_dev *pdev, u16 offset, u16 *val);
272int bcm43xx_pci_read_config_32(struct pci_dev *pdev, u16 offset, u32 *val);
273int bcm43xx_pci_write_config_16(struct pci_dev *pdev, int offset, u16 val);
274int bcm43xx_pci_write_config_32(struct pci_dev *pdev, int offset, u32 val);
275
276void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
277void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
278
279u8 bcm43xx_sprom_crc(const u16 *sprom);
280
281void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
282
283#endif /* BCM43xx_MAIN_H_ */