Pull bugzilla-9429 into release branch
[pv_ops_mirror.git] / drivers / net / wireless / zd1211rw / zd_mac.h
blob1b15bde3ff60a35599a86361778605e926b71963
1 /* zd_mac.h
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.
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.
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
18 #ifndef _ZD_MAC_H
19 #define _ZD_MAC_H
21 #include <linux/wireless.h>
22 #include <linux/kernel.h>
23 #include <linux/workqueue.h>
24 #include <net/ieee80211.h>
25 #include <net/ieee80211softmac.h>
27 #include "zd_chip.h"
28 #include "zd_netdev.h"
30 struct zd_ctrlset {
31 u8 modulation;
32 __le16 tx_length;
33 u8 control;
34 /* stores only the difference to tx_length on ZD1211B */
35 __le16 packet_length;
36 __le16 current_length;
37 u8 service;
38 __le16 next_frame_length;
39 } __attribute__((packed));
41 #define ZD_CS_RESERVED_SIZE 25
43 /* The field modulation of struct zd_ctrlset controls the bit rate, the use
44 * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
45 * 802.11g in OFDM mode.
47 * The term zd-rate is used for the combination of the modulation type flag
48 * and the "pure" rate value.
50 #define ZD_PURE_RATE_MASK 0x0f
51 #define ZD_MODULATION_TYPE_MASK 0x10
52 #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
53 #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
54 #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
55 #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
57 /* The two possible modulation types. Notify that 802.11b doesn't use the CCK
58 * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
59 * consistent with uses the term at other places.
61 #define ZD_CCK 0x00
62 #define ZD_OFDM 0x10
64 /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
65 * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
66 * with the modulation type flag and call the resulting values zd-rates.
68 #define ZD_CCK_RATE_1M (ZD_CCK|0x00)
69 #define ZD_CCK_RATE_2M (ZD_CCK|0x01)
70 #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
71 #define ZD_CCK_RATE_11M (ZD_CCK|0x03)
72 #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
73 #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
74 #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
75 #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
76 #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
77 #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
78 #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
79 #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
81 /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
82 * mode or the 802.11a/802.11g selection in OFDM mode.
84 #define ZD_CCK_PREA_LONG 0x00
85 #define ZD_CCK_PREA_SHORT 0x20
86 #define ZD_OFDM_MODE_11G 0x00
87 #define ZD_OFDM_MODE_11A 0x20
89 /* zd_ctrlset control field */
90 #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
91 #define ZD_CS_MULTICAST 0x02
93 #define ZD_CS_FRAME_TYPE_MASK 0x0c
94 #define ZD_CS_DATA_FRAME 0x00
95 #define ZD_CS_PS_POLL_FRAME 0x04
96 #define ZD_CS_MANAGEMENT_FRAME 0x08
97 #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
99 #define ZD_CS_WAKE_DESTINATION 0x10
100 #define ZD_CS_RTS 0x20
101 #define ZD_CS_ENCRYPT 0x40
102 #define ZD_CS_SELF_CTS 0x80
104 /* Incoming frames are prepended by a PLCP header */
105 #define ZD_PLCP_HEADER_SIZE 5
107 struct rx_length_info {
108 __le16 length[3];
109 __le16 tag;
110 } __attribute__((packed));
112 #define RX_LENGTH_INFO_TAG 0x697e
114 struct rx_status {
115 u8 signal_quality_cck;
116 /* rssi */
117 u8 signal_strength;
118 u8 signal_quality_ofdm;
119 u8 decryption_type;
120 u8 frame_status;
121 } __attribute__((packed));
123 /* rx_status field decryption_type */
124 #define ZD_RX_NO_WEP 0
125 #define ZD_RX_WEP64 1
126 #define ZD_RX_TKIP 2
127 #define ZD_RX_AES 4
128 #define ZD_RX_WEP128 5
129 #define ZD_RX_WEP256 6
131 /* rx_status field frame_status */
132 #define ZD_RX_FRAME_MODULATION_MASK 0x01
133 #define ZD_RX_CCK 0x00
134 #define ZD_RX_OFDM 0x01
136 #define ZD_RX_TIMEOUT_ERROR 0x02
137 #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
138 #define ZD_RX_DECRYPTION_ERROR 0x08
139 #define ZD_RX_CRC32_ERROR 0x10
140 #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
141 #define ZD_RX_CRC16_ERROR 0x40
142 #define ZD_RX_ERROR 0x80
144 struct housekeeping {
145 struct delayed_work link_led_work;
148 #define ZD_MAC_STATS_BUFFER_SIZE 16
150 struct zd_mac {
151 struct zd_chip chip;
152 spinlock_t lock;
153 struct net_device *netdev;
155 /* Unlocked reading possible */
156 struct iw_statistics iw_stats;
158 struct housekeeping housekeeping;
159 struct work_struct set_multicast_hash_work;
160 struct zd_mc_hash multicast_hash;
161 struct delayed_work set_rts_cts_work;
162 struct delayed_work set_basic_rates_work;
164 struct tasklet_struct rx_tasklet;
165 struct sk_buff_head rx_queue;
167 unsigned int stats_count;
168 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
169 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
170 u8 regdomain;
171 u8 default_regdomain;
172 u8 requested_channel;
174 /* A bitpattern of cr_rates */
175 u16 basic_rates;
177 /* A zd_rate */
178 u8 rts_rate;
180 /* Short preamble (used for RTS/CTS) */
181 unsigned int short_preamble:1;
183 /* flags to indicate update in progress */
184 unsigned int updating_rts_rate:1;
185 unsigned int updating_basic_rates:1;
188 static inline struct ieee80211_device *zd_mac_to_ieee80211(struct zd_mac *mac)
190 return zd_netdev_ieee80211(mac->netdev);
193 static inline struct zd_mac *zd_netdev_mac(struct net_device *netdev)
195 return ieee80211softmac_priv(netdev);
198 static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
200 return container_of(chip, struct zd_mac, chip);
203 static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
205 return zd_chip_to_mac(zd_usb_to_chip(usb));
208 #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
210 int zd_mac_init(struct zd_mac *mac,
211 struct net_device *netdev,
212 struct usb_interface *intf);
213 void zd_mac_clear(struct zd_mac *mac);
215 int zd_mac_preinit_hw(struct zd_mac *mac);
216 int zd_mac_init_hw(struct zd_mac *mac);
218 int zd_mac_open(struct net_device *netdev);
219 int zd_mac_stop(struct net_device *netdev);
220 int zd_mac_set_mac_address(struct net_device *dev, void *p);
221 void zd_mac_set_multicast_list(struct net_device *netdev);
223 int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length);
225 int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
226 u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
228 int zd_mac_request_channel(struct zd_mac *mac, u8 channel);
229 u8 zd_mac_get_channel(struct zd_mac *mac);
231 int zd_mac_set_mode(struct zd_mac *mac, u32 mode);
232 int zd_mac_get_mode(struct zd_mac *mac, u32 *mode);
234 int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range);
236 struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev);
238 #ifdef DEBUG
239 void zd_dump_rx_status(const struct rx_status *status);
240 #else
241 #define zd_dump_rx_status(status)
242 #endif /* DEBUG */
244 #endif /* _ZD_MAC_H */