aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/zd1211rw/zd_mac.c
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2007-11-19 10:00:29 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:04:47 -0500
commit459c51ad6e1fc19e91a53798358433d3c08cd09d (patch)
treefb86feacf1b229cb4ab6b36b4d1deaf4983b1e45 /drivers/net/wireless/zd1211rw/zd_mac.c
parent0765af4493193149505f118d04d9300f0a15c8f5 (diff)
zd1211rw: port to mac80211
This seems to be working smoothly now. Let's not hold back the mac80211 transition any further. This patch ports the existing driver from softmac to mac80211. Many thanks to everyone who helped out with the porting efforts. Signed-off-by: Daniel Drake <dsd@gentoo.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_mac.c')
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c1536
1 files changed, 579 insertions, 957 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 5298a8bf1129..aaffd081b1bf 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -1,5 +1,7 @@
1/* zd_mac.c 1/* zd_mac.c
2 * 2 *
3 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
4 *
3 * This program is free software; you can redistribute it and/or modify 5 * 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 6 * 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 7 * the Free Software Foundation; either version 2 of the License, or
@@ -17,7 +19,6 @@
17 19
18#include <linux/netdevice.h> 20#include <linux/netdevice.h>
19#include <linux/etherdevice.h> 21#include <linux/etherdevice.h>
20#include <linux/wireless.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22#include <linux/jiffies.h> 23#include <linux/jiffies.h>
23#include <net/ieee80211_radiotap.h> 24#include <net/ieee80211_radiotap.h>
@@ -26,81 +27,105 @@
26#include "zd_chip.h" 27#include "zd_chip.h"
27#include "zd_mac.h" 28#include "zd_mac.h"
28#include "zd_ieee80211.h" 29#include "zd_ieee80211.h"
29#include "zd_netdev.h"
30#include "zd_rf.h" 30#include "zd_rf.h"
31 31
32static void ieee_init(struct ieee80211_device *ieee); 32/* This table contains the hardware specific values for the modulation rates. */
33static void softmac_init(struct ieee80211softmac_device *sm); 33static const struct ieee80211_rate zd_rates[] = {
34static void set_rts_cts_work(struct work_struct *work); 34 { .rate = 10,
35static void set_basic_rates_work(struct work_struct *work); 35 .val = ZD_CCK_RATE_1M,
36 .flags = IEEE80211_RATE_CCK },
37 { .rate = 20,
38 .val = ZD_CCK_RATE_2M,
39 .val2 = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT,
40 .flags = IEEE80211_RATE_CCK_2 },
41 { .rate = 55,
42 .val = ZD_CCK_RATE_5_5M,
43 .val2 = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT,
44 .flags = IEEE80211_RATE_CCK_2 },
45 { .rate = 110,
46 .val = ZD_CCK_RATE_11M,
47 .val2 = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT,
48 .flags = IEEE80211_RATE_CCK_2 },
49 { .rate = 60,
50 .val = ZD_OFDM_RATE_6M,
51 .flags = IEEE80211_RATE_OFDM },
52 { .rate = 90,
53 .val = ZD_OFDM_RATE_9M,
54 .flags = IEEE80211_RATE_OFDM },
55 { .rate = 120,
56 .val = ZD_OFDM_RATE_12M,
57 .flags = IEEE80211_RATE_OFDM },
58 { .rate = 180,
59 .val = ZD_OFDM_RATE_18M,
60 .flags = IEEE80211_RATE_OFDM },
61 { .rate = 240,
62 .val = ZD_OFDM_RATE_24M,
63 .flags = IEEE80211_RATE_OFDM },
64 { .rate = 360,
65 .val = ZD_OFDM_RATE_36M,
66 .flags = IEEE80211_RATE_OFDM },
67 { .rate = 480,
68 .val = ZD_OFDM_RATE_48M,
69 .flags = IEEE80211_RATE_OFDM },
70 { .rate = 540,
71 .val = ZD_OFDM_RATE_54M,
72 .flags = IEEE80211_RATE_OFDM },
73};
74
75static const struct ieee80211_channel zd_channels[] = {
76 { .chan = 1,
77 .freq = 2412},
78 { .chan = 2,
79 .freq = 2417},
80 { .chan = 3,
81 .freq = 2422},
82 { .chan = 4,
83 .freq = 2427},
84 { .chan = 5,
85 .freq = 2432},
86 { .chan = 6,
87 .freq = 2437},
88 { .chan = 7,
89 .freq = 2442},
90 { .chan = 8,
91 .freq = 2447},
92 { .chan = 9,
93 .freq = 2452},
94 { .chan = 10,
95 .freq = 2457},
96 { .chan = 11,
97 .freq = 2462},
98 { .chan = 12,
99 .freq = 2467},
100 { .chan = 13,
101 .freq = 2472},
102 { .chan = 14,
103 .freq = 2484}
104};
36 105
37static void housekeeping_init(struct zd_mac *mac); 106static void housekeeping_init(struct zd_mac *mac);
38static void housekeeping_enable(struct zd_mac *mac); 107static void housekeeping_enable(struct zd_mac *mac);
39static void housekeeping_disable(struct zd_mac *mac); 108static void housekeeping_disable(struct zd_mac *mac);
40 109
41static void set_multicast_hash_handler(struct work_struct *work); 110int zd_mac_preinit_hw(struct ieee80211_hw *hw)
42
43static void do_rx(unsigned long mac_ptr);
44
45int zd_mac_init(struct zd_mac *mac,
46 struct net_device *netdev,
47 struct usb_interface *intf)
48{
49 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
50
51 memset(mac, 0, sizeof(*mac));
52 spin_lock_init(&mac->lock);
53 mac->netdev = netdev;
54 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
55 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work);
56
57 skb_queue_head_init(&mac->rx_queue);
58 tasklet_init(&mac->rx_tasklet, do_rx, (unsigned long)mac);
59 tasklet_disable(&mac->rx_tasklet);
60
61 ieee_init(ieee);
62 softmac_init(ieee80211_priv(netdev));
63 zd_chip_init(&mac->chip, netdev, intf);
64 housekeeping_init(mac);
65 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
66 return 0;
67}
68
69static int reset_channel(struct zd_mac *mac)
70{
71 int r;
72 unsigned long flags;
73 const struct channel_range *range;
74
75 spin_lock_irqsave(&mac->lock, flags);
76 range = zd_channel_range(mac->regdomain);
77 if (!range->start) {
78 r = -EINVAL;
79 goto out;
80 }
81 mac->requested_channel = range->start;
82 r = 0;
83out:
84 spin_unlock_irqrestore(&mac->lock, flags);
85 return r;
86}
87
88int zd_mac_preinit_hw(struct zd_mac *mac)
89{ 111{
90 int r; 112 int r;
91 u8 addr[ETH_ALEN]; 113 u8 addr[ETH_ALEN];
114 struct zd_mac *mac = zd_hw_mac(hw);
92 115
93 r = zd_chip_read_mac_addr_fw(&mac->chip, addr); 116 r = zd_chip_read_mac_addr_fw(&mac->chip, addr);
94 if (r) 117 if (r)
95 return r; 118 return r;
96 119
97 memcpy(mac->netdev->dev_addr, addr, ETH_ALEN); 120 SET_IEEE80211_PERM_ADDR(hw, addr);
121
98 return 0; 122 return 0;
99} 123}
100 124
101int zd_mac_init_hw(struct zd_mac *mac) 125int zd_mac_init_hw(struct ieee80211_hw *hw)
102{ 126{
103 int r; 127 int r;
128 struct zd_mac *mac = zd_hw_mac(hw);
104 struct zd_chip *chip = &mac->chip; 129 struct zd_chip *chip = &mac->chip;
105 u8 default_regdomain; 130 u8 default_regdomain;
106 131
@@ -116,22 +141,9 @@ int zd_mac_init_hw(struct zd_mac *mac)
116 r = zd_read_regdomain(chip, &default_regdomain); 141 r = zd_read_regdomain(chip, &default_regdomain);
117 if (r) 142 if (r)
118 goto disable_int; 143 goto disable_int;
119 if (!zd_regdomain_supported(default_regdomain)) {
120 /* The vendor driver overrides the regulatory domain and
121 * allowed channel registers and unconditionally restricts
122 * available channels to 1-11 everywhere. Match their
123 * questionable behaviour only for regdomains which we don't
124 * recognise. */
125 dev_warn(zd_mac_dev(mac), "Unrecognised regulatory domain: "
126 "%#04x. Defaulting to FCC.\n", default_regdomain);
127 default_regdomain = ZD_REGDOMAIN_FCC;
128 }
129 spin_lock_irq(&mac->lock); 144 spin_lock_irq(&mac->lock);
130 mac->regdomain = mac->default_regdomain = default_regdomain; 145 mac->regdomain = mac->default_regdomain = default_regdomain;
131 spin_unlock_irq(&mac->lock); 146 spin_unlock_irq(&mac->lock);
132 r = reset_channel(mac);
133 if (r)
134 goto disable_int;
135 147
136 /* We must inform the device that we are doing encryption/decryption in 148 /* We must inform the device that we are doing encryption/decryption in
137 * software at the moment. */ 149 * software at the moment. */
@@ -139,9 +151,7 @@ int zd_mac_init_hw(struct zd_mac *mac)
139 if (r) 151 if (r)
140 goto disable_int; 152 goto disable_int;
141 153
142 r = zd_geo_init(zd_mac_to_ieee80211(mac), mac->regdomain); 154 zd_geo_init(hw, mac->regdomain);
143 if (r)
144 goto disable_int;
145 155
146 r = 0; 156 r = 0;
147disable_int: 157disable_int:
@@ -153,8 +163,6 @@ out:
153void zd_mac_clear(struct zd_mac *mac) 163void zd_mac_clear(struct zd_mac *mac)
154{ 164{
155 flush_workqueue(zd_workqueue); 165 flush_workqueue(zd_workqueue);
156 skb_queue_purge(&mac->rx_queue);
157 tasklet_kill(&mac->rx_tasklet);
158 zd_chip_clear(&mac->chip); 166 zd_chip_clear(&mac->chip);
159 ZD_ASSERT(!spin_is_locked(&mac->lock)); 167 ZD_ASSERT(!spin_is_locked(&mac->lock));
160 ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); 168 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
@@ -162,34 +170,27 @@ void zd_mac_clear(struct zd_mac *mac)
162 170
163static int set_rx_filter(struct zd_mac *mac) 171static int set_rx_filter(struct zd_mac *mac)
164{ 172{
165 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 173 unsigned long flags;
166 u32 filter = (ieee->iw_mode == IW_MODE_MONITOR) ? ~0 : STA_RX_FILTER; 174 u32 filter = STA_RX_FILTER;
167 return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
168}
169 175
170static int set_sniffer(struct zd_mac *mac) 176 spin_lock_irqsave(&mac->lock, flags);
171{ 177 if (mac->pass_ctrl)
172 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 178 filter |= RX_FILTER_CTRL;
173 return zd_iowrite32(&mac->chip, CR_SNIFFER_ON, 179 spin_unlock_irqrestore(&mac->lock, flags);
174 ieee->iw_mode == IW_MODE_MONITOR ? 1 : 0); 180
175 return 0; 181 return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
176} 182}
177 183
178static int set_mc_hash(struct zd_mac *mac) 184static int set_mc_hash(struct zd_mac *mac)
179{ 185{
180 struct zd_mc_hash hash; 186 struct zd_mc_hash hash;
181 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
182
183 zd_mc_clear(&hash); 187 zd_mc_clear(&hash);
184 if (ieee->iw_mode == IW_MODE_MONITOR)
185 zd_mc_add_all(&hash);
186
187 return zd_chip_set_multicast_hash(&mac->chip, &hash); 188 return zd_chip_set_multicast_hash(&mac->chip, &hash);
188} 189}
189 190
190int zd_mac_open(struct net_device *netdev) 191static int zd_op_start(struct ieee80211_hw *hw)
191{ 192{
192 struct zd_mac *mac = zd_netdev_mac(netdev); 193 struct zd_mac *mac = zd_hw_mac(hw);
193 struct zd_chip *chip = &mac->chip; 194 struct zd_chip *chip = &mac->chip;
194 struct zd_usb *usb = &chip->usb; 195 struct zd_usb *usb = &chip->usb;
195 int r; 196 int r;
@@ -200,46 +201,33 @@ int zd_mac_open(struct net_device *netdev)
200 goto out; 201 goto out;
201 } 202 }
202 203
203 tasklet_enable(&mac->rx_tasklet);
204
205 r = zd_chip_enable_int(chip); 204 r = zd_chip_enable_int(chip);
206 if (r < 0) 205 if (r < 0)
207 goto out; 206 goto out;
208 207
209 r = zd_write_mac_addr(chip, netdev->dev_addr);
210 if (r)
211 goto disable_int;
212
213 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G); 208 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
214 if (r < 0) 209 if (r < 0)
215 goto disable_int; 210 goto disable_int;
216 r = set_rx_filter(mac); 211 r = set_rx_filter(mac);
217 if (r) 212 if (r)
218 goto disable_int; 213 goto disable_int;
219 r = set_sniffer(mac);
220 if (r)
221 goto disable_int;
222 r = set_mc_hash(mac); 214 r = set_mc_hash(mac);
223 if (r) 215 if (r)
224 goto disable_int; 216 goto disable_int;
225 r = zd_chip_switch_radio_on(chip); 217 r = zd_chip_switch_radio_on(chip);
226 if (r < 0) 218 if (r < 0)
227 goto disable_int; 219 goto disable_int;
228 r = zd_chip_set_channel(chip, mac->requested_channel); 220 r = zd_chip_enable_rxtx(chip);
229 if (r < 0)
230 goto disable_radio;
231 r = zd_chip_enable_rx(chip);
232 if (r < 0) 221 if (r < 0)
233 goto disable_radio; 222 goto disable_radio;
234 r = zd_chip_enable_hwint(chip); 223 r = zd_chip_enable_hwint(chip);
235 if (r < 0) 224 if (r < 0)
236 goto disable_rx; 225 goto disable_rxtx;
237 226
238 housekeeping_enable(mac); 227 housekeeping_enable(mac);
239 ieee80211softmac_start(netdev);
240 return 0; 228 return 0;
241disable_rx: 229disable_rxtx:
242 zd_chip_disable_rx(chip); 230 zd_chip_disable_rxtx(chip);
243disable_radio: 231disable_radio:
244 zd_chip_switch_radio_off(chip); 232 zd_chip_switch_radio_off(chip);
245disable_int: 233disable_int:
@@ -248,494 +236,190 @@ out:
248 return r; 236 return r;
249} 237}
250 238
251int zd_mac_stop(struct net_device *netdev) 239/**
240 * clear_tx_skb_control_block - clears the control block of tx skbuffs
241 * @skb: a &struct sk_buff pointer
242 *
243 * This clears the control block of skbuff buffers, which were transmitted to
244 * the device. Notify that the function is not thread-safe, so prevent
245 * multiple calls.
246 */
247static void clear_tx_skb_control_block(struct sk_buff *skb)
248{
249 struct zd_tx_skb_control_block *cb =
250 (struct zd_tx_skb_control_block *)skb->cb;
251
252 kfree(cb->control);
253 cb->control = NULL;
254}
255
256/**
257 * kfree_tx_skb - frees a tx skbuff
258 * @skb: a &struct sk_buff pointer
259 *
260 * Frees the tx skbuff. Frees also the allocated control structure in the
261 * control block if necessary.
262 */
263static void kfree_tx_skb(struct sk_buff *skb)
252{ 264{
253 struct zd_mac *mac = zd_netdev_mac(netdev); 265 clear_tx_skb_control_block(skb);
254 struct zd_chip *chip = &mac->chip; 266 dev_kfree_skb_any(skb);
267}
255 268
256 netif_stop_queue(netdev); 269static void zd_op_stop(struct ieee80211_hw *hw)
270{
271 struct zd_mac *mac = zd_hw_mac(hw);
272 struct zd_chip *chip = &mac->chip;
273 struct sk_buff *skb;
274 struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue;
257 275
258 /* 276 /* The order here deliberately is a little different from the open()
259 * The order here deliberately is a little different from the open()
260 * method, since we need to make sure there is no opportunity for RX 277 * method, since we need to make sure there is no opportunity for RX
261 * frames to be processed by softmac after we have stopped it. 278 * frames to be processed by mac80211 after we have stopped it.
262 */ 279 */
263 280
264 zd_chip_disable_rx(chip); 281 zd_chip_disable_rxtx(chip);
265 skb_queue_purge(&mac->rx_queue);
266 tasklet_disable(&mac->rx_tasklet);
267 housekeeping_disable(mac); 282 housekeeping_disable(mac);
268 ieee80211softmac_stop(netdev);
269
270 /* Ensure no work items are running or queued from this point */
271 cancel_delayed_work(&mac->set_rts_cts_work);
272 cancel_delayed_work(&mac->set_basic_rates_work);
273 flush_workqueue(zd_workqueue); 283 flush_workqueue(zd_workqueue);
274 mac->updating_rts_rate = 0;
275 mac->updating_basic_rates = 0;
276 284
277 zd_chip_disable_hwint(chip); 285 zd_chip_disable_hwint(chip);
278 zd_chip_switch_radio_off(chip); 286 zd_chip_switch_radio_off(chip);
279 zd_chip_disable_int(chip); 287 zd_chip_disable_int(chip);
280 288
281 return 0;
282}
283
284int zd_mac_set_mac_address(struct net_device *netdev, void *p)
285{
286 int r;
287 unsigned long flags;
288 struct sockaddr *addr = p;
289 struct zd_mac *mac = zd_netdev_mac(netdev);
290 struct zd_chip *chip = &mac->chip;
291 DECLARE_MAC_BUF(mac2);
292 289
293 if (!is_valid_ether_addr(addr->sa_data)) 290 while ((skb = skb_dequeue(ack_wait_queue)))
294 return -EADDRNOTAVAIL; 291 kfree_tx_skb(skb);
295
296 dev_dbg_f(zd_mac_dev(mac),
297 "Setting MAC to %s\n", print_mac(mac2, addr->sa_data));
298
299 if (netdev->flags & IFF_UP) {
300 r = zd_write_mac_addr(chip, addr->sa_data);
301 if (r)
302 return r;
303 }
304
305 spin_lock_irqsave(&mac->lock, flags);
306 memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN);
307 spin_unlock_irqrestore(&mac->lock, flags);
308
309 return 0;
310}
311
312static void set_multicast_hash_handler(struct work_struct *work)
313{
314 struct zd_mac *mac = container_of(work, struct zd_mac,
315 set_multicast_hash_work);
316 struct zd_mc_hash hash;
317
318 spin_lock_irq(&mac->lock);
319 hash = mac->multicast_hash;
320 spin_unlock_irq(&mac->lock);
321
322 zd_chip_set_multicast_hash(&mac->chip, &hash);
323}
324
325void zd_mac_set_multicast_list(struct net_device *dev)
326{
327 struct zd_mac *mac = zd_netdev_mac(dev);
328 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
329 struct zd_mc_hash hash;
330 struct dev_mc_list *mc;
331 unsigned long flags;
332 DECLARE_MAC_BUF(mac2);
333
334 if (dev->flags & (IFF_PROMISC|IFF_ALLMULTI) ||
335 ieee->iw_mode == IW_MODE_MONITOR) {
336 zd_mc_add_all(&hash);
337 } else {
338 zd_mc_clear(&hash);
339 for (mc = dev->mc_list; mc; mc = mc->next) {
340 dev_dbg_f(zd_mac_dev(mac), "mc addr %s\n",
341 print_mac(mac2, mc->dmi_addr));
342 zd_mc_add_addr(&hash, mc->dmi_addr);
343 }
344 }
345
346 spin_lock_irqsave(&mac->lock, flags);
347 mac->multicast_hash = hash;
348 spin_unlock_irqrestore(&mac->lock, flags);
349 queue_work(zd_workqueue, &mac->set_multicast_hash_work);
350} 292}
351 293
352int zd_mac_set_regdomain(struct zd_mac *mac, u8 regdomain) 294/**
353{ 295 * init_tx_skb_control_block - initializes skb control block
354 int r; 296 * @skb: a &sk_buff pointer
355 u8 channel; 297 * @dev: pointer to the mac80221 device
356 298 * @control: mac80211 tx control applying for the frame in @skb
357 ZD_ASSERT(!irqs_disabled()); 299 *
358 spin_lock_irq(&mac->lock); 300 * Initializes the control block of the skbuff to be transmitted.
359 if (regdomain == 0) { 301 */
360 regdomain = mac->default_regdomain; 302static int init_tx_skb_control_block(struct sk_buff *skb,
361 } 303 struct ieee80211_hw *hw,
362 if (!zd_regdomain_supported(regdomain)) { 304 struct ieee80211_tx_control *control)
363 spin_unlock_irq(&mac->lock); 305{
364 return -EINVAL; 306 struct zd_tx_skb_control_block *cb =
365 } 307 (struct zd_tx_skb_control_block *)skb->cb;
366 mac->regdomain = regdomain; 308
367 channel = mac->requested_channel; 309 ZD_ASSERT(sizeof(*cb) <= sizeof(skb->cb));
368 spin_unlock_irq(&mac->lock); 310 memset(cb, 0, sizeof(*cb));
369 311 cb->hw= hw;
370 r = zd_geo_init(zd_mac_to_ieee80211(mac), regdomain); 312 cb->control = kmalloc(sizeof(*control), GFP_ATOMIC);
371 if (r) 313 if (cb->control == NULL)
372 return r; 314 return -ENOMEM;
373 if (!zd_regdomain_supports_channel(regdomain, channel)) { 315 memcpy(cb->control, control, sizeof(*control));
374 r = reset_channel(mac);
375 if (r)
376 return r;
377 }
378 316
379 return 0; 317 return 0;
380} 318}
381 319
382u8 zd_mac_get_regdomain(struct zd_mac *mac) 320/**
383{ 321 * tx_status - reports tx status of a packet if required
384 unsigned long flags; 322 * @hw - a &struct ieee80211_hw pointer
385 u8 regdomain; 323 * @skb - a sk-buffer
386 324 * @status - the tx status of the packet without control information
387 spin_lock_irqsave(&mac->lock, flags); 325 * @success - True for successfull transmission of the frame
388 regdomain = mac->regdomain; 326 *
389 spin_unlock_irqrestore(&mac->lock, flags); 327 * This information calls ieee80211_tx_status_irqsafe() if required by the
390 return regdomain; 328 * control information. It copies the control information into the status
391} 329 * information.
392 330 *
393/* Fallback to lowest rate, if rate is unknown. */ 331 * If no status information has been requested, the skb is freed.
394static u8 rate_to_zd_rate(u8 rate) 332 */
395{ 333static void tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
396 switch (rate) { 334 struct ieee80211_tx_status *status,
397 case IEEE80211_CCK_RATE_2MB: 335 bool success)
398 return ZD_CCK_RATE_2M;
399 case IEEE80211_CCK_RATE_5MB:
400 return ZD_CCK_RATE_5_5M;
401 case IEEE80211_CCK_RATE_11MB:
402 return ZD_CCK_RATE_11M;
403 case IEEE80211_OFDM_RATE_6MB:
404 return ZD_OFDM_RATE_6M;
405 case IEEE80211_OFDM_RATE_9MB:
406 return ZD_OFDM_RATE_9M;
407 case IEEE80211_OFDM_RATE_12MB:
408 return ZD_OFDM_RATE_12M;
409 case IEEE80211_OFDM_RATE_18MB:
410 return ZD_OFDM_RATE_18M;
411 case IEEE80211_OFDM_RATE_24MB:
412 return ZD_OFDM_RATE_24M;
413 case IEEE80211_OFDM_RATE_36MB:
414 return ZD_OFDM_RATE_36M;
415 case IEEE80211_OFDM_RATE_48MB:
416 return ZD_OFDM_RATE_48M;
417 case IEEE80211_OFDM_RATE_54MB:
418 return ZD_OFDM_RATE_54M;
419 }
420 return ZD_CCK_RATE_1M;
421}
422
423static u16 rate_to_cr_rate(u8 rate)
424{
425 switch (rate) {
426 case IEEE80211_CCK_RATE_2MB:
427 return CR_RATE_1M;
428 case IEEE80211_CCK_RATE_5MB:
429 return CR_RATE_5_5M;
430 case IEEE80211_CCK_RATE_11MB:
431 return CR_RATE_11M;
432 case IEEE80211_OFDM_RATE_6MB:
433 return CR_RATE_6M;
434 case IEEE80211_OFDM_RATE_9MB:
435 return CR_RATE_9M;
436 case IEEE80211_OFDM_RATE_12MB:
437 return CR_RATE_12M;
438 case IEEE80211_OFDM_RATE_18MB:
439 return CR_RATE_18M;
440 case IEEE80211_OFDM_RATE_24MB:
441 return CR_RATE_24M;
442 case IEEE80211_OFDM_RATE_36MB:
443 return CR_RATE_36M;
444 case IEEE80211_OFDM_RATE_48MB:
445 return CR_RATE_48M;
446 case IEEE80211_OFDM_RATE_54MB:
447 return CR_RATE_54M;
448 }
449 return CR_RATE_1M;
450}
451
452static void try_enable_tx(struct zd_mac *mac)
453{
454 unsigned long flags;
455
456 spin_lock_irqsave(&mac->lock, flags);
457 if (mac->updating_rts_rate == 0 && mac->updating_basic_rates == 0)
458 netif_wake_queue(mac->netdev);
459 spin_unlock_irqrestore(&mac->lock, flags);
460}
461
462static void set_rts_cts_work(struct work_struct *work)
463{ 336{
464 struct zd_mac *mac = 337 struct zd_tx_skb_control_block *cb = (struct zd_tx_skb_control_block *)
465 container_of(work, struct zd_mac, set_rts_cts_work.work); 338 skb->cb;
466 unsigned long flags;
467 u8 rts_rate;
468 unsigned int short_preamble;
469
470 mutex_lock(&mac->chip.mutex);
471
472 spin_lock_irqsave(&mac->lock, flags);
473 mac->updating_rts_rate = 0;
474 rts_rate = mac->rts_rate;
475 short_preamble = mac->short_preamble;
476 spin_unlock_irqrestore(&mac->lock, flags);
477
478 zd_chip_set_rts_cts_rate_locked(&mac->chip, rts_rate, short_preamble);
479 mutex_unlock(&mac->chip.mutex);
480 339
481 try_enable_tx(mac); 340 ZD_ASSERT(cb->control != NULL);
341 memcpy(&status->control, cb->control, sizeof(status->control));
342 if (!success)
343 status->excessive_retries = 1;
344 clear_tx_skb_control_block(skb);
345 ieee80211_tx_status_irqsafe(hw, skb, status);
482} 346}
483 347
484static void set_basic_rates_work(struct work_struct *work) 348/**
349 * zd_mac_tx_failed - callback for failed frames
350 * @dev: the mac80211 wireless device
351 *
352 * This function is called if a frame couldn't be succesfully be
353 * transferred. The first frame from the tx queue, will be selected and
354 * reported as error to the upper layers.
355 */
356void zd_mac_tx_failed(struct ieee80211_hw *hw)
485{ 357{
486 struct zd_mac *mac = 358 struct sk_buff_head *q = &zd_hw_mac(hw)->ack_wait_queue;
487 container_of(work, struct zd_mac, set_basic_rates_work.work); 359 struct sk_buff *skb;
488 unsigned long flags; 360 struct ieee80211_tx_status status = {{0}};
489 u16 basic_rates;
490
491 mutex_lock(&mac->chip.mutex);
492
493 spin_lock_irqsave(&mac->lock, flags);
494 mac->updating_basic_rates = 0;
495 basic_rates = mac->basic_rates;
496 spin_unlock_irqrestore(&mac->lock, flags);
497
498 zd_chip_set_basic_rates_locked(&mac->chip, basic_rates);
499 mutex_unlock(&mac->chip.mutex);
500 361
501 try_enable_tx(mac); 362 skb = skb_dequeue(q);
363 if (skb == NULL)
364 return;
365 tx_status(hw, skb, &status, 0);
502} 366}
503 367
504static void bssinfo_change(struct net_device *netdev, u32 changes) 368/**
505{ 369 * zd_mac_tx_to_dev - callback for USB layer
506 struct zd_mac *mac = zd_netdev_mac(netdev); 370 * @skb: a &sk_buff pointer
507 struct ieee80211softmac_device *softmac = ieee80211_priv(netdev); 371 * @error: error value, 0 if transmission successful
508 struct ieee80211softmac_bss_info *bssinfo = &softmac->bssinfo; 372 *
509 int need_set_rts_cts = 0; 373 * Informs the MAC layer that the frame has successfully transferred to the
510 int need_set_rates = 0; 374 * device. If an ACK is required and the transfer to the device has been
511 u16 basic_rates; 375 * successful, the packets are put on the @ack_wait_queue with
512 unsigned long flags; 376 * the control set removed.
513 377 */
514 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes); 378void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
515 379{
516 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE) { 380 struct zd_tx_skb_control_block *cb =
517 spin_lock_irqsave(&mac->lock, flags); 381 (struct zd_tx_skb_control_block *)skb->cb;
518 mac->short_preamble = bssinfo->short_preamble; 382 struct ieee80211_hw *hw = cb->hw;
519 spin_unlock_irqrestore(&mac->lock, flags); 383
520 need_set_rts_cts = 1; 384 if (likely(cb->control)) {
521 } 385 skb_pull(skb, sizeof(struct zd_ctrlset));
522 386 if (unlikely(error ||
523 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) { 387 (cb->control->flags & IEEE80211_TXCTL_NO_ACK)))
524 /* Set RTS rate to highest available basic rate */ 388 {
525 u8 hi_rate = ieee80211softmac_highest_supported_rate(softmac, 389 struct ieee80211_tx_status status = {{0}};
526 &bssinfo->supported_rates, 1); 390 tx_status(hw, skb, &status, !error);
527 hi_rate = rate_to_zd_rate(hi_rate);
528
529 spin_lock_irqsave(&mac->lock, flags);
530 if (hi_rate != mac->rts_rate) {
531 mac->rts_rate = hi_rate;
532 need_set_rts_cts = 1;
533 }
534 spin_unlock_irqrestore(&mac->lock, flags);
535
536 /* Set basic rates */
537 need_set_rates = 1;
538 if (bssinfo->supported_rates.count == 0) {
539 /* Allow the device to be flexible */
540 basic_rates = CR_RATES_80211B | CR_RATES_80211G;
541 } else { 391 } else {
542 int i = 0; 392 struct sk_buff_head *q =
543 basic_rates = 0; 393 &zd_hw_mac(hw)->ack_wait_queue;
544 394
545 for (i = 0; i < bssinfo->supported_rates.count; i++) { 395 skb_queue_tail(q, skb);
546 u16 rate = bssinfo->supported_rates.rates[i]; 396 while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS)
547 if ((rate & IEEE80211_BASIC_RATE_MASK) == 0) 397 zd_mac_tx_failed(hw);
548 continue;
549
550 rate &= ~IEEE80211_BASIC_RATE_MASK;
551 basic_rates |= rate_to_cr_rate(rate);
552 }
553 } 398 }
554 spin_lock_irqsave(&mac->lock, flags); 399 } else {
555 mac->basic_rates = basic_rates; 400 kfree_tx_skb(skb);
556 spin_unlock_irqrestore(&mac->lock, flags);
557 }
558
559 /* Schedule any changes we made above */
560
561 spin_lock_irqsave(&mac->lock, flags);
562 if (need_set_rts_cts && !mac->updating_rts_rate) {
563 mac->updating_rts_rate = 1;
564 netif_stop_queue(mac->netdev);
565 queue_delayed_work(zd_workqueue, &mac->set_rts_cts_work, 0);
566 }
567 if (need_set_rates && !mac->updating_basic_rates) {
568 mac->updating_basic_rates = 1;
569 netif_stop_queue(mac->netdev);
570 queue_delayed_work(zd_workqueue, &mac->set_basic_rates_work,
571 0);
572 }
573 spin_unlock_irqrestore(&mac->lock, flags);
574}
575
576static void set_channel(struct net_device *netdev, u8 channel)
577{
578 struct zd_mac *mac = zd_netdev_mac(netdev);
579
580 dev_dbg_f(zd_mac_dev(mac), "channel %d\n", channel);
581
582 zd_chip_set_channel(&mac->chip, channel);
583}
584
585int zd_mac_request_channel(struct zd_mac *mac, u8 channel)
586{
587 unsigned long lock_flags;
588 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
589
590 if (ieee->iw_mode == IW_MODE_INFRA)
591 return -EPERM;
592
593 spin_lock_irqsave(&mac->lock, lock_flags);
594 if (!zd_regdomain_supports_channel(mac->regdomain, channel)) {
595 spin_unlock_irqrestore(&mac->lock, lock_flags);
596 return -EINVAL;
597 }
598 mac->requested_channel = channel;
599 spin_unlock_irqrestore(&mac->lock, lock_flags);
600 if (netif_running(mac->netdev))
601 return zd_chip_set_channel(&mac->chip, channel);
602 else
603 return 0;
604}
605
606u8 zd_mac_get_channel(struct zd_mac *mac)
607{
608 u8 channel = zd_chip_get_channel(&mac->chip);
609
610 dev_dbg_f(zd_mac_dev(mac), "channel %u\n", channel);
611 return channel;
612}
613
614int zd_mac_set_mode(struct zd_mac *mac, u32 mode)
615{
616 struct ieee80211_device *ieee;
617
618 switch (mode) {
619 case IW_MODE_AUTO:
620 case IW_MODE_ADHOC:
621 case IW_MODE_INFRA:
622 mac->netdev->type = ARPHRD_ETHER;
623 break;
624 case IW_MODE_MONITOR:
625 mac->netdev->type = ARPHRD_IEEE80211_RADIOTAP;
626 break;
627 default:
628 dev_dbg_f(zd_mac_dev(mac), "wrong mode %u\n", mode);
629 return -EINVAL;
630 }
631
632 ieee = zd_mac_to_ieee80211(mac);
633 ZD_ASSERT(!irqs_disabled());
634 spin_lock_irq(&ieee->lock);
635 ieee->iw_mode = mode;
636 spin_unlock_irq(&ieee->lock);
637
638 if (netif_running(mac->netdev)) {
639 int r = set_rx_filter(mac);
640 if (r)
641 return r;
642 return set_sniffer(mac);
643 }
644
645 return 0;
646}
647
648int zd_mac_get_mode(struct zd_mac *mac, u32 *mode)
649{
650 unsigned long flags;
651 struct ieee80211_device *ieee;
652
653 ieee = zd_mac_to_ieee80211(mac);
654 spin_lock_irqsave(&ieee->lock, flags);
655 *mode = ieee->iw_mode;
656 spin_unlock_irqrestore(&ieee->lock, flags);
657 return 0;
658}
659
660int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range)
661{
662 int i;
663 const struct channel_range *channel_range;
664 u8 regdomain;
665
666 memset(range, 0, sizeof(*range));
667
668 /* FIXME: Not so important and depends on the mode. For 802.11g
669 * usually this value is used. It seems to be that Bit/s number is
670 * given here.
671 */
672 range->throughput = 27 * 1000 * 1000;
673
674 range->max_qual.qual = 100;
675 range->max_qual.level = 100;
676
677 /* FIXME: Needs still to be tuned. */
678 range->avg_qual.qual = 71;
679 range->avg_qual.level = 80;
680
681 /* FIXME: depends on standard? */
682 range->min_rts = 256;
683 range->max_rts = 2346;
684
685 range->min_frag = MIN_FRAG_THRESHOLD;
686 range->max_frag = MAX_FRAG_THRESHOLD;
687
688 range->max_encoding_tokens = WEP_KEYS;
689 range->num_encoding_sizes = 2;
690 range->encoding_size[0] = 5;
691 range->encoding_size[1] = WEP_KEY_LEN;
692
693 range->we_version_compiled = WIRELESS_EXT;
694 range->we_version_source = 20;
695
696 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
697 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
698
699 ZD_ASSERT(!irqs_disabled());
700 spin_lock_irq(&mac->lock);
701 regdomain = mac->regdomain;
702 spin_unlock_irq(&mac->lock);
703 channel_range = zd_channel_range(regdomain);
704
705 range->num_channels = channel_range->end - channel_range->start;
706 range->old_num_channels = range->num_channels;
707 range->num_frequency = range->num_channels;
708 range->old_num_frequency = range->num_frequency;
709
710 for (i = 0; i < range->num_frequency; i++) {
711 struct iw_freq *freq = &range->freq[i];
712 freq->i = channel_range->start + i;
713 zd_channel_to_freq(freq, freq->i);
714 } 401 }
715
716 return 0;
717} 402}
718 403
719static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length) 404static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
720{ 405{
721 /* ZD_PURE_RATE() must be used to remove the modulation type flag of 406 /* ZD_PURE_RATE() must be used to remove the modulation type flag of
722 * the zd-rate values. */ 407 * the zd-rate values.
408 */
723 static const u8 rate_divisor[] = { 409 static const u8 rate_divisor[] = {
724 [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1, 410 [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1,
725 [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2, 411 [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2,
726 412 /* Bits must be doubled. */
727 /* bits must be doubled */ 413 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11,
728 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11, 414 [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11,
729 415 [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6,
730 [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11, 416 [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9,
731 [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6, 417 [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12,
732 [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9, 418 [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18,
733 [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12, 419 [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24,
734 [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18, 420 [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36,
735 [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24, 421 [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
736 [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36, 422 [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
737 [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
738 [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
739 }; 423 };
740 424
741 u32 bits = (u32)tx_length * 8; 425 u32 bits = (u32)tx_length * 8;
@@ -764,34 +448,10 @@ static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
764 return bits/divisor; 448 return bits/divisor;
765} 449}
766 450
767static void cs_set_modulation(struct zd_mac *mac, struct zd_ctrlset *cs,
768 struct ieee80211_hdr_4addr *hdr)
769{
770 struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev);
771 u16 ftype = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_ctl));
772 u8 rate;
773 int is_mgt = (ftype == IEEE80211_FTYPE_MGMT) != 0;
774 int is_multicast = is_multicast_ether_addr(hdr->addr1);
775 int short_preamble = ieee80211softmac_short_preamble_ok(softmac,
776 is_multicast, is_mgt);
777
778 rate = ieee80211softmac_suggest_txrate(softmac, is_multicast, is_mgt);
779 cs->modulation = rate_to_zd_rate(rate);
780
781 /* Set short preamble bit when appropriate */
782 if (short_preamble && ZD_MODULATION_TYPE(cs->modulation) == ZD_CCK
783 && cs->modulation != ZD_CCK_RATE_1M)
784 cs->modulation |= ZD_CCK_PREA_SHORT;
785}
786
787static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs, 451static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
788 struct ieee80211_hdr_4addr *header) 452 struct ieee80211_hdr *header, u32 flags)
789{ 453{
790 struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev); 454 u16 fctl = le16_to_cpu(header->frame_control);
791 unsigned int tx_length = le16_to_cpu(cs->tx_length);
792 u16 fctl = le16_to_cpu(header->frame_ctl);
793 u16 ftype = WLAN_FC_GET_TYPE(fctl);
794 u16 stype = WLAN_FC_GET_STYPE(fctl);
795 455
796 /* 456 /*
797 * CONTROL TODO: 457 * CONTROL TODO:
@@ -802,7 +462,7 @@ static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
802 cs->control = 0; 462 cs->control = 0;
803 463
804 /* First fragment */ 464 /* First fragment */
805 if (WLAN_GET_SEQ_FRAG(le16_to_cpu(header->seq_ctl)) == 0) 465 if (flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
806 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF; 466 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
807 467
808 /* Multicast */ 468 /* Multicast */
@@ -810,54 +470,37 @@ static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
810 cs->control |= ZD_CS_MULTICAST; 470 cs->control |= ZD_CS_MULTICAST;
811 471
812 /* PS-POLL */ 472 /* PS-POLL */
813 if (ftype == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) 473 if ((fctl & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)) ==
474 (IEEE80211_FTYPE_CTL|IEEE80211_STYPE_PSPOLL))
814 cs->control |= ZD_CS_PS_POLL_FRAME; 475 cs->control |= ZD_CS_PS_POLL_FRAME;
815 476
816 /* Unicast data frames over the threshold should have RTS */ 477 if (flags & IEEE80211_TXCTL_USE_RTS_CTS)
817 if (!is_multicast_ether_addr(header->addr1) &&
818 ftype != IEEE80211_FTYPE_MGMT &&
819 tx_length > zd_netdev_ieee80211(mac->netdev)->rts)
820 cs->control |= ZD_CS_RTS; 478 cs->control |= ZD_CS_RTS;
821 479
822 /* Use CTS-to-self protection if required */ 480 if (flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
823 if (ZD_MODULATION_TYPE(cs->modulation) == ZD_OFDM &&
824 ieee80211softmac_protection_needed(softmac)) {
825 /* FIXME: avoid sending RTS *and* self-CTS, is that correct? */
826 cs->control &= ~ZD_CS_RTS;
827 cs->control |= ZD_CS_SELF_CTS; 481 cs->control |= ZD_CS_SELF_CTS;
828 }
829 482
830 /* FIXME: Management frame? */ 483 /* FIXME: Management frame? */
831} 484}
832 485
833static int fill_ctrlset(struct zd_mac *mac, 486static int fill_ctrlset(struct zd_mac *mac,
834 struct ieee80211_txb *txb, 487 struct sk_buff *skb,
835 int frag_num) 488 struct ieee80211_tx_control *control)
836{ 489{
837 int r; 490 int r;
838 struct sk_buff *skb = txb->fragments[frag_num]; 491 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
839 struct ieee80211_hdr_4addr *hdr = 492 unsigned int frag_len = skb->len + FCS_LEN;
840 (struct ieee80211_hdr_4addr *) skb->data;
841 unsigned int frag_len = skb->len + IEEE80211_FCS_LEN;
842 unsigned int next_frag_len;
843 unsigned int packet_length; 493 unsigned int packet_length;
844 struct zd_ctrlset *cs = (struct zd_ctrlset *) 494 struct zd_ctrlset *cs = (struct zd_ctrlset *)
845 skb_push(skb, sizeof(struct zd_ctrlset)); 495 skb_push(skb, sizeof(struct zd_ctrlset));
846 496
847 if (frag_num+1 < txb->nr_frags) {
848 next_frag_len = txb->fragments[frag_num+1]->len +
849 IEEE80211_FCS_LEN;
850 } else {
851 next_frag_len = 0;
852 }
853 ZD_ASSERT(frag_len <= 0xffff); 497 ZD_ASSERT(frag_len <= 0xffff);
854 ZD_ASSERT(next_frag_len <= 0xffff);
855 498
856 cs_set_modulation(mac, cs, hdr); 499 cs->modulation = control->tx_rate;
857 500
858 cs->tx_length = cpu_to_le16(frag_len); 501 cs->tx_length = cpu_to_le16(frag_len);
859 502
860 cs_set_control(mac, cs, hdr); 503 cs_set_control(mac, cs, hdr, control->flags);
861 504
862 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10; 505 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
863 ZD_ASSERT(packet_length <= 0xffff); 506 ZD_ASSERT(packet_length <= 0xffff);
@@ -886,419 +529,399 @@ static int fill_ctrlset(struct zd_mac *mac,
886 if (r < 0) 529 if (r < 0)
887 return r; 530 return r;
888 cs->current_length = cpu_to_le16(r); 531 cs->current_length = cpu_to_le16(r);
889 532 cs->next_frame_length = 0;
890 if (next_frag_len == 0) {
891 cs->next_frame_length = 0;
892 } else {
893 r = zd_calc_tx_length_us(NULL, ZD_RATE(cs->modulation),
894 next_frag_len);
895 if (r < 0)
896 return r;
897 cs->next_frame_length = cpu_to_le16(r);
898 }
899 533
900 return 0; 534 return 0;
901} 535}
902 536
903static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri) 537/**
538 * zd_op_tx - transmits a network frame to the device
539 *
540 * @dev: mac80211 hardware device
541 * @skb: socket buffer
542 * @control: the control structure
543 *
544 * This function transmit an IEEE 802.11 network frame to the device. The
545 * control block of the skbuff will be initialized. If necessary the incoming
546 * mac80211 queues will be stopped.
547 */
548static int zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
549 struct ieee80211_tx_control *control)
904{ 550{
905 int i, r; 551 struct zd_mac *mac = zd_hw_mac(hw);
906 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 552 int r;
907 553
908 for (i = 0; i < txb->nr_frags; i++) { 554 r = fill_ctrlset(mac, skb, control);
909 struct sk_buff *skb = txb->fragments[i]; 555 if (r)
556 return r;
910 557
911 r = fill_ctrlset(mac, txb, i); 558 r = init_tx_skb_control_block(skb, hw, control);
912 if (r) { 559 if (r)
913 ieee->stats.tx_dropped++; 560 return r;
914 return r; 561 r = zd_usb_tx(&mac->chip.usb, skb);
915 } 562 if (r) {
916 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len); 563 clear_tx_skb_control_block(skb);
917 if (r) { 564 return r;
918 ieee->stats.tx_dropped++;
919 return r;
920 }
921 } 565 }
922
923 /* FIXME: shouldn't this be handled by the upper layers? */
924 mac->netdev->trans_start = jiffies;
925
926 ieee80211_txb_free(txb);
927 return 0; 566 return 0;
928} 567}
929 568
930struct zd_rt_hdr { 569/**
931 struct ieee80211_radiotap_header rt_hdr; 570 * filter_ack - filters incoming packets for acknowledgements
932 u8 rt_flags; 571 * @dev: the mac80211 device
933 u8 rt_rate; 572 * @rx_hdr: received header
934 u16 rt_channel; 573 * @stats: the status for the received packet
935 u16 rt_chbitmask;
936} __attribute__((packed));
937
938static void fill_rt_header(void *buffer, struct zd_mac *mac,
939 const struct ieee80211_rx_stats *stats,
940 const struct rx_status *status)
941{
942 struct zd_rt_hdr *hdr = buffer;
943
944 hdr->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
945 hdr->rt_hdr.it_pad = 0;
946 hdr->rt_hdr.it_len = cpu_to_le16(sizeof(struct zd_rt_hdr));
947 hdr->rt_hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
948 (1 << IEEE80211_RADIOTAP_CHANNEL) |
949 (1 << IEEE80211_RADIOTAP_RATE));
950
951 hdr->rt_flags = 0;
952 if (status->decryption_type & (ZD_RX_WEP64|ZD_RX_WEP128|ZD_RX_WEP256))
953 hdr->rt_flags |= IEEE80211_RADIOTAP_F_WEP;
954
955 hdr->rt_rate = stats->rate / 5;
956
957 /* FIXME: 802.11a */
958 hdr->rt_channel = cpu_to_le16(ieee80211chan2mhz(
959 _zd_chip_get_channel(&mac->chip)));
960 hdr->rt_chbitmask = cpu_to_le16(IEEE80211_CHAN_2GHZ |
961 ((status->frame_status & ZD_RX_FRAME_MODULATION_MASK) ==
962 ZD_RX_OFDM ? IEEE80211_CHAN_OFDM : IEEE80211_CHAN_CCK));
963}
964
965/* Returns 1 if the data packet is for us and 0 otherwise. */
966static int is_data_packet_for_us(struct ieee80211_device *ieee,
967 struct ieee80211_hdr_4addr *hdr)
968{
969 struct net_device *netdev = ieee->dev;
970 u16 fc = le16_to_cpu(hdr->frame_ctl);
971
972 ZD_ASSERT(WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA);
973
974 switch (ieee->iw_mode) {
975 case IW_MODE_ADHOC:
976 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != 0 ||
977 compare_ether_addr(hdr->addr3, ieee->bssid) != 0)
978 return 0;
979 break;
980 case IW_MODE_AUTO:
981 case IW_MODE_INFRA:
982 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) !=
983 IEEE80211_FCTL_FROMDS ||
984 compare_ether_addr(hdr->addr2, ieee->bssid) != 0)
985 return 0;
986 break;
987 default:
988 ZD_ASSERT(ieee->iw_mode != IW_MODE_MONITOR);
989 return 0;
990 }
991
992 return compare_ether_addr(hdr->addr1, netdev->dev_addr) == 0 ||
993 (is_multicast_ether_addr(hdr->addr1) &&
994 compare_ether_addr(hdr->addr3, netdev->dev_addr) != 0) ||
995 (netdev->flags & IFF_PROMISC);
996}
997
998/* Filters received packets. The function returns 1 if the packet should be
999 * forwarded to ieee80211_rx(). If the packet should be ignored the function
1000 * returns 0. If an invalid packet is found the function returns -EINVAL.
1001 * 574 *
1002 * The function calls ieee80211_rx_mgt() directly. 575 * This functions looks for ACK packets and tries to match them with the
576 * frames in the tx queue. If a match is found the frame will be dequeued and
577 * the upper layers is informed about the successful transmission. If
578 * mac80211 queues have been stopped and the number of frames still to be
579 * transmitted is low the queues will be opened again.
1003 * 580 *
1004 * It has been based on ieee80211_rx_any. 581 * Returns 1 if the frame was an ACK, 0 if it was ignored.
1005 */ 582 */
1006static int filter_rx(struct ieee80211_device *ieee, 583static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
1007 const u8 *buffer, unsigned int length, 584 struct ieee80211_rx_status *stats)
1008 struct ieee80211_rx_stats *stats)
1009{ 585{
1010 struct ieee80211_hdr_4addr *hdr; 586 u16 fc = le16_to_cpu(rx_hdr->frame_control);
1011 u16 fc; 587 struct sk_buff *skb;
1012 588 struct sk_buff_head *q;
1013 if (ieee->iw_mode == IW_MODE_MONITOR) 589 unsigned long flags;
1014 return 1;
1015
1016 hdr = (struct ieee80211_hdr_4addr *)buffer;
1017 fc = le16_to_cpu(hdr->frame_ctl);
1018 if ((fc & IEEE80211_FCTL_VERS) != 0)
1019 return -EINVAL;
1020 590
1021 switch (WLAN_FC_GET_TYPE(fc)) { 591 if ((fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) !=
1022 case IEEE80211_FTYPE_MGMT: 592 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK))
1023 if (length < sizeof(struct ieee80211_hdr_3addr))
1024 return -EINVAL;
1025 ieee80211_rx_mgt(ieee, hdr, stats);
1026 return 0; 593 return 0;
1027 case IEEE80211_FTYPE_CTL:
1028 return 0;
1029 case IEEE80211_FTYPE_DATA:
1030 /* Ignore invalid short buffers */
1031 if (length < sizeof(struct ieee80211_hdr_3addr))
1032 return -EINVAL;
1033 return is_data_packet_for_us(ieee, hdr);
1034 }
1035 594
1036 return -EINVAL; 595 q = &zd_hw_mac(hw)->ack_wait_queue;
596 spin_lock_irqsave(&q->lock, flags);
597 for (skb = q->next; skb != (struct sk_buff *)q; skb = skb->next) {
598 struct ieee80211_hdr *tx_hdr;
599
600 tx_hdr = (struct ieee80211_hdr *)skb->data;
601 if (likely(!compare_ether_addr(tx_hdr->addr2, rx_hdr->addr1)))
602 {
603 struct ieee80211_tx_status status = {{0}};
604 status.flags = IEEE80211_TX_STATUS_ACK;
605 status.ack_signal = stats->ssi;
606 __skb_unlink(skb, q);
607 tx_status(hw, skb, &status, 1);
608 goto out;
609 }
610 }
611out:
612 spin_unlock_irqrestore(&q->lock, flags);
613 return 1;
1037} 614}
1038 615
1039static void update_qual_rssi(struct zd_mac *mac, 616int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
1040 const u8 *buffer, unsigned int length,
1041 u8 qual_percent, u8 rssi_percent)
1042{ 617{
1043 unsigned long flags; 618 struct zd_mac *mac = zd_hw_mac(hw);
1044 struct ieee80211_hdr_3addr *hdr; 619 struct ieee80211_rx_status stats;
1045 int i; 620 const struct rx_status *status;
621 struct sk_buff *skb;
622 int bad_frame = 0;
1046 623
1047 hdr = (struct ieee80211_hdr_3addr *)buffer; 624 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
1048 if (length < offsetof(struct ieee80211_hdr_3addr, addr3)) 625 FCS_LEN + sizeof(struct rx_status))
1049 return; 626 return -EINVAL;
1050 if (compare_ether_addr(hdr->addr2, zd_mac_to_ieee80211(mac)->bssid) != 0)
1051 return;
1052 627
1053 spin_lock_irqsave(&mac->lock, flags); 628 memset(&stats, 0, sizeof(stats));
1054 i = mac->stats_count % ZD_MAC_STATS_BUFFER_SIZE;
1055 mac->qual_buffer[i] = qual_percent;
1056 mac->rssi_buffer[i] = rssi_percent;
1057 mac->stats_count++;
1058 spin_unlock_irqrestore(&mac->lock, flags);
1059}
1060 629
1061static int fill_rx_stats(struct ieee80211_rx_stats *stats, 630 /* Note about pass_failed_fcs and pass_ctrl access below:
1062 const struct rx_status **pstatus, 631 * mac locking intentionally omitted here, as this is the only unlocked
1063 struct zd_mac *mac, 632 * reader and the only writer is configure_filter. Plus, if there were
1064 const u8 *buffer, unsigned int length) 633 * any races accessing these variables, it wouldn't really matter.
1065{ 634 * If mac80211 ever provides a way for us to access filter flags
1066 const struct rx_status *status; 635 * from outside configure_filter, we could improve on this. Also, this
636 * situation may change once we implement some kind of DMA-into-skb
637 * RX path. */
1067 638
1068 *pstatus = status = (struct rx_status *) 639 /* Caller has to ensure that length >= sizeof(struct rx_status). */
640 status = (struct rx_status *)
1069 (buffer + (length - sizeof(struct rx_status))); 641 (buffer + (length - sizeof(struct rx_status)));
1070 if (status->frame_status & ZD_RX_ERROR) { 642 if (status->frame_status & ZD_RX_ERROR) {
1071 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 643 if (mac->pass_failed_fcs &&
1072 ieee->stats.rx_errors++; 644 (status->frame_status & ZD_RX_CRC32_ERROR)) {
1073 if (status->frame_status & ZD_RX_TIMEOUT_ERROR) 645 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
1074 ieee->stats.rx_missed_errors++; 646 bad_frame = 1;
1075 else if (status->frame_status & ZD_RX_FIFO_OVERRUN_ERROR) 647 } else {
1076 ieee->stats.rx_fifo_errors++; 648 return -EINVAL;
1077 else if (status->frame_status & ZD_RX_DECRYPTION_ERROR)
1078 ieee->ieee_stats.rx_discards_undecryptable++;
1079 else if (status->frame_status & ZD_RX_CRC32_ERROR) {
1080 ieee->stats.rx_crc_errors++;
1081 ieee->ieee_stats.rx_fcs_errors++;
1082 } 649 }
1083 else if (status->frame_status & ZD_RX_CRC16_ERROR)
1084 ieee->stats.rx_crc_errors++;
1085 return -EINVAL;
1086 } 650 }
1087 651
1088 memset(stats, 0, sizeof(struct ieee80211_rx_stats)); 652 stats.channel = _zd_chip_get_channel(&mac->chip);
1089 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN + 653 stats.freq = zd_channels[stats.channel - 1].freq;
1090 + sizeof(struct rx_status)); 654 stats.phymode = MODE_IEEE80211G;
1091 /* FIXME: 802.11a */ 655 stats.ssi = status->signal_strength;
1092 stats->freq = IEEE80211_24GHZ_BAND; 656 stats.signal = zd_rx_qual_percent(buffer,
1093 stats->received_channel = _zd_chip_get_channel(&mac->chip);
1094 stats->rssi = zd_rx_strength_percent(status->signal_strength);
1095 stats->signal = zd_rx_qual_percent(buffer,
1096 length - sizeof(struct rx_status), 657 length - sizeof(struct rx_status),
1097 status); 658 status);
1098 stats->mask = IEEE80211_STATMASK_RSSI | IEEE80211_STATMASK_SIGNAL; 659 stats.rate = zd_rx_rate(buffer, status);
1099 stats->rate = zd_rx_rate(buffer, status); 660
1100 if (stats->rate) 661 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
1101 stats->mask |= IEEE80211_STATMASK_RATE; 662 buffer += ZD_PLCP_HEADER_SIZE;
663
664 /* Except for bad frames, filter each frame to see if it is an ACK, in
665 * which case our internal TX tracking is updated. Normally we then
666 * bail here as there's no need to pass ACKs on up to the stack, but
667 * there is also the case where the stack has requested us to pass
668 * control frames on up (pass_ctrl) which we must consider. */
669 if (!bad_frame &&
670 filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats)
671 && !mac->pass_ctrl)
672 return 0;
1102 673
674 skb = dev_alloc_skb(length);
675 if (skb == NULL)
676 return -ENOMEM;
677 memcpy(skb_put(skb, length), buffer, length);
678
679 ieee80211_rx_irqsafe(hw, skb, &stats);
1103 return 0; 680 return 0;
1104} 681}
1105 682
1106static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb) 683static int zd_op_add_interface(struct ieee80211_hw *hw,
684 struct ieee80211_if_init_conf *conf)
1107{ 685{
1108 int r; 686 struct zd_mac *mac = zd_hw_mac(hw);
1109 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1110 struct ieee80211_rx_stats stats;
1111 const struct rx_status *status;
1112 687
1113 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + 688 /* using IEEE80211_IF_TYPE_INVALID to indicate no mode selected */
1114 IEEE80211_FCS_LEN + sizeof(struct rx_status)) 689 if (mac->type != IEEE80211_IF_TYPE_INVALID)
1115 { 690 return -EOPNOTSUPP;
1116 ieee->stats.rx_errors++;
1117 ieee->stats.rx_length_errors++;
1118 goto free_skb;
1119 }
1120 691
1121 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len); 692 switch (conf->type) {
1122 if (r) { 693 case IEEE80211_IF_TYPE_MNTR:
1123 /* Only packets with rx errors are included here. 694 case IEEE80211_IF_TYPE_STA:
1124 * The error stats have already been set in fill_rx_stats. 695 mac->type = conf->type;
1125 */ 696 break;
1126 goto free_skb; 697 default:
698 return -EOPNOTSUPP;
1127 } 699 }
1128 700
1129 __skb_pull(skb, ZD_PLCP_HEADER_SIZE); 701 return zd_write_mac_addr(&mac->chip, conf->mac_addr);
1130 __skb_trim(skb, skb->len - 702}
1131 (IEEE80211_FCS_LEN + sizeof(struct rx_status)));
1132 703
1133 ZD_ASSERT(IS_ALIGNED((unsigned long)skb->data, 4)); 704static void zd_op_remove_interface(struct ieee80211_hw *hw,
705 struct ieee80211_if_init_conf *conf)
706{
707 struct zd_mac *mac = zd_hw_mac(hw);
708 mac->type = IEEE80211_IF_TYPE_INVALID;
709 zd_write_mac_addr(&mac->chip, NULL);
710}
1134 711
1135 update_qual_rssi(mac, skb->data, skb->len, stats.signal, 712static int zd_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
1136 status->signal_strength); 713{
714 struct zd_mac *mac = zd_hw_mac(hw);
715 return zd_chip_set_channel(&mac->chip, conf->channel);
716}
1137 717
1138 r = filter_rx(ieee, skb->data, skb->len, &stats); 718static int zd_op_config_interface(struct ieee80211_hw *hw, int if_id,
1139 if (r <= 0) { 719 struct ieee80211_if_conf *conf)
1140 if (r < 0) { 720{
1141 ieee->stats.rx_errors++; 721 struct zd_mac *mac = zd_hw_mac(hw);
1142 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1143 }
1144 goto free_skb;
1145 }
1146 722
1147 if (ieee->iw_mode == IW_MODE_MONITOR) 723 spin_lock_irq(&mac->lock);
1148 fill_rt_header(skb_push(skb, sizeof(struct zd_rt_hdr)), mac, 724 mac->associated = is_valid_ether_addr(conf->bssid);
1149 &stats, status); 725 spin_unlock_irq(&mac->lock);
1150 726
1151 r = ieee80211_rx(ieee, skb, &stats); 727 /* TODO: do hardware bssid filtering */
1152 if (r) 728 return 0;
1153 return;
1154free_skb:
1155 /* We are always in a soft irq. */
1156 dev_kfree_skb(skb);
1157} 729}
1158 730
1159static void do_rx(unsigned long mac_ptr) 731static void set_multicast_hash_handler(struct work_struct *work)
1160{ 732{
1161 struct zd_mac *mac = (struct zd_mac *)mac_ptr; 733 struct zd_mac *mac =
1162 struct sk_buff *skb; 734 container_of(work, struct zd_mac, set_multicast_hash_work);
735 struct zd_mc_hash hash;
1163 736
1164 while ((skb = skb_dequeue(&mac->rx_queue)) != NULL) 737 spin_lock_irq(&mac->lock);
1165 zd_mac_rx(mac, skb); 738 hash = mac->multicast_hash;
1166} 739 spin_unlock_irq(&mac->lock);
1167 740
1168int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length) 741 zd_chip_set_multicast_hash(&mac->chip, &hash);
1169{
1170 struct sk_buff *skb;
1171 unsigned int reserved =
1172 ALIGN(max_t(unsigned int,
1173 sizeof(struct zd_rt_hdr), ZD_PLCP_HEADER_SIZE), 4) -
1174 ZD_PLCP_HEADER_SIZE;
1175
1176 skb = dev_alloc_skb(reserved + length);
1177 if (!skb) {
1178 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1179 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1180 ieee->stats.rx_dropped++;
1181 return -ENOMEM;
1182 }
1183 skb_reserve(skb, reserved);
1184 memcpy(__skb_put(skb, length), buffer, length);
1185 skb_queue_tail(&mac->rx_queue, skb);
1186 tasklet_schedule(&mac->rx_tasklet);
1187 return 0;
1188} 742}
1189 743
1190static int netdev_tx(struct ieee80211_txb *txb, struct net_device *netdev, 744static void set_rx_filter_handler(struct work_struct *work)
1191 int pri)
1192{ 745{
1193 return zd_mac_tx(zd_netdev_mac(netdev), txb, pri); 746 struct zd_mac *mac =
747 container_of(work, struct zd_mac, set_rx_filter_work);
748 int r;
749
750 dev_dbg_f(zd_mac_dev(mac), "\n");
751 r = set_rx_filter(mac);
752 if (r)
753 dev_err(zd_mac_dev(mac), "set_rx_filter_handler error %d\n", r);
1194} 754}
1195 755
1196static void set_security(struct net_device *netdev, 756#define SUPPORTED_FIF_FLAGS \
1197 struct ieee80211_security *sec) 757 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
758 FIF_OTHER_BSS)
759static void zd_op_configure_filter(struct ieee80211_hw *hw,
760 unsigned int changed_flags,
761 unsigned int *new_flags,
762 int mc_count, struct dev_mc_list *mclist)
1198{ 763{
1199 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev); 764 struct zd_mc_hash hash;
1200 struct ieee80211_security *secinfo = &ieee->sec; 765 struct zd_mac *mac = zd_hw_mac(hw);
1201 int keyidx; 766 unsigned long flags;
1202 767 int i;
1203 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), "\n");
1204
1205 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
1206 if (sec->flags & (1<<keyidx)) {
1207 secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
1208 secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
1209 memcpy(secinfo->keys[keyidx], sec->keys[keyidx],
1210 SCM_KEY_LEN);
1211 }
1212 768
1213 if (sec->flags & SEC_ACTIVE_KEY) { 769 /* Only deal with supported flags */
1214 secinfo->active_key = sec->active_key; 770 changed_flags &= SUPPORTED_FIF_FLAGS;
1215 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), 771 *new_flags &= SUPPORTED_FIF_FLAGS;
1216 " .active_key = %d\n", sec->active_key); 772
1217 } 773 /* changed_flags is always populated but this driver
1218 if (sec->flags & SEC_UNICAST_GROUP) { 774 * doesn't support all FIF flags so its possible we don't
1219 secinfo->unicast_uses_group = sec->unicast_uses_group; 775 * need to do anything */
1220 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), 776 if (!changed_flags)
1221 " .unicast_uses_group = %d\n", 777 return;
1222 sec->unicast_uses_group); 778
1223 } 779 if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)) {
1224 if (sec->flags & SEC_LEVEL) { 780 zd_mc_add_all(&hash);
1225 secinfo->level = sec->level; 781 } else {
1226 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), 782 DECLARE_MAC_BUF(macbuf);
1227 " .level = %d\n", sec->level); 783
1228 } 784 zd_mc_clear(&hash);
1229 if (sec->flags & SEC_ENABLED) { 785 for (i = 0; i < mc_count; i++) {
1230 secinfo->enabled = sec->enabled; 786 if (!mclist)
1231 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), 787 break;
1232 " .enabled = %d\n", sec->enabled); 788 dev_dbg_f(zd_mac_dev(mac), "mc addr %s\n",
1233 } 789 print_mac(macbuf, mclist->dmi_addr));
1234 if (sec->flags & SEC_ENCRYPT) { 790 zd_mc_add_addr(&hash, mclist->dmi_addr);
1235 secinfo->encrypt = sec->encrypt; 791 mclist = mclist->next;
1236 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), 792 }
1237 " .encrypt = %d\n", sec->encrypt);
1238 }
1239 if (sec->flags & SEC_AUTH_MODE) {
1240 secinfo->auth_mode = sec->auth_mode;
1241 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
1242 " .auth_mode = %d\n", sec->auth_mode);
1243 } 793 }
794
795 spin_lock_irqsave(&mac->lock, flags);
796 mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
797 mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
798 mac->multicast_hash = hash;
799 spin_unlock_irqrestore(&mac->lock, flags);
800 queue_work(zd_workqueue, &mac->set_multicast_hash_work);
801
802 if (changed_flags & FIF_CONTROL)
803 queue_work(zd_workqueue, &mac->set_rx_filter_work);
804
805 /* no handling required for FIF_OTHER_BSS as we don't currently
806 * do BSSID filtering */
807 /* FIXME: in future it would be nice to enable the probe response
808 * filter (so that the driver doesn't see them) until
809 * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
810 * have to schedule work to enable prbresp reception, which might
811 * happen too late. For now we'll just listen and forward them all the
812 * time. */
1244} 813}
1245 814
1246static void ieee_init(struct ieee80211_device *ieee) 815static void set_rts_cts_work(struct work_struct *work)
1247{ 816{
1248 ieee->mode = IEEE_B | IEEE_G; 817 struct zd_mac *mac =
1249 ieee->freq_band = IEEE80211_24GHZ_BAND; 818 container_of(work, struct zd_mac, set_rts_cts_work);
1250 ieee->modulation = IEEE80211_OFDM_MODULATION | IEEE80211_CCK_MODULATION; 819 unsigned long flags;
1251 ieee->tx_headroom = sizeof(struct zd_ctrlset); 820 unsigned int short_preamble;
1252 ieee->set_security = set_security; 821
1253 ieee->hard_start_xmit = netdev_tx; 822 mutex_lock(&mac->chip.mutex);
1254 823
1255 /* Software encryption/decryption for now */ 824 spin_lock_irqsave(&mac->lock, flags);
1256 ieee->host_build_iv = 0; 825 mac->updating_rts_rate = 0;
1257 ieee->host_encrypt = 1; 826 short_preamble = mac->short_preamble;
1258 ieee->host_decrypt = 1; 827 spin_unlock_irqrestore(&mac->lock, flags);
1259 828
1260 /* FIXME: default to managed mode, until ieee80211 and zd1211rw can 829 zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble);
1261 * correctly support AUTO */ 830 mutex_unlock(&mac->chip.mutex);
1262 ieee->iw_mode = IW_MODE_INFRA;
1263} 831}
1264 832
1265static void softmac_init(struct ieee80211softmac_device *sm) 833static void zd_op_erp_ie_changed(struct ieee80211_hw *hw, u8 changes,
834 int cts_protection, int preamble)
1266{ 835{
1267 sm->set_channel = set_channel; 836 struct zd_mac *mac = zd_hw_mac(hw);
1268 sm->bssinfo_change = bssinfo_change; 837 unsigned long flags;
838
839 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
840
841 if (changes & IEEE80211_ERP_CHANGE_PREAMBLE) {
842 spin_lock_irqsave(&mac->lock, flags);
843 mac->short_preamble = !preamble;
844 if (!mac->updating_rts_rate) {
845 mac->updating_rts_rate = 1;
846 /* FIXME: should disable TX here, until work has
847 * completed and RTS_CTS reg is updated */
848 queue_work(zd_workqueue, &mac->set_rts_cts_work);
849 }
850 spin_unlock_irqrestore(&mac->lock, flags);
851 }
1269} 852}
1270 853
1271struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev) 854static const struct ieee80211_ops zd_ops = {
855 .tx = zd_op_tx,
856 .start = zd_op_start,
857 .stop = zd_op_stop,
858 .add_interface = zd_op_add_interface,
859 .remove_interface = zd_op_remove_interface,
860 .config = zd_op_config,
861 .config_interface = zd_op_config_interface,
862 .configure_filter = zd_op_configure_filter,
863 .erp_ie_changed = zd_op_erp_ie_changed,
864};
865
866struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
1272{ 867{
1273 struct zd_mac *mac = zd_netdev_mac(ndev); 868 struct zd_mac *mac;
1274 struct iw_statistics *iw_stats = &mac->iw_stats; 869 struct ieee80211_hw *hw;
1275 unsigned int i, count, qual_total, rssi_total; 870 int i;
1276 871
1277 memset(iw_stats, 0, sizeof(struct iw_statistics)); 872 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
1278 /* We are not setting the status, because ieee->state is not updated 873 if (!hw) {
1279 * at all and this driver doesn't track authentication state. 874 dev_dbg_f(&intf->dev, "out of memory\n");
1280 */ 875 return NULL;
1281 spin_lock_irq(&mac->lock);
1282 count = mac->stats_count < ZD_MAC_STATS_BUFFER_SIZE ?
1283 mac->stats_count : ZD_MAC_STATS_BUFFER_SIZE;
1284 qual_total = rssi_total = 0;
1285 for (i = 0; i < count; i++) {
1286 qual_total += mac->qual_buffer[i];
1287 rssi_total += mac->rssi_buffer[i];
1288 } 876 }
1289 spin_unlock_irq(&mac->lock); 877
1290 iw_stats->qual.updated = IW_QUAL_NOISE_INVALID; 878 mac = zd_hw_mac(hw);
1291 if (count > 0) { 879
1292 iw_stats->qual.qual = qual_total / count; 880 memset(mac, 0, sizeof(*mac));
1293 iw_stats->qual.level = rssi_total / count; 881 spin_lock_init(&mac->lock);
1294 iw_stats->qual.updated |= 882 mac->hw = hw;
1295 IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED; 883
1296 } else { 884 mac->type = IEEE80211_IF_TYPE_INVALID;
1297 iw_stats->qual.updated |= 885
1298 IW_QUAL_QUAL_INVALID|IW_QUAL_LEVEL_INVALID; 886 memcpy(mac->channels, zd_channels, sizeof(zd_channels));
887 memcpy(mac->rates, zd_rates, sizeof(zd_rates));
888 mac->modes[0].mode = MODE_IEEE80211G;
889 mac->modes[0].num_rates = ARRAY_SIZE(zd_rates);
890 mac->modes[0].rates = mac->rates;
891 mac->modes[0].num_channels = ARRAY_SIZE(zd_channels);
892 mac->modes[0].channels = mac->channels;
893 mac->modes[1].mode = MODE_IEEE80211B;
894 mac->modes[1].num_rates = 4;
895 mac->modes[1].rates = mac->rates;
896 mac->modes[1].num_channels = ARRAY_SIZE(zd_channels);
897 mac->modes[1].channels = mac->channels;
898
899 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
900 IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED;
901 hw->max_rssi = 100;
902 hw->max_signal = 100;
903
904 hw->queues = 1;
905 hw->extra_tx_headroom = sizeof(struct zd_ctrlset);
906
907 skb_queue_head_init(&mac->ack_wait_queue);
908
909 for (i = 0; i < 2; i++) {
910 if (ieee80211_register_hwmode(hw, &mac->modes[i])) {
911 dev_dbg_f(&intf->dev, "cannot register hwmode\n");
912 ieee80211_free_hw(hw);
913 return NULL;
914 }
1299 } 915 }
1300 /* TODO: update counter */ 916
1301 return iw_stats; 917 zd_chip_init(&mac->chip, hw, intf);
918 housekeeping_init(mac);
919 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
920 INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
921 INIT_WORK(&mac->set_rx_filter_work, set_rx_filter_handler);
922
923 SET_IEEE80211_DEV(hw, &intf->dev);
924 return hw;
1302} 925}
1303 926
1304#define LINK_LED_WORK_DELAY HZ 927#define LINK_LED_WORK_DELAY HZ
@@ -1308,18 +931,17 @@ static void link_led_handler(struct work_struct *work)
1308 struct zd_mac *mac = 931 struct zd_mac *mac =
1309 container_of(work, struct zd_mac, housekeeping.link_led_work.work); 932 container_of(work, struct zd_mac, housekeeping.link_led_work.work);
1310 struct zd_chip *chip = &mac->chip; 933 struct zd_chip *chip = &mac->chip;
1311 struct ieee80211softmac_device *sm = ieee80211_priv(mac->netdev);
1312 int is_associated; 934 int is_associated;
1313 int r; 935 int r;
1314 936
1315 spin_lock_irq(&mac->lock); 937 spin_lock_irq(&mac->lock);
1316 is_associated = sm->associnfo.associated != 0; 938 is_associated = mac->associated;
1317 spin_unlock_irq(&mac->lock); 939 spin_unlock_irq(&mac->lock);
1318 940
1319 r = zd_chip_control_leds(chip, 941 r = zd_chip_control_leds(chip,
1320 is_associated ? LED_ASSOCIATED : LED_SCANNING); 942 is_associated ? LED_ASSOCIATED : LED_SCANNING);
1321 if (r) 943 if (r)
1322 dev_err(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r); 944 dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
1323 945
1324 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work, 946 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1325 LINK_LED_WORK_DELAY); 947 LINK_LED_WORK_DELAY);