blob: c01eca859f95cd5c554f51bc28b3e7da9bbb45e4 [file] [log] [blame]
Daniel Drake66bb42f2007-11-19 16:20:12 +00001/* ZD1211 USB-WLAN driver for Linux
2 *
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
Daniel Drakee85d0912006-06-02 17:11:32 +01005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _ZD_MAC_H
22#define _ZD_MAC_H
23
Daniel Drakee85d0912006-06-02 17:11:32 +010024#include <linux/kernel.h>
Daniel Drake459c51a2007-11-19 15:00:29 +000025#include <net/mac80211.h>
Daniel Drakee85d0912006-06-02 17:11:32 +010026
27#include "zd_chip.h"
Daniel Drakee85d0912006-06-02 17:11:32 +010028
29struct zd_ctrlset {
30 u8 modulation;
31 __le16 tx_length;
32 u8 control;
33 /* stores only the difference to tx_length on ZD1211B */
34 __le16 packet_length;
35 __le16 current_length;
36 u8 service;
37 __le16 next_frame_length;
Eric Dumazetba2d3582010-06-02 18:10:09 +000038} __packed;
Daniel Drakee85d0912006-06-02 17:11:32 +010039
40#define ZD_CS_RESERVED_SIZE 25
41
Ulrich Kunitz64f222c2007-08-06 01:24:31 +010042/* The field modulation of struct zd_ctrlset controls the bit rate, the use
43 * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
44 * 802.11g in OFDM mode.
45 *
46 * The term zd-rate is used for the combination of the modulation type flag
47 * and the "pure" rate value.
Daniel Drakee85d0912006-06-02 17:11:32 +010048 */
Ulrich Kunitz64f222c2007-08-06 01:24:31 +010049#define ZD_PURE_RATE_MASK 0x0f
50#define ZD_MODULATION_TYPE_MASK 0x10
51#define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
52#define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
53#define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
54#define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
Daniel Drakee85d0912006-06-02 17:11:32 +010055
Ulrich Kunitz64f222c2007-08-06 01:24:31 +010056/* The two possible modulation types. Notify that 802.11b doesn't use the CCK
57 * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
58 * consistent with uses the term at other places.
Daniel Drake459c51a2007-11-19 15:00:29 +000059 */
Ulrich Kunitz64f222c2007-08-06 01:24:31 +010060#define ZD_CCK 0x00
61#define ZD_OFDM 0x10
62
63/* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
64 * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
65 * with the modulation type flag and call the resulting values zd-rates.
66 */
67#define ZD_CCK_RATE_1M (ZD_CCK|0x00)
68#define ZD_CCK_RATE_2M (ZD_CCK|0x01)
69#define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
70#define ZD_CCK_RATE_11M (ZD_CCK|0x03)
71#define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
72#define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
73#define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
74#define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
75#define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
76#define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
77#define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
78#define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
79
80/* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
81 * mode or the 802.11a/802.11g selection in OFDM mode.
82 */
83#define ZD_CCK_PREA_LONG 0x00
84#define ZD_CCK_PREA_SHORT 0x20
85#define ZD_OFDM_MODE_11G 0x00
86#define ZD_OFDM_MODE_11A 0x20
Daniel Drakee85d0912006-06-02 17:11:32 +010087
88/* zd_ctrlset control field */
89#define ZD_CS_NEED_RANDOM_BACKOFF 0x01
Gábor Stefanik13bdcd92009-05-14 17:34:59 +000090#define ZD_CS_NO_ACK 0x02
Daniel Drakee85d0912006-06-02 17:11:32 +010091
92#define ZD_CS_FRAME_TYPE_MASK 0x0c
93#define ZD_CS_DATA_FRAME 0x00
94#define ZD_CS_PS_POLL_FRAME 0x04
95#define ZD_CS_MANAGEMENT_FRAME 0x08
96#define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
97
98#define ZD_CS_WAKE_DESTINATION 0x10
99#define ZD_CS_RTS 0x20
100#define ZD_CS_ENCRYPT 0x40
101#define ZD_CS_SELF_CTS 0x80
102
103/* Incoming frames are prepended by a PLCP header */
104#define ZD_PLCP_HEADER_SIZE 5
105
106struct rx_length_info {
107 __le16 length[3];
108 __le16 tag;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000109} __packed;
Daniel Drakee85d0912006-06-02 17:11:32 +0100110
111#define RX_LENGTH_INFO_TAG 0x697e
112
113struct rx_status {
Ulrich Kunitzdb888ae2006-08-29 23:50:29 +0100114 u8 signal_quality_cck;
Daniel Drakee85d0912006-06-02 17:11:32 +0100115 /* rssi */
116 u8 signal_strength;
Daniel Drakee85d0912006-06-02 17:11:32 +0100117 u8 signal_quality_ofdm;
118 u8 decryption_type;
119 u8 frame_status;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000120} __packed;
Daniel Drakee85d0912006-06-02 17:11:32 +0100121
122/* rx_status field decryption_type */
123#define ZD_RX_NO_WEP 0
124#define ZD_RX_WEP64 1
125#define ZD_RX_TKIP 2
126#define ZD_RX_AES 4
127#define ZD_RX_WEP128 5
128#define ZD_RX_WEP256 6
129
130/* rx_status field frame_status */
131#define ZD_RX_FRAME_MODULATION_MASK 0x01
132#define ZD_RX_CCK 0x00
133#define ZD_RX_OFDM 0x01
134
135#define ZD_RX_TIMEOUT_ERROR 0x02
136#define ZD_RX_FIFO_OVERRUN_ERROR 0x04
137#define ZD_RX_DECRYPTION_ERROR 0x08
138#define ZD_RX_CRC32_ERROR 0x10
139#define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
140#define ZD_RX_CRC16_ERROR 0x40
141#define ZD_RX_ERROR 0x80
142
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200143struct tx_retry_rate {
144 int count; /* number of valid element in rate[] array */
145 int rate[10]; /* retry rates, described by an index in zd_rates[] */
146};
147
148struct tx_status {
149 u8 type; /* must always be 0x01 : USB_INT_TYPE */
150 u8 id; /* must always be 0xa0 : USB_INT_ID_RETRY_FAILED */
151 u8 rate;
152 u8 pad;
153 u8 mac[ETH_ALEN];
154 u8 retry;
155 u8 failure;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000156} __packed;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200157
Daniel Drake459c51a2007-11-19 15:00:29 +0000158enum mac_flags {
159 MAC_FIXED_CHANNEL = 0x01,
160};
161
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100162struct housekeeping {
David Howellsc4028952006-11-22 14:57:56 +0000163 struct delayed_work link_led_work;
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100164};
165
Jussi Kivilinna9be23252011-01-31 20:48:55 +0200166struct beacon {
167 struct delayed_work watchdog_work;
Jussi Kivilinnaf762d8c2011-06-20 14:42:39 +0300168 struct sk_buff *cur_beacon;
Jussi Kivilinna9be23252011-01-31 20:48:55 +0200169 unsigned long last_update;
170 u16 interval;
171 u8 period;
172};
173
174enum zd_device_flags {
175 ZD_DEVICE_RUNNING,
176};
177
Ulrich Kunitzdb888ae2006-08-29 23:50:29 +0100178#define ZD_MAC_STATS_BUFFER_SIZE 16
179
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200180#define ZD_MAC_MAX_ACK_WAITERS 50
Daniel Drake459c51a2007-11-19 15:00:29 +0000181
Daniel Drakee85d0912006-06-02 17:11:32 +0100182struct zd_mac {
Daniel Drakee85d0912006-06-02 17:11:32 +0100183 struct zd_chip chip;
184 spinlock_t lock;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800185 spinlock_t intr_lock;
Daniel Drake459c51a2007-11-19 15:00:29 +0000186 struct ieee80211_hw *hw;
Jussi Kivilinnac2fadcb2011-01-31 20:48:06 +0200187 struct ieee80211_vif *vif;
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100188 struct housekeeping housekeeping;
Jussi Kivilinna9be23252011-01-31 20:48:55 +0200189 struct beacon beacon;
Daniel Drake459c51a2007-11-19 15:00:29 +0000190 struct work_struct set_rts_cts_work;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800191 struct work_struct process_intr;
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000192 struct zd_mc_hash multicast_hash;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800193 u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
Daniel Drakee85d0912006-06-02 17:11:32 +0100194 u8 regdomain;
195 u8 default_regdomain;
Jussi Kivilinna212e1a52011-01-31 20:49:43 +0200196 u8 channel;
Daniel Drake459c51a2007-11-19 15:00:29 +0000197 int type;
198 int associated;
Jussi Kivilinna9be23252011-01-31 20:48:55 +0200199 unsigned long flags;
Daniel Drake459c51a2007-11-19 15:00:29 +0000200 struct sk_buff_head ack_wait_queue;
201 struct ieee80211_channel channels[14];
202 struct ieee80211_rate rates[12];
Johannes Berg8318d782008-01-24 19:38:38 +0100203 struct ieee80211_supported_band band;
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000204
205 /* Short preamble (used for RTS/CTS) */
206 unsigned int short_preamble:1;
207
Daniel Drake459c51a2007-11-19 15:00:29 +0000208 /* whether to pass frames with CRC errors to stack */
209 unsigned int pass_failed_fcs:1;
210
211 /* whether to pass control frames to stack */
212 unsigned int pass_ctrl:1;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200213
214 /* whether we have received a 802.11 ACK that is pending */
215 unsigned int ack_pending:1;
216
217 /* signal strength of the last 802.11 ACK received */
218 int ack_signal;
Daniel Drakee85d0912006-06-02 17:11:32 +0100219};
220
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700221#define ZD_REGDOMAIN_FCC 0x10
222#define ZD_REGDOMAIN_IC 0x20
223#define ZD_REGDOMAIN_ETSI 0x30
224#define ZD_REGDOMAIN_SPAIN 0x31
225#define ZD_REGDOMAIN_FRANCE 0x32
John W. Linville3d3b33b2010-06-16 14:41:36 -0400226#define ZD_REGDOMAIN_JAPAN_2 0x40
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700227#define ZD_REGDOMAIN_JAPAN 0x41
John W. Linville3d3b33b2010-06-16 14:41:36 -0400228#define ZD_REGDOMAIN_JAPAN_3 0x49
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700229
230enum {
231 MIN_CHANNEL24 = 1,
232 MAX_CHANNEL24 = 14,
233};
234
235#define ZD_PLCP_SERVICE_LENGTH_EXTENSION 0x80
236
237struct ofdm_plcp_header {
238 u8 prefix[3];
239 __le16 service;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000240} __packed;
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700241
242static inline u8 zd_ofdm_plcp_header_rate(const struct ofdm_plcp_header *header)
243{
244 return header->prefix[0] & 0xf;
245}
246
247/* The following defines give the encoding of the 4-bit rate field in the
248 * OFDM (802.11a/802.11g) PLCP header. Notify that these values are used to
249 * define the zd-rate values for OFDM.
250 *
251 * See the struct zd_ctrlset definition in zd_mac.h.
252 */
253#define ZD_OFDM_PLCP_RATE_6M 0xb
254#define ZD_OFDM_PLCP_RATE_9M 0xf
255#define ZD_OFDM_PLCP_RATE_12M 0xa
256#define ZD_OFDM_PLCP_RATE_18M 0xe
257#define ZD_OFDM_PLCP_RATE_24M 0x9
258#define ZD_OFDM_PLCP_RATE_36M 0xd
259#define ZD_OFDM_PLCP_RATE_48M 0x8
260#define ZD_OFDM_PLCP_RATE_54M 0xc
261
262struct cck_plcp_header {
263 u8 signal;
264 u8 service;
265 __le16 length;
266 __le16 crc16;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000267} __packed;
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700268
269static inline u8 zd_cck_plcp_header_signal(const struct cck_plcp_header *header)
270{
271 return header->signal;
272}
273
274/* These defines give the encodings of the signal field in the 802.11b PLCP
275 * header. The signal field gives the bit rate of the following packet. Even
276 * if technically wrong we use CCK here also for the 1 MBit/s and 2 MBit/s
277 * rate to stay consistent with Zydas and our use of the term.
278 *
279 * Notify that these values are *not* used in the zd-rates.
280 */
281#define ZD_CCK_PLCP_SIGNAL_1M 0x0a
282#define ZD_CCK_PLCP_SIGNAL_2M 0x14
283#define ZD_CCK_PLCP_SIGNAL_5M5 0x37
284#define ZD_CCK_PLCP_SIGNAL_11M 0x6e
285
Daniel Drake459c51a2007-11-19 15:00:29 +0000286static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw)
Daniel Drakee85d0912006-06-02 17:11:32 +0100287{
Daniel Drake459c51a2007-11-19 15:00:29 +0000288 return hw->priv;
Daniel Drakee85d0912006-06-02 17:11:32 +0100289}
290
291static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
292{
293 return container_of(chip, struct zd_mac, chip);
294}
295
296static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
297{
298 return zd_chip_to_mac(zd_usb_to_chip(usb));
299}
300
Daniel Drake459c51a2007-11-19 15:00:29 +0000301static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac)
302{
303 return mac->hw->wiphy->perm_addr;
304}
305
Daniel Drakee85d0912006-06-02 17:11:32 +0100306#define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
307
Daniel Drake459c51a2007-11-19 15:00:29 +0000308struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf);
Daniel Drakee85d0912006-06-02 17:11:32 +0100309void zd_mac_clear(struct zd_mac *mac);
310
Daniel Drake459c51a2007-11-19 15:00:29 +0000311int zd_mac_preinit_hw(struct ieee80211_hw *hw);
312int zd_mac_init_hw(struct ieee80211_hw *hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100313
Daniel Drake459c51a2007-11-19 15:00:29 +0000314int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200315void zd_mac_tx_failed(struct urb *urb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000316void zd_mac_tx_to_dev(struct sk_buff *skb, int error);
Daniel Drakee85d0912006-06-02 17:11:32 +0100317
Jussi Kivilinnaa0fd7512011-01-31 20:49:52 +0200318int zd_op_start(struct ieee80211_hw *hw);
319void zd_op_stop(struct ieee80211_hw *hw);
Jussi Kivilinna212e1a52011-01-31 20:49:43 +0200320int zd_restore_settings(struct zd_mac *mac);
321
Daniel Drakee85d0912006-06-02 17:11:32 +0100322#ifdef DEBUG
323void zd_dump_rx_status(const struct rx_status *status);
324#else
325#define zd_dump_rx_status(status)
326#endif /* DEBUG */
327
328#endif /* _ZD_MAC_H */