blob: 49ab3c35710076647c85b69e9dc33c888ab2d822 [file] [log] [blame]
Daniel Drake66bb42f2007-11-19 16:20:12 +00001/* ZD1211 USB-WLAN driver for Linux
Daniel Drakee85d0912006-06-02 17:11:32 +01002 *
Daniel Drake66bb42f2007-11-19 16:20:12 +00003 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
5 * Copyright (C) 2006-2007 Michael Wu <flamingice@sourmilk.net>
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -07006 * Copyright (C) 2007-2008 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
Daniel Drake459c51a2007-11-19 15:00:29 +00007 *
Daniel Drakee85d0912006-06-02 17:11:32 +01008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/netdevice.h>
24#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Daniel Drakee85d0912006-06-02 17:11:32 +010026#include <linux/usb.h>
27#include <linux/jiffies.h>
28#include <net/ieee80211_radiotap.h>
29
30#include "zd_def.h"
31#include "zd_chip.h"
32#include "zd_mac.h"
Daniel Drakee85d0912006-06-02 17:11:32 +010033#include "zd_rf.h"
Daniel Drakee85d0912006-06-02 17:11:32 +010034
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -070035struct zd_reg_alpha2_map {
36 u32 reg;
37 char alpha2[2];
38};
39
40static struct zd_reg_alpha2_map reg_alpha2_map[] = {
41 { ZD_REGDOMAIN_FCC, "US" },
42 { ZD_REGDOMAIN_IC, "CA" },
43 { ZD_REGDOMAIN_ETSI, "DE" }, /* Generic ETSI, use most restrictive */
44 { ZD_REGDOMAIN_JAPAN, "JP" },
John W. Linville3d3b33b2010-06-16 14:41:36 -040045 { ZD_REGDOMAIN_JAPAN_2, "JP" },
46 { ZD_REGDOMAIN_JAPAN_3, "JP" },
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -070047 { ZD_REGDOMAIN_SPAIN, "ES" },
48 { ZD_REGDOMAIN_FRANCE, "FR" },
49};
50
Daniel Drake459c51a2007-11-19 15:00:29 +000051/* This table contains the hardware specific values for the modulation rates. */
52static const struct ieee80211_rate zd_rates[] = {
Johannes Berg8318d782008-01-24 19:38:38 +010053 { .bitrate = 10,
54 .hw_value = ZD_CCK_RATE_1M, },
55 { .bitrate = 20,
56 .hw_value = ZD_CCK_RATE_2M,
57 .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT,
58 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
59 { .bitrate = 55,
60 .hw_value = ZD_CCK_RATE_5_5M,
61 .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT,
62 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
63 { .bitrate = 110,
64 .hw_value = ZD_CCK_RATE_11M,
65 .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT,
66 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
67 { .bitrate = 60,
68 .hw_value = ZD_OFDM_RATE_6M,
69 .flags = 0 },
70 { .bitrate = 90,
71 .hw_value = ZD_OFDM_RATE_9M,
72 .flags = 0 },
73 { .bitrate = 120,
74 .hw_value = ZD_OFDM_RATE_12M,
75 .flags = 0 },
76 { .bitrate = 180,
77 .hw_value = ZD_OFDM_RATE_18M,
78 .flags = 0 },
79 { .bitrate = 240,
80 .hw_value = ZD_OFDM_RATE_24M,
81 .flags = 0 },
82 { .bitrate = 360,
83 .hw_value = ZD_OFDM_RATE_36M,
84 .flags = 0 },
85 { .bitrate = 480,
86 .hw_value = ZD_OFDM_RATE_48M,
87 .flags = 0 },
88 { .bitrate = 540,
89 .hw_value = ZD_OFDM_RATE_54M,
90 .flags = 0 },
Daniel Drake459c51a2007-11-19 15:00:29 +000091};
92
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +020093/*
94 * Zydas retry rates table. Each line is listed in the same order as
95 * in zd_rates[] and contains all the rate used when a packet is sent
96 * starting with a given rates. Let's consider an example :
97 *
98 * "11 Mbits : 4, 3, 2, 1, 0" means :
99 * - packet is sent using 4 different rates
100 * - 1st rate is index 3 (ie 11 Mbits)
101 * - 2nd rate is index 2 (ie 5.5 Mbits)
102 * - 3rd rate is index 1 (ie 2 Mbits)
103 * - 4th rate is index 0 (ie 1 Mbits)
104 */
105
106static const struct tx_retry_rate zd_retry_rates[] = {
107 { /* 1 Mbits */ 1, { 0 }},
108 { /* 2 Mbits */ 2, { 1, 0 }},
109 { /* 5.5 Mbits */ 3, { 2, 1, 0 }},
110 { /* 11 Mbits */ 4, { 3, 2, 1, 0 }},
111 { /* 6 Mbits */ 5, { 4, 3, 2, 1, 0 }},
112 { /* 9 Mbits */ 6, { 5, 4, 3, 2, 1, 0}},
113 { /* 12 Mbits */ 5, { 6, 3, 2, 1, 0 }},
114 { /* 18 Mbits */ 6, { 7, 6, 3, 2, 1, 0 }},
115 { /* 24 Mbits */ 6, { 8, 6, 3, 2, 1, 0 }},
116 { /* 36 Mbits */ 7, { 9, 8, 6, 3, 2, 1, 0 }},
117 { /* 48 Mbits */ 8, {10, 9, 8, 6, 3, 2, 1, 0 }},
118 { /* 54 Mbits */ 9, {11, 10, 9, 8, 6, 3, 2, 1, 0 }}
119};
120
Daniel Drake459c51a2007-11-19 15:00:29 +0000121static const struct ieee80211_channel zd_channels[] = {
Johannes Berg8318d782008-01-24 19:38:38 +0100122 { .center_freq = 2412, .hw_value = 1 },
123 { .center_freq = 2417, .hw_value = 2 },
124 { .center_freq = 2422, .hw_value = 3 },
125 { .center_freq = 2427, .hw_value = 4 },
126 { .center_freq = 2432, .hw_value = 5 },
127 { .center_freq = 2437, .hw_value = 6 },
128 { .center_freq = 2442, .hw_value = 7 },
129 { .center_freq = 2447, .hw_value = 8 },
130 { .center_freq = 2452, .hw_value = 9 },
131 { .center_freq = 2457, .hw_value = 10 },
132 { .center_freq = 2462, .hw_value = 11 },
133 { .center_freq = 2467, .hw_value = 12 },
134 { .center_freq = 2472, .hw_value = 13 },
135 { .center_freq = 2484, .hw_value = 14 },
Daniel Drake459c51a2007-11-19 15:00:29 +0000136};
Daniel Drakee85d0912006-06-02 17:11:32 +0100137
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100138static void housekeeping_init(struct zd_mac *mac);
139static void housekeeping_enable(struct zd_mac *mac);
140static void housekeeping_disable(struct zd_mac *mac);
141
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700142static int zd_reg2alpha2(u8 regdomain, char *alpha2)
143{
144 unsigned int i;
145 struct zd_reg_alpha2_map *reg_map;
146 for (i = 0; i < ARRAY_SIZE(reg_alpha2_map); i++) {
147 reg_map = &reg_alpha2_map[i];
148 if (regdomain == reg_map->reg) {
149 alpha2[0] = reg_map->alpha2[0];
150 alpha2[1] = reg_map->alpha2[1];
151 return 0;
152 }
153 }
154 return 1;
155}
156
Daniel Drake459c51a2007-11-19 15:00:29 +0000157int zd_mac_preinit_hw(struct ieee80211_hw *hw)
Daniel Drake74553ae2007-07-01 18:22:32 +0100158{
159 int r;
160 u8 addr[ETH_ALEN];
Daniel Drake459c51a2007-11-19 15:00:29 +0000161 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drake74553ae2007-07-01 18:22:32 +0100162
163 r = zd_chip_read_mac_addr_fw(&mac->chip, addr);
164 if (r)
165 return r;
166
Daniel Drake459c51a2007-11-19 15:00:29 +0000167 SET_IEEE80211_PERM_ADDR(hw, addr);
168
Daniel Drake74553ae2007-07-01 18:22:32 +0100169 return 0;
170}
171
Daniel Drake459c51a2007-11-19 15:00:29 +0000172int zd_mac_init_hw(struct ieee80211_hw *hw)
Daniel Drakee85d0912006-06-02 17:11:32 +0100173{
174 int r;
Daniel Drake459c51a2007-11-19 15:00:29 +0000175 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100176 struct zd_chip *chip = &mac->chip;
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700177 char alpha2[2];
Daniel Drakee85d0912006-06-02 17:11:32 +0100178 u8 default_regdomain;
179
180 r = zd_chip_enable_int(chip);
181 if (r)
182 goto out;
Daniel Drake74553ae2007-07-01 18:22:32 +0100183 r = zd_chip_init_hw(chip);
Daniel Drakee85d0912006-06-02 17:11:32 +0100184 if (r)
185 goto disable_int;
186
Daniel Drakee85d0912006-06-02 17:11:32 +0100187 ZD_ASSERT(!irqs_disabled());
Daniel Drakee85d0912006-06-02 17:11:32 +0100188
189 r = zd_read_regdomain(chip, &default_regdomain);
190 if (r)
191 goto disable_int;
Daniel Drakee85d0912006-06-02 17:11:32 +0100192 spin_lock_irq(&mac->lock);
193 mac->regdomain = mac->default_regdomain = default_regdomain;
194 spin_unlock_irq(&mac->lock);
Daniel Drakee85d0912006-06-02 17:11:32 +0100195
Daniel Drake40da08b2006-08-01 23:43:32 +0200196 /* We must inform the device that we are doing encryption/decryption in
197 * software at the moment. */
198 r = zd_set_encryption_type(chip, ENC_SNIFFER);
Daniel Drakee85d0912006-06-02 17:11:32 +0100199 if (r)
200 goto disable_int;
201
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700202 r = zd_reg2alpha2(mac->regdomain, alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -0500203 if (r)
204 goto disable_int;
Daniel Drakee85d0912006-06-02 17:11:32 +0100205
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -0500206 r = regulatory_hint(hw->wiphy, alpha2);
Daniel Drakee85d0912006-06-02 17:11:32 +0100207disable_int:
208 zd_chip_disable_int(chip);
209out:
210 return r;
211}
212
213void zd_mac_clear(struct zd_mac *mac)
214{
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000215 flush_workqueue(zd_workqueue);
Daniel Drakee85d0912006-06-02 17:11:32 +0100216 zd_chip_clear(&mac->chip);
Ulrich Kunitzc48cf122006-08-12 18:00:17 +0100217 ZD_ASSERT(!spin_is_locked(&mac->lock));
218 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
Daniel Drakee85d0912006-06-02 17:11:32 +0100219}
220
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100221static int set_rx_filter(struct zd_mac *mac)
Daniel Drakee85d0912006-06-02 17:11:32 +0100222{
Daniel Drake459c51a2007-11-19 15:00:29 +0000223 unsigned long flags;
224 u32 filter = STA_RX_FILTER;
Daniel Drakee85d0912006-06-02 17:11:32 +0100225
Daniel Drake459c51a2007-11-19 15:00:29 +0000226 spin_lock_irqsave(&mac->lock, flags);
227 if (mac->pass_ctrl)
228 filter |= RX_FILTER_CTRL;
229 spin_unlock_irqrestore(&mac->lock, flags);
230
231 return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100232}
233
Jussi Kivilinnac2fadcb2011-01-31 20:48:06 +0200234static int set_mac_and_bssid(struct zd_mac *mac)
235{
236 int r;
237
238 if (!mac->vif)
239 return -1;
240
241 r = zd_write_mac_addr(&mac->chip, mac->vif->addr);
242 if (r)
243 return r;
244
245 /* Vendor driver after setting MAC either sets BSSID for AP or
246 * filter for other modes.
247 */
248 if (mac->type != NL80211_IFTYPE_AP)
249 return set_rx_filter(mac);
250 else
251 return zd_write_bssid(&mac->chip, mac->vif->addr);
252}
253
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100254static int set_mc_hash(struct zd_mac *mac)
255{
256 struct zd_mc_hash hash;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100257 zd_mc_clear(&hash);
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100258 return zd_chip_set_multicast_hash(&mac->chip, &hash);
259}
260
Daniel Drake459c51a2007-11-19 15:00:29 +0000261static int zd_op_start(struct ieee80211_hw *hw)
Daniel Drakee85d0912006-06-02 17:11:32 +0100262{
Daniel Drake459c51a2007-11-19 15:00:29 +0000263 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100264 struct zd_chip *chip = &mac->chip;
Daniel Drake74553ae2007-07-01 18:22:32 +0100265 struct zd_usb *usb = &chip->usb;
Daniel Drakee85d0912006-06-02 17:11:32 +0100266 int r;
267
Daniel Drake74553ae2007-07-01 18:22:32 +0100268 if (!usb->initialized) {
269 r = zd_usb_init_hw(usb);
270 if (r)
271 goto out;
272 }
273
Daniel Drakee85d0912006-06-02 17:11:32 +0100274 r = zd_chip_enable_int(chip);
275 if (r < 0)
276 goto out;
277
278 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
279 if (r < 0)
280 goto disable_int;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100281 r = set_rx_filter(mac);
282 if (r)
283 goto disable_int;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100284 r = set_mc_hash(mac);
Daniel Drakee85d0912006-06-02 17:11:32 +0100285 if (r)
286 goto disable_int;
287 r = zd_chip_switch_radio_on(chip);
288 if (r < 0)
289 goto disable_int;
Daniel Drake459c51a2007-11-19 15:00:29 +0000290 r = zd_chip_enable_rxtx(chip);
Daniel Drakee85d0912006-06-02 17:11:32 +0100291 if (r < 0)
292 goto disable_radio;
293 r = zd_chip_enable_hwint(chip);
294 if (r < 0)
Daniel Drake459c51a2007-11-19 15:00:29 +0000295 goto disable_rxtx;
Daniel Drakee85d0912006-06-02 17:11:32 +0100296
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100297 housekeeping_enable(mac);
Daniel Drakee85d0912006-06-02 17:11:32 +0100298 return 0;
Daniel Drake459c51a2007-11-19 15:00:29 +0000299disable_rxtx:
300 zd_chip_disable_rxtx(chip);
Daniel Drakee85d0912006-06-02 17:11:32 +0100301disable_radio:
302 zd_chip_switch_radio_off(chip);
303disable_int:
304 zd_chip_disable_int(chip);
305out:
306 return r;
307}
308
Daniel Drake459c51a2007-11-19 15:00:29 +0000309static void zd_op_stop(struct ieee80211_hw *hw)
310{
311 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100312 struct zd_chip *chip = &mac->chip;
Daniel Drake459c51a2007-11-19 15:00:29 +0000313 struct sk_buff *skb;
314 struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue;
Daniel Drakee85d0912006-06-02 17:11:32 +0100315
Daniel Drake459c51a2007-11-19 15:00:29 +0000316 /* The order here deliberately is a little different from the open()
Daniel Drakee85d0912006-06-02 17:11:32 +0100317 * method, since we need to make sure there is no opportunity for RX
Daniel Drake459c51a2007-11-19 15:00:29 +0000318 * frames to be processed by mac80211 after we have stopped it.
Daniel Drakee85d0912006-06-02 17:11:32 +0100319 */
320
Daniel Drake459c51a2007-11-19 15:00:29 +0000321 zd_chip_disable_rxtx(chip);
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100322 housekeeping_disable(mac);
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000323 flush_workqueue(zd_workqueue);
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000324
Daniel Drakee85d0912006-06-02 17:11:32 +0100325 zd_chip_disable_hwint(chip);
326 zd_chip_switch_radio_off(chip);
327 zd_chip_disable_int(chip);
328
Daniel Drake459c51a2007-11-19 15:00:29 +0000329
330 while ((skb = skb_dequeue(ack_wait_queue)))
Johannes Berge039fa42008-05-15 12:55:29 +0200331 dev_kfree_skb_any(skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100332}
333
Daniel Drake459c51a2007-11-19 15:00:29 +0000334/**
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200335 * zd_mac_tx_status - reports tx status of a packet if required
Daniel Drake459c51a2007-11-19 15:00:29 +0000336 * @hw - a &struct ieee80211_hw pointer
337 * @skb - a sk-buffer
Johannes Berge039fa42008-05-15 12:55:29 +0200338 * @flags: extra flags to set in the TX status info
339 * @ackssi: ACK signal strength
Coly Li73ac36e2009-01-07 18:09:16 -0800340 * @success - True for successful transmission of the frame
Daniel Drake459c51a2007-11-19 15:00:29 +0000341 *
342 * This information calls ieee80211_tx_status_irqsafe() if required by the
343 * control information. It copies the control information into the status
344 * information.
345 *
346 * If no status information has been requested, the skb is freed.
347 */
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200348static void zd_mac_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
349 int ackssi, struct tx_status *tx_status)
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000350{
Johannes Berge039fa42008-05-15 12:55:29 +0200351 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200352 int i;
353 int success = 1, retry = 1;
354 int first_idx;
355 const struct tx_retry_rate *retries;
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000356
Johannes Berge6a98542008-10-21 12:40:02 +0200357 ieee80211_tx_info_clear_status(info);
Johannes Berge039fa42008-05-15 12:55:29 +0200358
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200359 if (tx_status) {
360 success = !tx_status->failure;
361 retry = tx_status->retry + success;
362 }
363
364 if (success) {
365 /* success */
Johannes Berge6a98542008-10-21 12:40:02 +0200366 info->flags |= IEEE80211_TX_STAT_ACK;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200367 } else {
368 /* failure */
369 info->flags &= ~IEEE80211_TX_STAT_ACK;
370 }
371
372 first_idx = info->status.rates[0].idx;
373 ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
374 retries = &zd_retry_rates[first_idx];
Dan Carpenter86baf712010-02-27 09:12:34 +0300375 ZD_ASSERT(1 <= retry && retry <= retries->count);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200376
377 info->status.rates[0].idx = retries->rate[0];
378 info->status.rates[0].count = 1; // (retry > 1 ? 2 : 1);
379
380 for (i=1; i<IEEE80211_TX_MAX_RATES-1 && i<retry; i++) {
381 info->status.rates[i].idx = retries->rate[i];
382 info->status.rates[i].count = 1; // ((i==retry-1) && success ? 1:2);
383 }
384 for (; i<IEEE80211_TX_MAX_RATES && i<retry; i++) {
Dan Carpenter86baf712010-02-27 09:12:34 +0300385 info->status.rates[i].idx = retries->rate[retry - 1];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200386 info->status.rates[i].count = 1; // (success ? 1:2);
387 }
388 if (i<IEEE80211_TX_MAX_RATES)
389 info->status.rates[i].idx = -1; /* terminate */
390
Johannes Berge039fa42008-05-15 12:55:29 +0200391 info->status.ack_signal = ackssi;
392 ieee80211_tx_status_irqsafe(hw, skb);
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000393}
394
Daniel Drake459c51a2007-11-19 15:00:29 +0000395/**
396 * zd_mac_tx_failed - callback for failed frames
397 * @dev: the mac80211 wireless device
398 *
Adam Buchbinder303863f2009-12-11 16:35:37 -0500399 * This function is called if a frame couldn't be successfully
Daniel Drake459c51a2007-11-19 15:00:29 +0000400 * transferred. The first frame from the tx queue, will be selected and
401 * reported as error to the upper layers.
402 */
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200403void zd_mac_tx_failed(struct urb *urb)
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000404{
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200405 struct ieee80211_hw * hw = zd_usb_to_hw(urb->context);
406 struct zd_mac *mac = zd_hw_mac(hw);
407 struct sk_buff_head *q = &mac->ack_wait_queue;
Daniel Drake459c51a2007-11-19 15:00:29 +0000408 struct sk_buff *skb;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200409 struct tx_status *tx_status = (struct tx_status *)urb->transfer_buffer;
410 unsigned long flags;
411 int success = !tx_status->failure;
412 int retry = tx_status->retry + success;
413 int found = 0;
414 int i, position = 0;
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000415
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200416 q = &mac->ack_wait_queue;
417 spin_lock_irqsave(&q->lock, flags);
Johannes Berg5078ed52008-02-20 12:09:25 +0100418
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200419 skb_queue_walk(q, skb) {
420 struct ieee80211_hdr *tx_hdr;
421 struct ieee80211_tx_info *info;
422 int first_idx, final_idx;
423 const struct tx_retry_rate *retries;
424 u8 final_rate;
425
426 position ++;
427
428 /* if the hardware reports a failure and we had a 802.11 ACK
429 * pending, then we skip the first skb when searching for a
430 * matching frame */
431 if (tx_status->failure && mac->ack_pending &&
432 skb_queue_is_first(q, skb)) {
433 continue;
434 }
435
436 tx_hdr = (struct ieee80211_hdr *)skb->data;
437
438 /* we skip all frames not matching the reported destination */
439 if (unlikely(memcmp(tx_hdr->addr1, tx_status->mac, ETH_ALEN))) {
440 continue;
441 }
442
443 /* we skip all frames not matching the reported final rate */
444
445 info = IEEE80211_SKB_CB(skb);
446 first_idx = info->status.rates[0].idx;
447 ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
448 retries = &zd_retry_rates[first_idx];
Dan Carpenter86baf712010-02-27 09:12:34 +0300449 if (retry <= 0 || retry > retries->count)
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200450 continue;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200451
Dan Carpenter86baf712010-02-27 09:12:34 +0300452 final_idx = retries->rate[retry - 1];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200453 final_rate = zd_rates[final_idx].hw_value;
454
455 if (final_rate != tx_status->rate) {
456 continue;
457 }
458
459 found = 1;
460 break;
461 }
462
463 if (found) {
464 for (i=1; i<=position; i++) {
465 skb = __skb_dequeue(q);
466 zd_mac_tx_status(hw, skb,
467 mac->ack_pending ? mac->ack_signal : 0,
468 i == position ? tx_status : NULL);
469 mac->ack_pending = 0;
470 }
471 }
472
473 spin_unlock_irqrestore(&q->lock, flags);
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000474}
475
Daniel Drake459c51a2007-11-19 15:00:29 +0000476/**
477 * zd_mac_tx_to_dev - callback for USB layer
478 * @skb: a &sk_buff pointer
479 * @error: error value, 0 if transmission successful
480 *
481 * Informs the MAC layer that the frame has successfully transferred to the
482 * device. If an ACK is required and the transfer to the device has been
483 * successful, the packets are put on the @ack_wait_queue with
484 * the control set removed.
485 */
486void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
Daniel Drakee85d0912006-06-02 17:11:32 +0100487{
Johannes Berge039fa42008-05-15 12:55:29 +0200488 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200489 struct ieee80211_hw *hw = info->rate_driver_data[0];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200490 struct zd_mac *mac = zd_hw_mac(hw);
491
492 ieee80211_tx_info_clear_status(info);
Daniel Drakee85d0912006-06-02 17:11:32 +0100493
Johannes Berge039fa42008-05-15 12:55:29 +0200494 skb_pull(skb, sizeof(struct zd_ctrlset));
495 if (unlikely(error ||
496 (info->flags & IEEE80211_TX_CTL_NO_ACK))) {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200497 /*
498 * FIXME : do we need to fill in anything ?
499 */
500 ieee80211_tx_status_irqsafe(hw, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000501 } else {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200502 struct sk_buff_head *q = &mac->ack_wait_queue;
Johannes Berge039fa42008-05-15 12:55:29 +0200503
504 skb_queue_tail(q, skb);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200505 while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) {
506 zd_mac_tx_status(hw, skb_dequeue(q),
507 mac->ack_pending ? mac->ack_signal : 0,
508 NULL);
509 mac->ack_pending = 0;
510 }
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000511 }
Daniel Drakee85d0912006-06-02 17:11:32 +0100512}
513
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000514static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
Daniel Drakee85d0912006-06-02 17:11:32 +0100515{
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100516 /* ZD_PURE_RATE() must be used to remove the modulation type flag of
Daniel Drake459c51a2007-11-19 15:00:29 +0000517 * the zd-rate values.
518 */
Daniel Drakee85d0912006-06-02 17:11:32 +0100519 static const u8 rate_divisor[] = {
Daniel Drake459c51a2007-11-19 15:00:29 +0000520 [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1,
521 [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2,
522 /* Bits must be doubled. */
523 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11,
524 [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11,
525 [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6,
526 [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9,
527 [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12,
528 [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18,
529 [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24,
530 [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36,
531 [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
532 [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
Daniel Drakee85d0912006-06-02 17:11:32 +0100533 };
534
535 u32 bits = (u32)tx_length * 8;
536 u32 divisor;
537
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100538 divisor = rate_divisor[ZD_PURE_RATE(zd_rate)];
Daniel Drakee85d0912006-06-02 17:11:32 +0100539 if (divisor == 0)
540 return -EINVAL;
541
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000542 switch (zd_rate) {
543 case ZD_CCK_RATE_5_5M:
Daniel Drakee85d0912006-06-02 17:11:32 +0100544 bits = (2*bits) + 10; /* round up to the next integer */
545 break;
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000546 case ZD_CCK_RATE_11M:
Daniel Drakee85d0912006-06-02 17:11:32 +0100547 if (service) {
548 u32 t = bits % 11;
549 *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
550 if (0 < t && t <= 3) {
551 *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
552 }
553 }
554 bits += 10; /* round up to the next integer */
555 break;
556 }
557
558 return bits/divisor;
559}
560
Daniel Drakee85d0912006-06-02 17:11:32 +0100561static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
Johannes Berge6a98542008-10-21 12:40:02 +0200562 struct ieee80211_hdr *header,
563 struct ieee80211_tx_info *info)
Daniel Drakee85d0912006-06-02 17:11:32 +0100564{
Daniel Drakee85d0912006-06-02 17:11:32 +0100565 /*
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000566 * CONTROL TODO:
Daniel Drakee85d0912006-06-02 17:11:32 +0100567 * - if backoff needed, enable bit 0
568 * - if burst (backoff not needed) disable bit 0
Daniel Drakee85d0912006-06-02 17:11:32 +0100569 */
570
571 cs->control = 0;
572
573 /* First fragment */
Johannes Berge6a98542008-10-21 12:40:02 +0200574 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Daniel Drakee85d0912006-06-02 17:11:32 +0100575 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
576
Gábor Stefanik13bdcd92009-05-14 17:34:59 +0000577 /* No ACK expected (multicast, etc.) */
578 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
579 cs->control |= ZD_CS_NO_ACK;
Daniel Drakee85d0912006-06-02 17:11:32 +0100580
581 /* PS-POLL */
Harvey Harrison85365822008-06-14 23:33:39 -0700582 if (ieee80211_is_pspoll(header->frame_control))
Daniel Drakee85d0912006-06-02 17:11:32 +0100583 cs->control |= ZD_CS_PS_POLL_FRAME;
584
Johannes Berge6a98542008-10-21 12:40:02 +0200585 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000586 cs->control |= ZD_CS_RTS;
587
Johannes Berge6a98542008-10-21 12:40:02 +0200588 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000589 cs->control |= ZD_CS_SELF_CTS;
Daniel Drakee85d0912006-06-02 17:11:32 +0100590
591 /* FIXME: Management frame? */
592}
593
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100594static int zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon)
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800595{
596 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100597 int r;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800598 u32 tmp, j = 0;
599 /* 4 more bytes for tail CRC */
600 u32 full_len = beacon->len + 4;
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100601
602 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 0);
603 if (r < 0)
604 return r;
605 r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
606 if (r < 0)
607 return r;
608
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800609 while (tmp & 0x2) {
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100610 r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
611 if (r < 0)
612 return r;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800613 if ((++j % 100) == 0) {
614 printk(KERN_ERR "CR_BCN_FIFO_SEMAPHORE not ready\n");
615 if (j >= 500) {
616 printk(KERN_ERR "Giving up beacon config.\n");
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100617 return -ETIMEDOUT;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800618 }
619 }
620 msleep(1);
621 }
622
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100623 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, full_len - 1);
624 if (r < 0)
625 return r;
626 if (zd_chip_is_zd1211b(&mac->chip)) {
627 r = zd_iowrite32(&mac->chip, CR_BCN_LENGTH, full_len - 1);
628 if (r < 0)
629 return r;
630 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800631
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100632 for (j = 0 ; j < beacon->len; j++) {
633 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO,
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800634 *((u8 *)(beacon->data + j)));
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100635 if (r < 0)
636 return r;
637 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800638
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100639 for (j = 0; j < 4; j++) {
640 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, 0x0);
641 if (r < 0)
642 return r;
643 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800644
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100645 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 1);
646 if (r < 0)
647 return r;
648
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800649 /* 802.11b/g 2.4G CCK 1Mb
650 * 802.11a, not yet implemented, uses different values (see GPL vendor
651 * driver)
652 */
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100653 return zd_iowrite32(&mac->chip, CR_BCN_PLCP_CFG, 0x00000400 |
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800654 (full_len << 19));
655}
656
Daniel Drakee85d0912006-06-02 17:11:32 +0100657static int fill_ctrlset(struct zd_mac *mac,
Johannes Berge039fa42008-05-15 12:55:29 +0200658 struct sk_buff *skb)
Daniel Drakee85d0912006-06-02 17:11:32 +0100659{
660 int r;
Daniel Drake459c51a2007-11-19 15:00:29 +0000661 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
662 unsigned int frag_len = skb->len + FCS_LEN;
Daniel Drakee85d0912006-06-02 17:11:32 +0100663 unsigned int packet_length;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200664 struct ieee80211_rate *txrate;
Daniel Drakee85d0912006-06-02 17:11:32 +0100665 struct zd_ctrlset *cs = (struct zd_ctrlset *)
666 skb_push(skb, sizeof(struct zd_ctrlset));
Johannes Berge039fa42008-05-15 12:55:29 +0200667 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100668
Daniel Drakee85d0912006-06-02 17:11:32 +0100669 ZD_ASSERT(frag_len <= 0xffff);
Daniel Drakee85d0912006-06-02 17:11:32 +0100670
Johannes Berge039fa42008-05-15 12:55:29 +0200671 txrate = ieee80211_get_tx_rate(mac->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200672
673 cs->modulation = txrate->hw_value;
Johannes Berge6a98542008-10-21 12:40:02 +0200674 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200675 cs->modulation = txrate->hw_value_short;
Daniel Drakee85d0912006-06-02 17:11:32 +0100676
677 cs->tx_length = cpu_to_le16(frag_len);
678
Johannes Berge6a98542008-10-21 12:40:02 +0200679 cs_set_control(mac, cs, hdr, info);
Daniel Drakee85d0912006-06-02 17:11:32 +0100680
681 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
682 ZD_ASSERT(packet_length <= 0xffff);
683 /* ZD1211B: Computing the length difference this way, gives us
684 * flexibility to compute the packet length.
685 */
Daniel Drake74553ae2007-07-01 18:22:32 +0100686 cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ?
Daniel Drakee85d0912006-06-02 17:11:32 +0100687 packet_length - frag_len : packet_length);
688
689 /*
690 * CURRENT LENGTH:
691 * - transmit frame length in microseconds
692 * - seems to be derived from frame length
693 * - see Cal_Us_Service() in zdinlinef.h
694 * - if macp->bTxBurstEnable is enabled, then multiply by 4
695 * - bTxBurstEnable is never set in the vendor driver
696 *
697 * SERVICE:
698 * - "for PLCP configuration"
699 * - always 0 except in some situations at 802.11b 11M
700 * - see line 53 of zdinlinef.h
701 */
702 cs->service = 0;
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100703 r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation),
Daniel Drakee85d0912006-06-02 17:11:32 +0100704 le16_to_cpu(cs->tx_length));
705 if (r < 0)
706 return r;
707 cs->current_length = cpu_to_le16(r);
Daniel Drake459c51a2007-11-19 15:00:29 +0000708 cs->next_frame_length = 0;
Daniel Drakee85d0912006-06-02 17:11:32 +0100709
710 return 0;
711}
712
Daniel Drake459c51a2007-11-19 15:00:29 +0000713/**
714 * zd_op_tx - transmits a network frame to the device
Ulrich Kunitz741fec52006-11-22 00:05:53 +0000715 *
Daniel Drake459c51a2007-11-19 15:00:29 +0000716 * @dev: mac80211 hardware device
717 * @skb: socket buffer
718 * @control: the control structure
Daniel Drakee85d0912006-06-02 17:11:32 +0100719 *
Daniel Drake459c51a2007-11-19 15:00:29 +0000720 * This function transmit an IEEE 802.11 network frame to the device. The
721 * control block of the skbuff will be initialized. If necessary the incoming
722 * mac80211 queues will be stopped.
Daniel Drakee85d0912006-06-02 17:11:32 +0100723 */
Johannes Berge039fa42008-05-15 12:55:29 +0200724static int zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Daniel Drakee85d0912006-06-02 17:11:32 +0100725{
Daniel Drake459c51a2007-11-19 15:00:29 +0000726 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200727 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000728 int r;
Daniel Drakee85d0912006-06-02 17:11:32 +0100729
Johannes Berge039fa42008-05-15 12:55:29 +0200730 r = fill_ctrlset(mac, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000731 if (r)
Jouni Malinen640c65e2009-03-16 21:47:33 +0200732 goto fail;
Daniel Drakee85d0912006-06-02 17:11:32 +0100733
Johannes Berge6a98542008-10-21 12:40:02 +0200734 info->rate_driver_data[0] = hw;
Johannes Berge039fa42008-05-15 12:55:29 +0200735
736 r = zd_usb_tx(&mac->chip.usb, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000737 if (r)
Jouni Malinen640c65e2009-03-16 21:47:33 +0200738 goto fail;
739 return 0;
740
741fail:
742 dev_kfree_skb(skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000743 return 0;
744}
745
746/**
747 * filter_ack - filters incoming packets for acknowledgements
748 * @dev: the mac80211 device
749 * @rx_hdr: received header
750 * @stats: the status for the received packet
751 *
752 * This functions looks for ACK packets and tries to match them with the
753 * frames in the tx queue. If a match is found the frame will be dequeued and
754 * the upper layers is informed about the successful transmission. If
755 * mac80211 queues have been stopped and the number of frames still to be
756 * transmitted is low the queues will be opened again.
757 *
758 * Returns 1 if the frame was an ACK, 0 if it was ignored.
759 */
760static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
761 struct ieee80211_rx_status *stats)
762{
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200763 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drake459c51a2007-11-19 15:00:29 +0000764 struct sk_buff *skb;
765 struct sk_buff_head *q;
766 unsigned long flags;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200767 int found = 0;
768 int i, position = 0;
Daniel Drake459c51a2007-11-19 15:00:29 +0000769
Harvey Harrison85365822008-06-14 23:33:39 -0700770 if (!ieee80211_is_ack(rx_hdr->frame_control))
Daniel Drake459c51a2007-11-19 15:00:29 +0000771 return 0;
772
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200773 q = &mac->ack_wait_queue;
Daniel Drake459c51a2007-11-19 15:00:29 +0000774 spin_lock_irqsave(&q->lock, flags);
David S. Miller47a227d2008-09-23 00:23:30 -0700775 skb_queue_walk(q, skb) {
Daniel Drake459c51a2007-11-19 15:00:29 +0000776 struct ieee80211_hdr *tx_hdr;
777
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200778 position ++;
779
780 if (mac->ack_pending && skb_queue_is_first(q, skb))
781 continue;
782
Daniel Drake459c51a2007-11-19 15:00:29 +0000783 tx_hdr = (struct ieee80211_hdr *)skb->data;
Shaddy Baddahcde69012008-11-28 17:10:45 +1100784 if (likely(!memcmp(tx_hdr->addr2, rx_hdr->addr1, ETH_ALEN)))
Daniel Drake459c51a2007-11-19 15:00:29 +0000785 {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200786 found = 1;
787 break;
Daniel Drake459c51a2007-11-19 15:00:29 +0000788 }
789 }
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200790
791 if (found) {
792 for (i=1; i<position; i++) {
793 skb = __skb_dequeue(q);
794 zd_mac_tx_status(hw, skb,
795 mac->ack_pending ? mac->ack_signal : 0,
796 NULL);
797 mac->ack_pending = 0;
798 }
799
800 mac->ack_pending = 1;
801 mac->ack_signal = stats->signal;
Jussi Kivilinnaf773e402011-01-31 20:48:16 +0200802
803 /* Prevent pending tx-packet on AP-mode */
804 if (mac->type == NL80211_IFTYPE_AP) {
805 skb = __skb_dequeue(q);
806 zd_mac_tx_status(hw, skb, mac->ack_signal, NULL);
807 mac->ack_pending = 0;
808 }
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200809 }
810
Daniel Drake459c51a2007-11-19 15:00:29 +0000811 spin_unlock_irqrestore(&q->lock, flags);
812 return 1;
813}
814
815int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
816{
817 struct zd_mac *mac = zd_hw_mac(hw);
818 struct ieee80211_rx_status stats;
819 const struct rx_status *status;
820 struct sk_buff *skb;
821 int bad_frame = 0;
Harvey Harrison85365822008-06-14 23:33:39 -0700822 __le16 fc;
823 int need_padding;
Johannes Berg8318d782008-01-24 19:38:38 +0100824 int i;
825 u8 rate;
Daniel Drake459c51a2007-11-19 15:00:29 +0000826
827 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
828 FCS_LEN + sizeof(struct rx_status))
Daniel Drakee85d0912006-06-02 17:11:32 +0100829 return -EINVAL;
830
Daniel Drake459c51a2007-11-19 15:00:29 +0000831 memset(&stats, 0, sizeof(stats));
Daniel Drakee85d0912006-06-02 17:11:32 +0100832
Daniel Drake459c51a2007-11-19 15:00:29 +0000833 /* Note about pass_failed_fcs and pass_ctrl access below:
834 * mac locking intentionally omitted here, as this is the only unlocked
835 * reader and the only writer is configure_filter. Plus, if there were
836 * any races accessing these variables, it wouldn't really matter.
837 * If mac80211 ever provides a way for us to access filter flags
838 * from outside configure_filter, we could improve on this. Also, this
839 * situation may change once we implement some kind of DMA-into-skb
840 * RX path. */
Daniel Drakee85d0912006-06-02 17:11:32 +0100841
Daniel Drake459c51a2007-11-19 15:00:29 +0000842 /* Caller has to ensure that length >= sizeof(struct rx_status). */
843 status = (struct rx_status *)
Ulrich Kunitz937a0492007-10-02 18:36:53 +0100844 (buffer + (length - sizeof(struct rx_status)));
Daniel Drakee85d0912006-06-02 17:11:32 +0100845 if (status->frame_status & ZD_RX_ERROR) {
Daniel Drake459c51a2007-11-19 15:00:29 +0000846 if (mac->pass_failed_fcs &&
847 (status->frame_status & ZD_RX_CRC32_ERROR)) {
848 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
849 bad_frame = 1;
850 } else {
851 return -EINVAL;
Ulrich Kunitz22d34052007-01-29 01:00:03 +0000852 }
Daniel Drakee85d0912006-06-02 17:11:32 +0100853 }
Ulrich Kunitz22d34052007-01-29 01:00:03 +0000854
Johannes Berg8318d782008-01-24 19:38:38 +0100855 stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq;
856 stats.band = IEEE80211_BAND_2GHZ;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200857 stats.signal = status->signal_strength;
Johannes Berg8318d782008-01-24 19:38:38 +0100858
859 rate = zd_rx_rate(buffer, status);
860
861 /* todo: return index in the big switches in zd_rx_rate instead */
862 for (i = 0; i < mac->band.n_bitrates; i++)
863 if (rate == mac->band.bitrates[i].hw_value)
864 stats.rate_idx = i;
Daniel Drakee85d0912006-06-02 17:11:32 +0100865
Daniel Drake459c51a2007-11-19 15:00:29 +0000866 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
867 buffer += ZD_PLCP_HEADER_SIZE;
Daniel Drakee85d0912006-06-02 17:11:32 +0100868
Daniel Drake459c51a2007-11-19 15:00:29 +0000869 /* Except for bad frames, filter each frame to see if it is an ACK, in
870 * which case our internal TX tracking is updated. Normally we then
871 * bail here as there's no need to pass ACKs on up to the stack, but
872 * there is also the case where the stack has requested us to pass
873 * control frames on up (pass_ctrl) which we must consider. */
874 if (!bad_frame &&
875 filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats)
876 && !mac->pass_ctrl)
877 return 0;
Daniel Drakee85d0912006-06-02 17:11:32 +0100878
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400879 fc = get_unaligned((__le16*)buffer);
Harvey Harrison85365822008-06-14 23:33:39 -0700880 need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
Michael Buesch90817282007-12-29 17:24:23 +0100881
882 skb = dev_alloc_skb(length + (need_padding ? 2 : 0));
Daniel Drake459c51a2007-11-19 15:00:29 +0000883 if (skb == NULL)
Ulrich Kunitz4d1feab2006-12-10 11:13:12 -0800884 return -ENOMEM;
Michael Buesch90817282007-12-29 17:24:23 +0100885 if (need_padding) {
Walter Goldens77c20612010-05-18 04:44:54 -0700886 /* Make sure the payload data is 4 byte aligned. */
Michael Buesch90817282007-12-29 17:24:23 +0100887 skb_reserve(skb, 2);
888 }
889
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200890 /* FIXME : could we avoid this big memcpy ? */
Daniel Drake459c51a2007-11-19 15:00:29 +0000891 memcpy(skb_put(skb, length), buffer, length);
892
Johannes Bergf1d58c22009-06-17 13:13:00 +0200893 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
894 ieee80211_rx_irqsafe(hw, skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100895 return 0;
896}
897
Daniel Drake459c51a2007-11-19 15:00:29 +0000898static int zd_op_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100899 struct ieee80211_vif *vif)
Daniel Drakee85d0912006-06-02 17:11:32 +0100900{
Daniel Drake459c51a2007-11-19 15:00:29 +0000901 struct zd_mac *mac = zd_hw_mac(hw);
902
Johannes Berg05c914f2008-09-11 00:01:58 +0200903 /* using NL80211_IFTYPE_UNSPECIFIED to indicate no mode selected */
904 if (mac->type != NL80211_IFTYPE_UNSPECIFIED)
Daniel Drake459c51a2007-11-19 15:00:29 +0000905 return -EOPNOTSUPP;
906
Johannes Berg1ed32e42009-12-23 13:15:45 +0100907 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200908 case NL80211_IFTYPE_MONITOR:
909 case NL80211_IFTYPE_MESH_POINT:
910 case NL80211_IFTYPE_STATION:
911 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ed32e42009-12-23 13:15:45 +0100912 mac->type = vif->type;
Daniel Drake459c51a2007-11-19 15:00:29 +0000913 break;
914 default:
915 return -EOPNOTSUPP;
916 }
917
Jussi Kivilinnac2fadcb2011-01-31 20:48:06 +0200918 mac->vif = vif;
919
920 return set_mac_and_bssid(mac);
Daniel Drakee85d0912006-06-02 17:11:32 +0100921}
922
Daniel Drake459c51a2007-11-19 15:00:29 +0000923static void zd_op_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100924 struct ieee80211_vif *vif)
Daniel Drakee85d0912006-06-02 17:11:32 +0100925{
Daniel Drake459c51a2007-11-19 15:00:29 +0000926 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berg05c914f2008-09-11 00:01:58 +0200927 mac->type = NL80211_IFTYPE_UNSPECIFIED;
Jussi Kivilinnac2fadcb2011-01-31 20:48:06 +0200928 mac->vif = NULL;
Jussi Kivilinnab91a5152011-01-31 20:48:25 +0200929 zd_set_beacon_interval(&mac->chip, 0, 0, NL80211_IFTYPE_UNSPECIFIED);
Daniel Drake459c51a2007-11-19 15:00:29 +0000930 zd_write_mac_addr(&mac->chip, NULL);
Daniel Drakee85d0912006-06-02 17:11:32 +0100931}
932
Johannes Berge8975582008-10-09 12:18:51 +0200933static int zd_op_config(struct ieee80211_hw *hw, u32 changed)
Daniel Drakee85d0912006-06-02 17:11:32 +0100934{
Daniel Drake459c51a2007-11-19 15:00:29 +0000935 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berge8975582008-10-09 12:18:51 +0200936 struct ieee80211_conf *conf = &hw->conf;
937
Johannes Berg8318d782008-01-24 19:38:38 +0100938 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
Daniel Drakee85d0912006-06-02 17:11:32 +0100939}
940
Jussi Kivilinna4099e2f2011-01-31 20:48:35 +0200941static void zd_beacon_done(struct zd_mac *mac)
942{
943 struct sk_buff *skb, *beacon;
944
945 if (!mac->vif || mac->vif->type != NL80211_IFTYPE_AP)
946 return;
947
948 /*
949 * Send out buffered broad- and multicast frames.
950 */
951 while (!ieee80211_queue_stopped(mac->hw, 0)) {
952 skb = ieee80211_get_buffered_bc(mac->hw, mac->vif);
953 if (!skb)
954 break;
955 zd_op_tx(mac->hw, skb);
956 }
957
958 /*
959 * Fetch next beacon so that tim_count is updated.
960 */
961 beacon = ieee80211_beacon_get(mac->hw, mac->vif);
962 if (!beacon)
963 return;
964
965 zd_mac_config_beacon(mac->hw, beacon);
966 kfree_skb(beacon);
967}
968
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700969static void zd_process_intr(struct work_struct *work)
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800970{
971 u16 int_status;
Jussi Kivilinna8b17f752011-01-31 20:47:27 +0200972 unsigned long flags;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800973 struct zd_mac *mac = container_of(work, struct zd_mac, process_intr);
974
Jussi Kivilinna8b17f752011-01-31 20:47:27 +0200975 spin_lock_irqsave(&mac->lock, flags);
976 int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer + 4));
977 spin_unlock_irqrestore(&mac->lock, flags);
978
Jussi Kivilinna4099e2f2011-01-31 20:48:35 +0200979 if (int_status & INT_CFG_NEXT_BCN) {
980 /*dev_dbg_f_limit(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n");*/
981 zd_beacon_done(mac);
982 } else {
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800983 dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n");
Jussi Kivilinna4099e2f2011-01-31 20:48:35 +0200984 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800985
986 zd_chip_enable_hwint(&mac->chip);
987}
988
989
Johannes Berg3ac64be2009-08-17 16:16:53 +0200990static u64 zd_op_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +0000991 struct netdev_hw_addr_list *mc_list)
Johannes Berg3ac64be2009-08-17 16:16:53 +0200992{
993 struct zd_mac *mac = zd_hw_mac(hw);
994 struct zd_mc_hash hash;
Jiri Pirko22bedad2010-04-01 21:22:57 +0000995 struct netdev_hw_addr *ha;
Johannes Berg3ac64be2009-08-17 16:16:53 +0200996
997 zd_mc_clear(&hash);
998
Jiri Pirko22bedad2010-04-01 21:22:57 +0000999 netdev_hw_addr_list_for_each(ha, mc_list) {
1000 dev_dbg_f(zd_mac_dev(mac), "mc addr %pM\n", ha->addr);
1001 zd_mc_add_addr(&hash, ha->addr);
Johannes Berg3ac64be2009-08-17 16:16:53 +02001002 }
1003
1004 return hash.low | ((u64)hash.high << 32);
1005}
1006
Daniel Drake459c51a2007-11-19 15:00:29 +00001007#define SUPPORTED_FIF_FLAGS \
1008 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
Michael Buesch2c1a1b12008-02-10 16:03:55 +01001009 FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
Daniel Drake459c51a2007-11-19 15:00:29 +00001010static void zd_op_configure_filter(struct ieee80211_hw *hw,
1011 unsigned int changed_flags,
1012 unsigned int *new_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001013 u64 multicast)
Daniel Drake459c51a2007-11-19 15:00:29 +00001014{
Johannes Berg3ac64be2009-08-17 16:16:53 +02001015 struct zd_mc_hash hash = {
1016 .low = multicast,
1017 .high = multicast >> 32,
1018 };
Daniel Drake459c51a2007-11-19 15:00:29 +00001019 struct zd_mac *mac = zd_hw_mac(hw);
1020 unsigned long flags;
Jussi Kivilinnaa6fb0712011-01-31 20:47:46 +02001021 int r;
Daniel Drake459c51a2007-11-19 15:00:29 +00001022
1023 /* Only deal with supported flags */
1024 changed_flags &= SUPPORTED_FIF_FLAGS;
1025 *new_flags &= SUPPORTED_FIF_FLAGS;
1026
Benoit Papillault7de3c5d2010-01-03 10:20:01 +01001027 /*
1028 * If multicast parameter (as returned by zd_op_prepare_multicast)
1029 * has changed, no bit in changed_flags is set. To handle this
1030 * situation, we do not return if changed_flags is 0. If we do so,
1031 * we will have some issue with IPv6 which uses multicast for link
1032 * layer address resolution.
1033 */
Johannes Berg3ac64be2009-08-17 16:16:53 +02001034 if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI))
Daniel Drake459c51a2007-11-19 15:00:29 +00001035 zd_mc_add_all(&hash);
Daniel Drake459c51a2007-11-19 15:00:29 +00001036
1037 spin_lock_irqsave(&mac->lock, flags);
1038 mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
1039 mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
1040 mac->multicast_hash = hash;
1041 spin_unlock_irqrestore(&mac->lock, flags);
Johannes Berg3ac64be2009-08-17 16:16:53 +02001042
Jussi Kivilinnaa6fb0712011-01-31 20:47:46 +02001043 zd_chip_set_multicast_hash(&mac->chip, &hash);
Daniel Drake459c51a2007-11-19 15:00:29 +00001044
Jussi Kivilinnaa6fb0712011-01-31 20:47:46 +02001045 if (changed_flags & FIF_CONTROL) {
1046 r = set_rx_filter(mac);
1047 if (r)
1048 dev_err(zd_mac_dev(mac), "set_rx_filter error %d\n", r);
1049 }
Daniel Drake459c51a2007-11-19 15:00:29 +00001050
1051 /* no handling required for FIF_OTHER_BSS as we don't currently
1052 * do BSSID filtering */
1053 /* FIXME: in future it would be nice to enable the probe response
1054 * filter (so that the driver doesn't see them) until
1055 * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
1056 * have to schedule work to enable prbresp reception, which might
1057 * happen too late. For now we'll just listen and forward them all the
1058 * time. */
1059}
1060
Jussi Kivilinna5cf6cf82011-01-31 20:47:56 +02001061static void set_rts_cts(struct zd_mac *mac, unsigned int short_preamble)
Daniel Drake459c51a2007-11-19 15:00:29 +00001062{
Daniel Drake459c51a2007-11-19 15:00:29 +00001063 mutex_lock(&mac->chip.mutex);
Daniel Drake459c51a2007-11-19 15:00:29 +00001064 zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble);
1065 mutex_unlock(&mac->chip.mutex);
1066}
1067
Johannes Berg471b3ef2007-12-28 14:32:58 +01001068static void zd_op_bss_info_changed(struct ieee80211_hw *hw,
1069 struct ieee80211_vif *vif,
1070 struct ieee80211_bss_conf *bss_conf,
1071 u32 changes)
Daniel Drake459c51a2007-11-19 15:00:29 +00001072{
1073 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001074 int associated;
Daniel Drake459c51a2007-11-19 15:00:29 +00001075
1076 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
1077
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001078 if (mac->type == NL80211_IFTYPE_MESH_POINT ||
1079 mac->type == NL80211_IFTYPE_ADHOC) {
1080 associated = true;
1081 if (changes & BSS_CHANGED_BEACON) {
1082 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1083
1084 if (beacon) {
1085 zd_mac_config_beacon(hw, beacon);
1086 kfree_skb(beacon);
1087 }
1088 }
1089
1090 if (changes & BSS_CHANGED_BEACON_ENABLED) {
Jussi Kivilinnab91a5152011-01-31 20:48:25 +02001091 u16 interval = 0;
1092 u8 period = 0;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001093
Jussi Kivilinnab91a5152011-01-31 20:48:25 +02001094 if (bss_conf->enable_beacon) {
1095 period = bss_conf->dtim_period;
1096 interval = bss_conf->beacon_int;
1097 }
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001098
Jussi Kivilinnab91a5152011-01-31 20:48:25 +02001099 zd_set_beacon_interval(&mac->chip, interval, period,
1100 mac->type);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001101 }
1102 } else
1103 associated = is_valid_ether_addr(bss_conf->bssid);
1104
1105 spin_lock_irq(&mac->lock);
1106 mac->associated = associated;
1107 spin_unlock_irq(&mac->lock);
1108
1109 /* TODO: do hardware bssid filtering */
1110
Johannes Berg471b3ef2007-12-28 14:32:58 +01001111 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Jussi Kivilinna5cf6cf82011-01-31 20:47:56 +02001112 spin_lock_irq(&mac->lock);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001113 mac->short_preamble = bss_conf->use_short_preamble;
Jussi Kivilinna5cf6cf82011-01-31 20:47:56 +02001114 spin_unlock_irq(&mac->lock);
1115
1116 set_rts_cts(mac, bss_conf->use_short_preamble);
Daniel Drake459c51a2007-11-19 15:00:29 +00001117 }
1118}
1119
Alina Friedrichsen5fe73192009-02-25 00:49:18 +01001120static u64 zd_op_get_tsf(struct ieee80211_hw *hw)
1121{
1122 struct zd_mac *mac = zd_hw_mac(hw);
1123 return zd_chip_get_tsf(&mac->chip);
1124}
1125
Daniel Drake459c51a2007-11-19 15:00:29 +00001126static const struct ieee80211_ops zd_ops = {
1127 .tx = zd_op_tx,
1128 .start = zd_op_start,
1129 .stop = zd_op_stop,
1130 .add_interface = zd_op_add_interface,
1131 .remove_interface = zd_op_remove_interface,
1132 .config = zd_op_config,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001133 .prepare_multicast = zd_op_prepare_multicast,
Daniel Drake459c51a2007-11-19 15:00:29 +00001134 .configure_filter = zd_op_configure_filter,
Johannes Berg471b3ef2007-12-28 14:32:58 +01001135 .bss_info_changed = zd_op_bss_info_changed,
Alina Friedrichsen5fe73192009-02-25 00:49:18 +01001136 .get_tsf = zd_op_get_tsf,
Daniel Drake459c51a2007-11-19 15:00:29 +00001137};
1138
1139struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
1140{
1141 struct zd_mac *mac;
1142 struct ieee80211_hw *hw;
Daniel Drake459c51a2007-11-19 15:00:29 +00001143
1144 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
1145 if (!hw) {
1146 dev_dbg_f(&intf->dev, "out of memory\n");
1147 return NULL;
1148 }
1149
1150 mac = zd_hw_mac(hw);
1151
1152 memset(mac, 0, sizeof(*mac));
1153 spin_lock_init(&mac->lock);
1154 mac->hw = hw;
1155
Johannes Berg05c914f2008-09-11 00:01:58 +02001156 mac->type = NL80211_IFTYPE_UNSPECIFIED;
Daniel Drake459c51a2007-11-19 15:00:29 +00001157
1158 memcpy(mac->channels, zd_channels, sizeof(zd_channels));
1159 memcpy(mac->rates, zd_rates, sizeof(zd_rates));
Johannes Berg8318d782008-01-24 19:38:38 +01001160 mac->band.n_bitrates = ARRAY_SIZE(zd_rates);
1161 mac->band.bitrates = mac->rates;
1162 mac->band.n_channels = ARRAY_SIZE(zd_channels);
1163 mac->band.channels = mac->channels;
Daniel Drake459c51a2007-11-19 15:00:29 +00001164
Johannes Berg8318d782008-01-24 19:38:38 +01001165 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band;
1166
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -08001167 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
Jussi Kivilinna4099e2f2011-01-31 20:48:35 +02001168 IEEE80211_HW_SIGNAL_UNSPEC |
1169 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
Daniel Drake459c51a2007-11-19 15:00:29 +00001170
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07001171 hw->wiphy->interface_modes =
1172 BIT(NL80211_IFTYPE_MESH_POINT) |
1173 BIT(NL80211_IFTYPE_STATION) |
1174 BIT(NL80211_IFTYPE_ADHOC);
1175
Bruno Randolf566bfe52008-05-08 19:15:40 +02001176 hw->max_signal = 100;
Daniel Drake459c51a2007-11-19 15:00:29 +00001177 hw->queues = 1;
1178 hw->extra_tx_headroom = sizeof(struct zd_ctrlset);
1179
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +02001180 /*
1181 * Tell mac80211 that we support multi rate retries
1182 */
1183 hw->max_rates = IEEE80211_TX_MAX_RATES;
1184 hw->max_rate_tries = 18; /* 9 rates * 2 retries/rate */
1185
Daniel Drake459c51a2007-11-19 15:00:29 +00001186 skb_queue_head_init(&mac->ack_wait_queue);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +02001187 mac->ack_pending = 0;
Daniel Drake459c51a2007-11-19 15:00:29 +00001188
Daniel Drake459c51a2007-11-19 15:00:29 +00001189 zd_chip_init(&mac->chip, hw, intf);
1190 housekeeping_init(mac);
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -08001191 INIT_WORK(&mac->process_intr, zd_process_intr);
Daniel Drake459c51a2007-11-19 15:00:29 +00001192
1193 SET_IEEE80211_DEV(hw, &intf->dev);
1194 return hw;
Daniel Drakee85d0912006-06-02 17:11:32 +01001195}
1196
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001197#define LINK_LED_WORK_DELAY HZ
1198
David Howellsc4028952006-11-22 14:57:56 +00001199static void link_led_handler(struct work_struct *work)
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001200{
David Howellsc4028952006-11-22 14:57:56 +00001201 struct zd_mac *mac =
1202 container_of(work, struct zd_mac, housekeeping.link_led_work.work);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001203 struct zd_chip *chip = &mac->chip;
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001204 int is_associated;
1205 int r;
1206
1207 spin_lock_irq(&mac->lock);
Daniel Drake459c51a2007-11-19 15:00:29 +00001208 is_associated = mac->associated;
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001209 spin_unlock_irq(&mac->lock);
1210
1211 r = zd_chip_control_leds(chip,
Luis R. Rodriguez14b46c82009-08-04 14:04:17 -07001212 is_associated ? ZD_LED_ASSOCIATED : ZD_LED_SCANNING);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001213 if (r)
Daniel Drake459c51a2007-11-19 15:00:29 +00001214 dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001215
1216 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1217 LINK_LED_WORK_DELAY);
1218}
1219
1220static void housekeeping_init(struct zd_mac *mac)
1221{
David Howellsc4028952006-11-22 14:57:56 +00001222 INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001223}
1224
1225static void housekeeping_enable(struct zd_mac *mac)
1226{
1227 dev_dbg_f(zd_mac_dev(mac), "\n");
1228 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1229 0);
1230}
1231
1232static void housekeeping_disable(struct zd_mac *mac)
1233{
1234 dev_dbg_f(zd_mac_dev(mac), "\n");
Tejun Heoafe2c512010-12-14 16:21:17 +01001235 cancel_delayed_work_sync(&mac->housekeeping.link_led_work);
Luis R. Rodriguez14b46c82009-08-04 14:04:17 -07001236 zd_chip_control_leds(&mac->chip, ZD_LED_OFF);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001237}