zd1211rw: port to mac80211
[deliverable/linux.git] / drivers / net / wireless / zd1211rw / zd_mac.h
1 /* zd_mac.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #ifndef _ZD_MAC_H
19 #define _ZD_MAC_H
20
21 #include <linux/kernel.h>
22 #include <net/mac80211.h>
23
24 #include "zd_chip.h"
25 #include "zd_ieee80211.h"
26
27 struct zd_ctrlset {
28 u8 modulation;
29 __le16 tx_length;
30 u8 control;
31 /* stores only the difference to tx_length on ZD1211B */
32 __le16 packet_length;
33 __le16 current_length;
34 u8 service;
35 __le16 next_frame_length;
36 } __attribute__((packed));
37
38 #define ZD_CS_RESERVED_SIZE 25
39
40 /* The field modulation of struct zd_ctrlset controls the bit rate, the use
41 * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
42 * 802.11g in OFDM mode.
43 *
44 * The term zd-rate is used for the combination of the modulation type flag
45 * and the "pure" rate value.
46 */
47 #define ZD_PURE_RATE_MASK 0x0f
48 #define ZD_MODULATION_TYPE_MASK 0x10
49 #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
50 #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
51 #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
52 #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
53
54 /* The two possible modulation types. Notify that 802.11b doesn't use the CCK
55 * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
56 * consistent with uses the term at other places.
57 */
58 #define ZD_CCK 0x00
59 #define ZD_OFDM 0x10
60
61 /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
62 * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
63 * with the modulation type flag and call the resulting values zd-rates.
64 */
65 #define ZD_CCK_RATE_1M (ZD_CCK|0x00)
66 #define ZD_CCK_RATE_2M (ZD_CCK|0x01)
67 #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
68 #define ZD_CCK_RATE_11M (ZD_CCK|0x03)
69 #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
70 #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
71 #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
72 #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
73 #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
74 #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
75 #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
76 #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
77
78 /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
79 * mode or the 802.11a/802.11g selection in OFDM mode.
80 */
81 #define ZD_CCK_PREA_LONG 0x00
82 #define ZD_CCK_PREA_SHORT 0x20
83 #define ZD_OFDM_MODE_11G 0x00
84 #define ZD_OFDM_MODE_11A 0x20
85
86 /* zd_ctrlset control field */
87 #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
88 #define ZD_CS_MULTICAST 0x02
89
90 #define ZD_CS_FRAME_TYPE_MASK 0x0c
91 #define ZD_CS_DATA_FRAME 0x00
92 #define ZD_CS_PS_POLL_FRAME 0x04
93 #define ZD_CS_MANAGEMENT_FRAME 0x08
94 #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
95
96 #define ZD_CS_WAKE_DESTINATION 0x10
97 #define ZD_CS_RTS 0x20
98 #define ZD_CS_ENCRYPT 0x40
99 #define ZD_CS_SELF_CTS 0x80
100
101 /* Incoming frames are prepended by a PLCP header */
102 #define ZD_PLCP_HEADER_SIZE 5
103
104 struct rx_length_info {
105 __le16 length[3];
106 __le16 tag;
107 } __attribute__((packed));
108
109 #define RX_LENGTH_INFO_TAG 0x697e
110
111 struct rx_status {
112 u8 signal_quality_cck;
113 /* rssi */
114 u8 signal_strength;
115 u8 signal_quality_ofdm;
116 u8 decryption_type;
117 u8 frame_status;
118 } __attribute__((packed));
119
120 /* rx_status field decryption_type */
121 #define ZD_RX_NO_WEP 0
122 #define ZD_RX_WEP64 1
123 #define ZD_RX_TKIP 2
124 #define ZD_RX_AES 4
125 #define ZD_RX_WEP128 5
126 #define ZD_RX_WEP256 6
127
128 /* rx_status field frame_status */
129 #define ZD_RX_FRAME_MODULATION_MASK 0x01
130 #define ZD_RX_CCK 0x00
131 #define ZD_RX_OFDM 0x01
132
133 #define ZD_RX_TIMEOUT_ERROR 0x02
134 #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
135 #define ZD_RX_DECRYPTION_ERROR 0x08
136 #define ZD_RX_CRC32_ERROR 0x10
137 #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
138 #define ZD_RX_CRC16_ERROR 0x40
139 #define ZD_RX_ERROR 0x80
140
141 enum mac_flags {
142 MAC_FIXED_CHANNEL = 0x01,
143 };
144
145 struct housekeeping {
146 struct delayed_work link_led_work;
147 };
148
149 /**
150 * struct zd_tx_skb_control_block - control block for tx skbuffs
151 * @control: &struct ieee80211_tx_control pointer
152 * @context: context pointer
153 *
154 * This structure is used to fill the cb field in an &sk_buff to transmit.
155 * The control field is NULL, if there is no requirement from the mac80211
156 * stack to report about the packet ACK. This is the case if the flag
157 * IEEE80211_TXCTL_NO_ACK is not set in &struct ieee80211_tx_control.
158 */
159 struct zd_tx_skb_control_block {
160 struct ieee80211_tx_control *control;
161 struct ieee80211_hw *hw;
162 void *context;
163 };
164
165 #define ZD_MAC_STATS_BUFFER_SIZE 16
166
167 #define ZD_MAC_MAX_ACK_WAITERS 10
168
169 struct zd_mac {
170 struct zd_chip chip;
171 spinlock_t lock;
172 struct ieee80211_hw *hw;
173 struct housekeeping housekeeping;
174 struct work_struct set_multicast_hash_work;
175 struct work_struct set_rts_cts_work;
176 struct work_struct set_rx_filter_work;
177 struct zd_mc_hash multicast_hash;
178 u8 regdomain;
179 u8 default_regdomain;
180 int type;
181 int associated;
182 struct sk_buff_head ack_wait_queue;
183 struct ieee80211_channel channels[14];
184 struct ieee80211_rate rates[12];
185 struct ieee80211_hw_mode modes[2];
186
187 /* Short preamble (used for RTS/CTS) */
188 unsigned int short_preamble:1;
189
190 /* flags to indicate update in progress */
191 unsigned int updating_rts_rate:1;
192
193 /* whether to pass frames with CRC errors to stack */
194 unsigned int pass_failed_fcs:1;
195
196 /* whether to pass control frames to stack */
197 unsigned int pass_ctrl:1;
198 };
199
200 static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw)
201 {
202 return hw->priv;
203 }
204
205 static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
206 {
207 return container_of(chip, struct zd_mac, chip);
208 }
209
210 static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
211 {
212 return zd_chip_to_mac(zd_usb_to_chip(usb));
213 }
214
215 static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac)
216 {
217 return mac->hw->wiphy->perm_addr;
218 }
219
220 #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
221
222 struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf);
223 void zd_mac_clear(struct zd_mac *mac);
224
225 int zd_mac_preinit_hw(struct ieee80211_hw *hw);
226 int zd_mac_init_hw(struct ieee80211_hw *hw);
227
228 int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length);
229 void zd_mac_tx_failed(struct ieee80211_hw *hw);
230 void zd_mac_tx_to_dev(struct sk_buff *skb, int error);
231
232 #ifdef DEBUG
233 void zd_dump_rx_status(const struct rx_status *status);
234 #else
235 #define zd_dump_rx_status(status)
236 #endif /* DEBUG */
237
238 #endif /* _ZD_MAC_H */
This page took 0.0455 seconds and 5 git commands to generate.