blob: 43307bd42a697c3bad30ee69a89e573a07146f48 [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
234static int set_mc_hash(struct zd_mac *mac)
235{
236 struct zd_mc_hash hash;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100237 zd_mc_clear(&hash);
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100238 return zd_chip_set_multicast_hash(&mac->chip, &hash);
239}
240
Daniel Drake459c51a2007-11-19 15:00:29 +0000241static int zd_op_start(struct ieee80211_hw *hw)
Daniel Drakee85d0912006-06-02 17:11:32 +0100242{
Daniel Drake459c51a2007-11-19 15:00:29 +0000243 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100244 struct zd_chip *chip = &mac->chip;
Daniel Drake74553ae2007-07-01 18:22:32 +0100245 struct zd_usb *usb = &chip->usb;
Daniel Drakee85d0912006-06-02 17:11:32 +0100246 int r;
247
Daniel Drake74553ae2007-07-01 18:22:32 +0100248 if (!usb->initialized) {
249 r = zd_usb_init_hw(usb);
250 if (r)
251 goto out;
252 }
253
Daniel Drakee85d0912006-06-02 17:11:32 +0100254 r = zd_chip_enable_int(chip);
255 if (r < 0)
256 goto out;
257
258 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
259 if (r < 0)
260 goto disable_int;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100261 r = set_rx_filter(mac);
262 if (r)
263 goto disable_int;
Ulrich Kunitzc5691232007-07-21 22:42:13 +0100264 r = set_mc_hash(mac);
Daniel Drakee85d0912006-06-02 17:11:32 +0100265 if (r)
266 goto disable_int;
267 r = zd_chip_switch_radio_on(chip);
268 if (r < 0)
269 goto disable_int;
Daniel Drake459c51a2007-11-19 15:00:29 +0000270 r = zd_chip_enable_rxtx(chip);
Daniel Drakee85d0912006-06-02 17:11:32 +0100271 if (r < 0)
272 goto disable_radio;
273 r = zd_chip_enable_hwint(chip);
274 if (r < 0)
Daniel Drake459c51a2007-11-19 15:00:29 +0000275 goto disable_rxtx;
Daniel Drakee85d0912006-06-02 17:11:32 +0100276
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100277 housekeeping_enable(mac);
Daniel Drakee85d0912006-06-02 17:11:32 +0100278 return 0;
Daniel Drake459c51a2007-11-19 15:00:29 +0000279disable_rxtx:
280 zd_chip_disable_rxtx(chip);
Daniel Drakee85d0912006-06-02 17:11:32 +0100281disable_radio:
282 zd_chip_switch_radio_off(chip);
283disable_int:
284 zd_chip_disable_int(chip);
285out:
286 return r;
287}
288
Daniel Drake459c51a2007-11-19 15:00:29 +0000289static void zd_op_stop(struct ieee80211_hw *hw)
290{
291 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakee85d0912006-06-02 17:11:32 +0100292 struct zd_chip *chip = &mac->chip;
Daniel Drake459c51a2007-11-19 15:00:29 +0000293 struct sk_buff *skb;
294 struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue;
Daniel Drakee85d0912006-06-02 17:11:32 +0100295
Daniel Drake459c51a2007-11-19 15:00:29 +0000296 /* The order here deliberately is a little different from the open()
Daniel Drakee85d0912006-06-02 17:11:32 +0100297 * method, since we need to make sure there is no opportunity for RX
Daniel Drake459c51a2007-11-19 15:00:29 +0000298 * frames to be processed by mac80211 after we have stopped it.
Daniel Drakee85d0912006-06-02 17:11:32 +0100299 */
300
Daniel Drake459c51a2007-11-19 15:00:29 +0000301 zd_chip_disable_rxtx(chip);
Ulrich Kunitz583afd12006-09-13 02:42:38 +0100302 housekeeping_disable(mac);
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000303 flush_workqueue(zd_workqueue);
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000304
Daniel Drakee85d0912006-06-02 17:11:32 +0100305 zd_chip_disable_hwint(chip);
306 zd_chip_switch_radio_off(chip);
307 zd_chip_disable_int(chip);
308
Daniel Drake459c51a2007-11-19 15:00:29 +0000309
310 while ((skb = skb_dequeue(ack_wait_queue)))
Johannes Berge039fa42008-05-15 12:55:29 +0200311 dev_kfree_skb_any(skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100312}
313
Daniel Drake459c51a2007-11-19 15:00:29 +0000314/**
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200315 * zd_mac_tx_status - reports tx status of a packet if required
Daniel Drake459c51a2007-11-19 15:00:29 +0000316 * @hw - a &struct ieee80211_hw pointer
317 * @skb - a sk-buffer
Johannes Berge039fa42008-05-15 12:55:29 +0200318 * @flags: extra flags to set in the TX status info
319 * @ackssi: ACK signal strength
Coly Li73ac36e2009-01-07 18:09:16 -0800320 * @success - True for successful transmission of the frame
Daniel Drake459c51a2007-11-19 15:00:29 +0000321 *
322 * This information calls ieee80211_tx_status_irqsafe() if required by the
323 * control information. It copies the control information into the status
324 * information.
325 *
326 * If no status information has been requested, the skb is freed.
327 */
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200328static void zd_mac_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
329 int ackssi, struct tx_status *tx_status)
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000330{
Johannes Berge039fa42008-05-15 12:55:29 +0200331 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200332 int i;
333 int success = 1, retry = 1;
334 int first_idx;
335 const struct tx_retry_rate *retries;
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000336
Johannes Berge6a98542008-10-21 12:40:02 +0200337 ieee80211_tx_info_clear_status(info);
Johannes Berge039fa42008-05-15 12:55:29 +0200338
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200339 if (tx_status) {
340 success = !tx_status->failure;
341 retry = tx_status->retry + success;
342 }
343
344 if (success) {
345 /* success */
Johannes Berge6a98542008-10-21 12:40:02 +0200346 info->flags |= IEEE80211_TX_STAT_ACK;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200347 } else {
348 /* failure */
349 info->flags &= ~IEEE80211_TX_STAT_ACK;
350 }
351
352 first_idx = info->status.rates[0].idx;
353 ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
354 retries = &zd_retry_rates[first_idx];
Dan Carpenter86baf712010-02-27 09:12:34 +0300355 ZD_ASSERT(1 <= retry && retry <= retries->count);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200356
357 info->status.rates[0].idx = retries->rate[0];
358 info->status.rates[0].count = 1; // (retry > 1 ? 2 : 1);
359
360 for (i=1; i<IEEE80211_TX_MAX_RATES-1 && i<retry; i++) {
361 info->status.rates[i].idx = retries->rate[i];
362 info->status.rates[i].count = 1; // ((i==retry-1) && success ? 1:2);
363 }
364 for (; i<IEEE80211_TX_MAX_RATES && i<retry; i++) {
Dan Carpenter86baf712010-02-27 09:12:34 +0300365 info->status.rates[i].idx = retries->rate[retry - 1];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200366 info->status.rates[i].count = 1; // (success ? 1:2);
367 }
368 if (i<IEEE80211_TX_MAX_RATES)
369 info->status.rates[i].idx = -1; /* terminate */
370
Johannes Berge039fa42008-05-15 12:55:29 +0200371 info->status.ack_signal = ackssi;
372 ieee80211_tx_status_irqsafe(hw, skb);
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000373}
374
Daniel Drake459c51a2007-11-19 15:00:29 +0000375/**
376 * zd_mac_tx_failed - callback for failed frames
377 * @dev: the mac80211 wireless device
378 *
Adam Buchbinder303863f2009-12-11 16:35:37 -0500379 * This function is called if a frame couldn't be successfully
Daniel Drake459c51a2007-11-19 15:00:29 +0000380 * transferred. The first frame from the tx queue, will be selected and
381 * reported as error to the upper layers.
382 */
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200383void zd_mac_tx_failed(struct urb *urb)
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000384{
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200385 struct ieee80211_hw * hw = zd_usb_to_hw(urb->context);
386 struct zd_mac *mac = zd_hw_mac(hw);
387 struct sk_buff_head *q = &mac->ack_wait_queue;
Daniel Drake459c51a2007-11-19 15:00:29 +0000388 struct sk_buff *skb;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200389 struct tx_status *tx_status = (struct tx_status *)urb->transfer_buffer;
390 unsigned long flags;
391 int success = !tx_status->failure;
392 int retry = tx_status->retry + success;
393 int found = 0;
394 int i, position = 0;
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000395
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200396 q = &mac->ack_wait_queue;
397 spin_lock_irqsave(&q->lock, flags);
Johannes Berg5078ed52008-02-20 12:09:25 +0100398
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200399 skb_queue_walk(q, skb) {
400 struct ieee80211_hdr *tx_hdr;
401 struct ieee80211_tx_info *info;
402 int first_idx, final_idx;
403 const struct tx_retry_rate *retries;
404 u8 final_rate;
405
406 position ++;
407
408 /* if the hardware reports a failure and we had a 802.11 ACK
409 * pending, then we skip the first skb when searching for a
410 * matching frame */
411 if (tx_status->failure && mac->ack_pending &&
412 skb_queue_is_first(q, skb)) {
413 continue;
414 }
415
416 tx_hdr = (struct ieee80211_hdr *)skb->data;
417
418 /* we skip all frames not matching the reported destination */
419 if (unlikely(memcmp(tx_hdr->addr1, tx_status->mac, ETH_ALEN))) {
420 continue;
421 }
422
423 /* we skip all frames not matching the reported final rate */
424
425 info = IEEE80211_SKB_CB(skb);
426 first_idx = info->status.rates[0].idx;
427 ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
428 retries = &zd_retry_rates[first_idx];
Dan Carpenter86baf712010-02-27 09:12:34 +0300429 if (retry <= 0 || retry > retries->count)
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200430 continue;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200431
Dan Carpenter86baf712010-02-27 09:12:34 +0300432 final_idx = retries->rate[retry - 1];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200433 final_rate = zd_rates[final_idx].hw_value;
434
435 if (final_rate != tx_status->rate) {
436 continue;
437 }
438
439 found = 1;
440 break;
441 }
442
443 if (found) {
444 for (i=1; i<=position; i++) {
445 skb = __skb_dequeue(q);
446 zd_mac_tx_status(hw, skb,
447 mac->ack_pending ? mac->ack_signal : 0,
448 i == position ? tx_status : NULL);
449 mac->ack_pending = 0;
450 }
451 }
452
453 spin_unlock_irqrestore(&q->lock, flags);
Ulrich Kunitz9cdac962006-12-01 00:58:07 +0000454}
455
Daniel Drake459c51a2007-11-19 15:00:29 +0000456/**
457 * zd_mac_tx_to_dev - callback for USB layer
458 * @skb: a &sk_buff pointer
459 * @error: error value, 0 if transmission successful
460 *
461 * Informs the MAC layer that the frame has successfully transferred to the
462 * device. If an ACK is required and the transfer to the device has been
463 * successful, the packets are put on the @ack_wait_queue with
464 * the control set removed.
465 */
466void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
Daniel Drakee85d0912006-06-02 17:11:32 +0100467{
Johannes Berge039fa42008-05-15 12:55:29 +0200468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200469 struct ieee80211_hw *hw = info->rate_driver_data[0];
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200470 struct zd_mac *mac = zd_hw_mac(hw);
471
472 ieee80211_tx_info_clear_status(info);
Daniel Drakee85d0912006-06-02 17:11:32 +0100473
Johannes Berge039fa42008-05-15 12:55:29 +0200474 skb_pull(skb, sizeof(struct zd_ctrlset));
475 if (unlikely(error ||
476 (info->flags & IEEE80211_TX_CTL_NO_ACK))) {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200477 /*
478 * FIXME : do we need to fill in anything ?
479 */
480 ieee80211_tx_status_irqsafe(hw, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000481 } else {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200482 struct sk_buff_head *q = &mac->ack_wait_queue;
Johannes Berge039fa42008-05-15 12:55:29 +0200483
484 skb_queue_tail(q, skb);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200485 while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) {
486 zd_mac_tx_status(hw, skb_dequeue(q),
487 mac->ack_pending ? mac->ack_signal : 0,
488 NULL);
489 mac->ack_pending = 0;
490 }
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000491 }
Daniel Drakee85d0912006-06-02 17:11:32 +0100492}
493
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000494static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
Daniel Drakee85d0912006-06-02 17:11:32 +0100495{
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100496 /* ZD_PURE_RATE() must be used to remove the modulation type flag of
Daniel Drake459c51a2007-11-19 15:00:29 +0000497 * the zd-rate values.
498 */
Daniel Drakee85d0912006-06-02 17:11:32 +0100499 static const u8 rate_divisor[] = {
Daniel Drake459c51a2007-11-19 15:00:29 +0000500 [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1,
501 [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2,
502 /* Bits must be doubled. */
503 [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11,
504 [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11,
505 [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6,
506 [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9,
507 [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12,
508 [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18,
509 [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24,
510 [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36,
511 [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
512 [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
Daniel Drakee85d0912006-06-02 17:11:32 +0100513 };
514
515 u32 bits = (u32)tx_length * 8;
516 u32 divisor;
517
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100518 divisor = rate_divisor[ZD_PURE_RATE(zd_rate)];
Daniel Drakee85d0912006-06-02 17:11:32 +0100519 if (divisor == 0)
520 return -EINVAL;
521
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000522 switch (zd_rate) {
523 case ZD_CCK_RATE_5_5M:
Daniel Drakee85d0912006-06-02 17:11:32 +0100524 bits = (2*bits) + 10; /* round up to the next integer */
525 break;
Daniel Drakeb1cd84162006-11-22 00:06:38 +0000526 case ZD_CCK_RATE_11M:
Daniel Drakee85d0912006-06-02 17:11:32 +0100527 if (service) {
528 u32 t = bits % 11;
529 *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
530 if (0 < t && t <= 3) {
531 *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
532 }
533 }
534 bits += 10; /* round up to the next integer */
535 break;
536 }
537
538 return bits/divisor;
539}
540
Daniel Drakee85d0912006-06-02 17:11:32 +0100541static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
Johannes Berge6a98542008-10-21 12:40:02 +0200542 struct ieee80211_hdr *header,
543 struct ieee80211_tx_info *info)
Daniel Drakee85d0912006-06-02 17:11:32 +0100544{
Daniel Drakee85d0912006-06-02 17:11:32 +0100545 /*
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000546 * CONTROL TODO:
Daniel Drakee85d0912006-06-02 17:11:32 +0100547 * - if backoff needed, enable bit 0
548 * - if burst (backoff not needed) disable bit 0
Daniel Drakee85d0912006-06-02 17:11:32 +0100549 */
550
551 cs->control = 0;
552
553 /* First fragment */
Johannes Berge6a98542008-10-21 12:40:02 +0200554 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Daniel Drakee85d0912006-06-02 17:11:32 +0100555 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
556
Gábor Stefanik13bdcd92009-05-14 17:34:59 +0000557 /* No ACK expected (multicast, etc.) */
558 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
559 cs->control |= ZD_CS_NO_ACK;
Daniel Drakee85d0912006-06-02 17:11:32 +0100560
561 /* PS-POLL */
Harvey Harrison85365822008-06-14 23:33:39 -0700562 if (ieee80211_is_pspoll(header->frame_control))
Daniel Drakee85d0912006-06-02 17:11:32 +0100563 cs->control |= ZD_CS_PS_POLL_FRAME;
564
Johannes Berge6a98542008-10-21 12:40:02 +0200565 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000566 cs->control |= ZD_CS_RTS;
567
Johannes Berge6a98542008-10-21 12:40:02 +0200568 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
Daniel Drakeb1382ed2006-11-22 00:06:48 +0000569 cs->control |= ZD_CS_SELF_CTS;
Daniel Drakee85d0912006-06-02 17:11:32 +0100570
571 /* FIXME: Management frame? */
572}
573
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100574static int zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon)
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800575{
576 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100577 int r;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800578 u32 tmp, j = 0;
579 /* 4 more bytes for tail CRC */
580 u32 full_len = beacon->len + 4;
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100581
582 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 0);
583 if (r < 0)
584 return r;
585 r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
586 if (r < 0)
587 return r;
588
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800589 while (tmp & 0x2) {
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100590 r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
591 if (r < 0)
592 return r;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800593 if ((++j % 100) == 0) {
594 printk(KERN_ERR "CR_BCN_FIFO_SEMAPHORE not ready\n");
595 if (j >= 500) {
596 printk(KERN_ERR "Giving up beacon config.\n");
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100597 return -ETIMEDOUT;
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800598 }
599 }
600 msleep(1);
601 }
602
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100603 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, full_len - 1);
604 if (r < 0)
605 return r;
606 if (zd_chip_is_zd1211b(&mac->chip)) {
607 r = zd_iowrite32(&mac->chip, CR_BCN_LENGTH, full_len - 1);
608 if (r < 0)
609 return r;
610 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800611
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100612 for (j = 0 ; j < beacon->len; j++) {
613 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO,
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800614 *((u8 *)(beacon->data + j)));
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100615 if (r < 0)
616 return r;
617 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800618
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100619 for (j = 0; j < 4; j++) {
620 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, 0x0);
621 if (r < 0)
622 return r;
623 }
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800624
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100625 r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 1);
626 if (r < 0)
627 return r;
628
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800629 /* 802.11b/g 2.4G CCK 1Mb
630 * 802.11a, not yet implemented, uses different values (see GPL vendor
631 * driver)
632 */
Daniel Drakef2cae6c2008-07-04 04:30:49 +0100633 return zd_iowrite32(&mac->chip, CR_BCN_PLCP_CFG, 0x00000400 |
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800634 (full_len << 19));
635}
636
Daniel Drakee85d0912006-06-02 17:11:32 +0100637static int fill_ctrlset(struct zd_mac *mac,
Johannes Berge039fa42008-05-15 12:55:29 +0200638 struct sk_buff *skb)
Daniel Drakee85d0912006-06-02 17:11:32 +0100639{
640 int r;
Daniel Drake459c51a2007-11-19 15:00:29 +0000641 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
642 unsigned int frag_len = skb->len + FCS_LEN;
Daniel Drakee85d0912006-06-02 17:11:32 +0100643 unsigned int packet_length;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200644 struct ieee80211_rate *txrate;
Daniel Drakee85d0912006-06-02 17:11:32 +0100645 struct zd_ctrlset *cs = (struct zd_ctrlset *)
646 skb_push(skb, sizeof(struct zd_ctrlset));
Johannes Berge039fa42008-05-15 12:55:29 +0200647 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100648
Daniel Drakee85d0912006-06-02 17:11:32 +0100649 ZD_ASSERT(frag_len <= 0xffff);
Daniel Drakee85d0912006-06-02 17:11:32 +0100650
Johannes Berge039fa42008-05-15 12:55:29 +0200651 txrate = ieee80211_get_tx_rate(mac->hw, info);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200652
653 cs->modulation = txrate->hw_value;
Johannes Berge6a98542008-10-21 12:40:02 +0200654 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200655 cs->modulation = txrate->hw_value_short;
Daniel Drakee85d0912006-06-02 17:11:32 +0100656
657 cs->tx_length = cpu_to_le16(frag_len);
658
Johannes Berge6a98542008-10-21 12:40:02 +0200659 cs_set_control(mac, cs, hdr, info);
Daniel Drakee85d0912006-06-02 17:11:32 +0100660
661 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
662 ZD_ASSERT(packet_length <= 0xffff);
663 /* ZD1211B: Computing the length difference this way, gives us
664 * flexibility to compute the packet length.
665 */
Daniel Drake74553ae2007-07-01 18:22:32 +0100666 cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ?
Daniel Drakee85d0912006-06-02 17:11:32 +0100667 packet_length - frag_len : packet_length);
668
669 /*
670 * CURRENT LENGTH:
671 * - transmit frame length in microseconds
672 * - seems to be derived from frame length
673 * - see Cal_Us_Service() in zdinlinef.h
674 * - if macp->bTxBurstEnable is enabled, then multiply by 4
675 * - bTxBurstEnable is never set in the vendor driver
676 *
677 * SERVICE:
678 * - "for PLCP configuration"
679 * - always 0 except in some situations at 802.11b 11M
680 * - see line 53 of zdinlinef.h
681 */
682 cs->service = 0;
Ulrich Kunitz64f222c2007-08-06 01:24:31 +0100683 r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation),
Daniel Drakee85d0912006-06-02 17:11:32 +0100684 le16_to_cpu(cs->tx_length));
685 if (r < 0)
686 return r;
687 cs->current_length = cpu_to_le16(r);
Daniel Drake459c51a2007-11-19 15:00:29 +0000688 cs->next_frame_length = 0;
Daniel Drakee85d0912006-06-02 17:11:32 +0100689
690 return 0;
691}
692
Daniel Drake459c51a2007-11-19 15:00:29 +0000693/**
694 * zd_op_tx - transmits a network frame to the device
Ulrich Kunitz741fec52006-11-22 00:05:53 +0000695 *
Daniel Drake459c51a2007-11-19 15:00:29 +0000696 * @dev: mac80211 hardware device
697 * @skb: socket buffer
698 * @control: the control structure
Daniel Drakee85d0912006-06-02 17:11:32 +0100699 *
Daniel Drake459c51a2007-11-19 15:00:29 +0000700 * This function transmit an IEEE 802.11 network frame to the device. The
701 * control block of the skbuff will be initialized. If necessary the incoming
702 * mac80211 queues will be stopped.
Daniel Drakee85d0912006-06-02 17:11:32 +0100703 */
Johannes Berge039fa42008-05-15 12:55:29 +0200704static int zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Daniel Drakee85d0912006-06-02 17:11:32 +0100705{
Daniel Drake459c51a2007-11-19 15:00:29 +0000706 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berge039fa42008-05-15 12:55:29 +0200707 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000708 int r;
Daniel Drakee85d0912006-06-02 17:11:32 +0100709
Johannes Berge039fa42008-05-15 12:55:29 +0200710 r = fill_ctrlset(mac, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000711 if (r)
Jouni Malinen640c65e2009-03-16 21:47:33 +0200712 goto fail;
Daniel Drakee85d0912006-06-02 17:11:32 +0100713
Johannes Berge6a98542008-10-21 12:40:02 +0200714 info->rate_driver_data[0] = hw;
Johannes Berge039fa42008-05-15 12:55:29 +0200715
716 r = zd_usb_tx(&mac->chip.usb, skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000717 if (r)
Jouni Malinen640c65e2009-03-16 21:47:33 +0200718 goto fail;
719 return 0;
720
721fail:
722 dev_kfree_skb(skb);
Daniel Drake459c51a2007-11-19 15:00:29 +0000723 return 0;
724}
725
726/**
727 * filter_ack - filters incoming packets for acknowledgements
728 * @dev: the mac80211 device
729 * @rx_hdr: received header
730 * @stats: the status for the received packet
731 *
732 * This functions looks for ACK packets and tries to match them with the
733 * frames in the tx queue. If a match is found the frame will be dequeued and
734 * the upper layers is informed about the successful transmission. If
735 * mac80211 queues have been stopped and the number of frames still to be
736 * transmitted is low the queues will be opened again.
737 *
738 * Returns 1 if the frame was an ACK, 0 if it was ignored.
739 */
740static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
741 struct ieee80211_rx_status *stats)
742{
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200743 struct zd_mac *mac = zd_hw_mac(hw);
Daniel Drake459c51a2007-11-19 15:00:29 +0000744 struct sk_buff *skb;
745 struct sk_buff_head *q;
746 unsigned long flags;
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200747 int found = 0;
748 int i, position = 0;
Daniel Drake459c51a2007-11-19 15:00:29 +0000749
Harvey Harrison85365822008-06-14 23:33:39 -0700750 if (!ieee80211_is_ack(rx_hdr->frame_control))
Daniel Drake459c51a2007-11-19 15:00:29 +0000751 return 0;
752
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200753 q = &mac->ack_wait_queue;
Daniel Drake459c51a2007-11-19 15:00:29 +0000754 spin_lock_irqsave(&q->lock, flags);
David S. Miller47a227d2008-09-23 00:23:30 -0700755 skb_queue_walk(q, skb) {
Daniel Drake459c51a2007-11-19 15:00:29 +0000756 struct ieee80211_hdr *tx_hdr;
757
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200758 position ++;
759
760 if (mac->ack_pending && skb_queue_is_first(q, skb))
761 continue;
762
Daniel Drake459c51a2007-11-19 15:00:29 +0000763 tx_hdr = (struct ieee80211_hdr *)skb->data;
Shaddy Baddahcde69012008-11-28 17:10:45 +1100764 if (likely(!memcmp(tx_hdr->addr2, rx_hdr->addr1, ETH_ALEN)))
Daniel Drake459c51a2007-11-19 15:00:29 +0000765 {
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200766 found = 1;
767 break;
Daniel Drake459c51a2007-11-19 15:00:29 +0000768 }
769 }
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200770
771 if (found) {
772 for (i=1; i<position; i++) {
773 skb = __skb_dequeue(q);
774 zd_mac_tx_status(hw, skb,
775 mac->ack_pending ? mac->ack_signal : 0,
776 NULL);
777 mac->ack_pending = 0;
778 }
779
780 mac->ack_pending = 1;
781 mac->ack_signal = stats->signal;
782 }
783
Daniel Drake459c51a2007-11-19 15:00:29 +0000784 spin_unlock_irqrestore(&q->lock, flags);
785 return 1;
786}
787
788int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
789{
790 struct zd_mac *mac = zd_hw_mac(hw);
791 struct ieee80211_rx_status stats;
792 const struct rx_status *status;
793 struct sk_buff *skb;
794 int bad_frame = 0;
Harvey Harrison85365822008-06-14 23:33:39 -0700795 __le16 fc;
796 int need_padding;
Johannes Berg8318d782008-01-24 19:38:38 +0100797 int i;
798 u8 rate;
Daniel Drake459c51a2007-11-19 15:00:29 +0000799
800 if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
801 FCS_LEN + sizeof(struct rx_status))
Daniel Drakee85d0912006-06-02 17:11:32 +0100802 return -EINVAL;
803
Daniel Drake459c51a2007-11-19 15:00:29 +0000804 memset(&stats, 0, sizeof(stats));
Daniel Drakee85d0912006-06-02 17:11:32 +0100805
Daniel Drake459c51a2007-11-19 15:00:29 +0000806 /* Note about pass_failed_fcs and pass_ctrl access below:
807 * mac locking intentionally omitted here, as this is the only unlocked
808 * reader and the only writer is configure_filter. Plus, if there were
809 * any races accessing these variables, it wouldn't really matter.
810 * If mac80211 ever provides a way for us to access filter flags
811 * from outside configure_filter, we could improve on this. Also, this
812 * situation may change once we implement some kind of DMA-into-skb
813 * RX path. */
Daniel Drakee85d0912006-06-02 17:11:32 +0100814
Daniel Drake459c51a2007-11-19 15:00:29 +0000815 /* Caller has to ensure that length >= sizeof(struct rx_status). */
816 status = (struct rx_status *)
Ulrich Kunitz937a0492007-10-02 18:36:53 +0100817 (buffer + (length - sizeof(struct rx_status)));
Daniel Drakee85d0912006-06-02 17:11:32 +0100818 if (status->frame_status & ZD_RX_ERROR) {
Daniel Drake459c51a2007-11-19 15:00:29 +0000819 if (mac->pass_failed_fcs &&
820 (status->frame_status & ZD_RX_CRC32_ERROR)) {
821 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
822 bad_frame = 1;
823 } else {
824 return -EINVAL;
Ulrich Kunitz22d34052007-01-29 01:00:03 +0000825 }
Daniel Drakee85d0912006-06-02 17:11:32 +0100826 }
Ulrich Kunitz22d34052007-01-29 01:00:03 +0000827
Johannes Berg8318d782008-01-24 19:38:38 +0100828 stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq;
829 stats.band = IEEE80211_BAND_2GHZ;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200830 stats.signal = status->signal_strength;
Johannes Berg8318d782008-01-24 19:38:38 +0100831
832 rate = zd_rx_rate(buffer, status);
833
834 /* todo: return index in the big switches in zd_rx_rate instead */
835 for (i = 0; i < mac->band.n_bitrates; i++)
836 if (rate == mac->band.bitrates[i].hw_value)
837 stats.rate_idx = i;
Daniel Drakee85d0912006-06-02 17:11:32 +0100838
Daniel Drake459c51a2007-11-19 15:00:29 +0000839 length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
840 buffer += ZD_PLCP_HEADER_SIZE;
Daniel Drakee85d0912006-06-02 17:11:32 +0100841
Daniel Drake459c51a2007-11-19 15:00:29 +0000842 /* Except for bad frames, filter each frame to see if it is an ACK, in
843 * which case our internal TX tracking is updated. Normally we then
844 * bail here as there's no need to pass ACKs on up to the stack, but
845 * there is also the case where the stack has requested us to pass
846 * control frames on up (pass_ctrl) which we must consider. */
847 if (!bad_frame &&
848 filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats)
849 && !mac->pass_ctrl)
850 return 0;
Daniel Drakee85d0912006-06-02 17:11:32 +0100851
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400852 fc = get_unaligned((__le16*)buffer);
Harvey Harrison85365822008-06-14 23:33:39 -0700853 need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
Michael Buesch90817282007-12-29 17:24:23 +0100854
855 skb = dev_alloc_skb(length + (need_padding ? 2 : 0));
Daniel Drake459c51a2007-11-19 15:00:29 +0000856 if (skb == NULL)
Ulrich Kunitz4d1feab2006-12-10 11:13:12 -0800857 return -ENOMEM;
Michael Buesch90817282007-12-29 17:24:23 +0100858 if (need_padding) {
Walter Goldens77c20612010-05-18 04:44:54 -0700859 /* Make sure the payload data is 4 byte aligned. */
Michael Buesch90817282007-12-29 17:24:23 +0100860 skb_reserve(skb, 2);
861 }
862
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +0200863 /* FIXME : could we avoid this big memcpy ? */
Daniel Drake459c51a2007-11-19 15:00:29 +0000864 memcpy(skb_put(skb, length), buffer, length);
865
Johannes Bergf1d58c22009-06-17 13:13:00 +0200866 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
867 ieee80211_rx_irqsafe(hw, skb);
Daniel Drakee85d0912006-06-02 17:11:32 +0100868 return 0;
869}
870
Daniel Drake459c51a2007-11-19 15:00:29 +0000871static int zd_op_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100872 struct ieee80211_vif *vif)
Daniel Drakee85d0912006-06-02 17:11:32 +0100873{
Daniel Drake459c51a2007-11-19 15:00:29 +0000874 struct zd_mac *mac = zd_hw_mac(hw);
875
Johannes Berg05c914f2008-09-11 00:01:58 +0200876 /* using NL80211_IFTYPE_UNSPECIFIED to indicate no mode selected */
877 if (mac->type != NL80211_IFTYPE_UNSPECIFIED)
Daniel Drake459c51a2007-11-19 15:00:29 +0000878 return -EOPNOTSUPP;
879
Johannes Berg1ed32e42009-12-23 13:15:45 +0100880 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200881 case NL80211_IFTYPE_MONITOR:
882 case NL80211_IFTYPE_MESH_POINT:
883 case NL80211_IFTYPE_STATION:
884 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ed32e42009-12-23 13:15:45 +0100885 mac->type = vif->type;
Daniel Drake459c51a2007-11-19 15:00:29 +0000886 break;
887 default:
888 return -EOPNOTSUPP;
889 }
890
Johannes Berg1ed32e42009-12-23 13:15:45 +0100891 return zd_write_mac_addr(&mac->chip, vif->addr);
Daniel Drakee85d0912006-06-02 17:11:32 +0100892}
893
Daniel Drake459c51a2007-11-19 15:00:29 +0000894static void zd_op_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100895 struct ieee80211_vif *vif)
Daniel Drakee85d0912006-06-02 17:11:32 +0100896{
Daniel Drake459c51a2007-11-19 15:00:29 +0000897 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berg05c914f2008-09-11 00:01:58 +0200898 mac->type = NL80211_IFTYPE_UNSPECIFIED;
Luis Carlos Cobo86229f02008-07-08 16:19:21 +0200899 zd_set_beacon_interval(&mac->chip, 0);
Daniel Drake459c51a2007-11-19 15:00:29 +0000900 zd_write_mac_addr(&mac->chip, NULL);
Daniel Drakee85d0912006-06-02 17:11:32 +0100901}
902
Johannes Berge8975582008-10-09 12:18:51 +0200903static int zd_op_config(struct ieee80211_hw *hw, u32 changed)
Daniel Drakee85d0912006-06-02 17:11:32 +0100904{
Daniel Drake459c51a2007-11-19 15:00:29 +0000905 struct zd_mac *mac = zd_hw_mac(hw);
Johannes Berge8975582008-10-09 12:18:51 +0200906 struct ieee80211_conf *conf = &hw->conf;
907
Johannes Berg8318d782008-01-24 19:38:38 +0100908 return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
Daniel Drakee85d0912006-06-02 17:11:32 +0100909}
910
Luis R. Rodrigueze83a1072008-09-09 23:19:49 -0700911static void zd_process_intr(struct work_struct *work)
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800912{
913 u16 int_status;
914 struct zd_mac *mac = container_of(work, struct zd_mac, process_intr);
915
Al Virod63ddce2008-05-21 01:34:30 +0100916 int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer+4));
Johannes Berg570a0a72009-02-10 21:25:37 +0100917 if (int_status & INT_CFG_NEXT_BCN)
918 dev_dbg_f_limit(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n");
919 else
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -0800920 dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n");
921
922 zd_chip_enable_hwint(&mac->chip);
923}
924
925
Daniel Drake459c51a2007-11-19 15:00:29 +0000926static void set_multicast_hash_handler(struct work_struct *work)
927{
928 struct zd_mac *mac =
929 container_of(work, struct zd_mac, set_multicast_hash_work);
930 struct zd_mc_hash hash;
931
932 spin_lock_irq(&mac->lock);
933 hash = mac->multicast_hash;
934 spin_unlock_irq(&mac->lock);
935
936 zd_chip_set_multicast_hash(&mac->chip, &hash);
937}
938
939static void set_rx_filter_handler(struct work_struct *work)
940{
941 struct zd_mac *mac =
942 container_of(work, struct zd_mac, set_rx_filter_work);
943 int r;
944
945 dev_dbg_f(zd_mac_dev(mac), "\n");
946 r = set_rx_filter(mac);
947 if (r)
948 dev_err(zd_mac_dev(mac), "set_rx_filter_handler error %d\n", r);
949}
950
Johannes Berg3ac64be2009-08-17 16:16:53 +0200951static u64 zd_op_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad32010-04-01 21:22:57 +0000952 struct netdev_hw_addr_list *mc_list)
Johannes Berg3ac64be2009-08-17 16:16:53 +0200953{
954 struct zd_mac *mac = zd_hw_mac(hw);
955 struct zd_mc_hash hash;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000956 struct netdev_hw_addr *ha;
Johannes Berg3ac64be2009-08-17 16:16:53 +0200957
958 zd_mc_clear(&hash);
959
Jiri Pirko22bedad32010-04-01 21:22:57 +0000960 netdev_hw_addr_list_for_each(ha, mc_list) {
961 dev_dbg_f(zd_mac_dev(mac), "mc addr %pM\n", ha->addr);
962 zd_mc_add_addr(&hash, ha->addr);
Johannes Berg3ac64be2009-08-17 16:16:53 +0200963 }
964
965 return hash.low | ((u64)hash.high << 32);
966}
967
Daniel Drake459c51a2007-11-19 15:00:29 +0000968#define SUPPORTED_FIF_FLAGS \
969 (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
Michael Buesch2c1a1b12008-02-10 16:03:55 +0100970 FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
Daniel Drake459c51a2007-11-19 15:00:29 +0000971static void zd_op_configure_filter(struct ieee80211_hw *hw,
972 unsigned int changed_flags,
973 unsigned int *new_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +0200974 u64 multicast)
Daniel Drake459c51a2007-11-19 15:00:29 +0000975{
Johannes Berg3ac64be2009-08-17 16:16:53 +0200976 struct zd_mc_hash hash = {
977 .low = multicast,
978 .high = multicast >> 32,
979 };
Daniel Drake459c51a2007-11-19 15:00:29 +0000980 struct zd_mac *mac = zd_hw_mac(hw);
981 unsigned long flags;
Daniel Drake459c51a2007-11-19 15:00:29 +0000982
983 /* Only deal with supported flags */
984 changed_flags &= SUPPORTED_FIF_FLAGS;
985 *new_flags &= SUPPORTED_FIF_FLAGS;
986
Benoit Papillault7de3c5d2010-01-03 10:20:01 +0100987 /*
988 * If multicast parameter (as returned by zd_op_prepare_multicast)
989 * has changed, no bit in changed_flags is set. To handle this
990 * situation, we do not return if changed_flags is 0. If we do so,
991 * we will have some issue with IPv6 which uses multicast for link
992 * layer address resolution.
993 */
Johannes Berg3ac64be2009-08-17 16:16:53 +0200994 if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI))
Daniel Drake459c51a2007-11-19 15:00:29 +0000995 zd_mc_add_all(&hash);
Daniel Drake459c51a2007-11-19 15:00:29 +0000996
997 spin_lock_irqsave(&mac->lock, flags);
998 mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
999 mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
1000 mac->multicast_hash = hash;
1001 spin_unlock_irqrestore(&mac->lock, flags);
Johannes Berg3ac64be2009-08-17 16:16:53 +02001002
1003 /* XXX: these can be called here now, can sleep now! */
Daniel Drake459c51a2007-11-19 15:00:29 +00001004 queue_work(zd_workqueue, &mac->set_multicast_hash_work);
1005
1006 if (changed_flags & FIF_CONTROL)
1007 queue_work(zd_workqueue, &mac->set_rx_filter_work);
1008
1009 /* no handling required for FIF_OTHER_BSS as we don't currently
1010 * do BSSID filtering */
1011 /* FIXME: in future it would be nice to enable the probe response
1012 * filter (so that the driver doesn't see them) until
1013 * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
1014 * have to schedule work to enable prbresp reception, which might
1015 * happen too late. For now we'll just listen and forward them all the
1016 * time. */
1017}
1018
1019static void set_rts_cts_work(struct work_struct *work)
1020{
1021 struct zd_mac *mac =
1022 container_of(work, struct zd_mac, set_rts_cts_work);
1023 unsigned long flags;
1024 unsigned int short_preamble;
1025
1026 mutex_lock(&mac->chip.mutex);
1027
1028 spin_lock_irqsave(&mac->lock, flags);
1029 mac->updating_rts_rate = 0;
1030 short_preamble = mac->short_preamble;
1031 spin_unlock_irqrestore(&mac->lock, flags);
1032
1033 zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble);
1034 mutex_unlock(&mac->chip.mutex);
1035}
1036
Johannes Berg471b3ef2007-12-28 14:32:58 +01001037static void zd_op_bss_info_changed(struct ieee80211_hw *hw,
1038 struct ieee80211_vif *vif,
1039 struct ieee80211_bss_conf *bss_conf,
1040 u32 changes)
Daniel Drake459c51a2007-11-19 15:00:29 +00001041{
1042 struct zd_mac *mac = zd_hw_mac(hw);
1043 unsigned long flags;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001044 int associated;
Daniel Drake459c51a2007-11-19 15:00:29 +00001045
1046 dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
1047
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001048 if (mac->type == NL80211_IFTYPE_MESH_POINT ||
1049 mac->type == NL80211_IFTYPE_ADHOC) {
1050 associated = true;
1051 if (changes & BSS_CHANGED_BEACON) {
1052 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1053
1054 if (beacon) {
1055 zd_mac_config_beacon(hw, beacon);
1056 kfree_skb(beacon);
1057 }
1058 }
1059
1060 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1061 u32 interval;
1062
1063 if (bss_conf->enable_beacon)
1064 interval = BCN_MODE_IBSS |
1065 bss_conf->beacon_int;
1066 else
1067 interval = 0;
1068
1069 zd_set_beacon_interval(&mac->chip, interval);
1070 }
1071 } else
1072 associated = is_valid_ether_addr(bss_conf->bssid);
1073
1074 spin_lock_irq(&mac->lock);
1075 mac->associated = associated;
1076 spin_unlock_irq(&mac->lock);
1077
1078 /* TODO: do hardware bssid filtering */
1079
Johannes Berg471b3ef2007-12-28 14:32:58 +01001080 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Daniel Drake459c51a2007-11-19 15:00:29 +00001081 spin_lock_irqsave(&mac->lock, flags);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001082 mac->short_preamble = bss_conf->use_short_preamble;
Daniel Drake459c51a2007-11-19 15:00:29 +00001083 if (!mac->updating_rts_rate) {
1084 mac->updating_rts_rate = 1;
1085 /* FIXME: should disable TX here, until work has
1086 * completed and RTS_CTS reg is updated */
1087 queue_work(zd_workqueue, &mac->set_rts_cts_work);
1088 }
1089 spin_unlock_irqrestore(&mac->lock, flags);
1090 }
1091}
1092
Alina Friedrichsen5fe73192009-02-25 00:49:18 +01001093static u64 zd_op_get_tsf(struct ieee80211_hw *hw)
1094{
1095 struct zd_mac *mac = zd_hw_mac(hw);
1096 return zd_chip_get_tsf(&mac->chip);
1097}
1098
Daniel Drake459c51a2007-11-19 15:00:29 +00001099static const struct ieee80211_ops zd_ops = {
1100 .tx = zd_op_tx,
1101 .start = zd_op_start,
1102 .stop = zd_op_stop,
1103 .add_interface = zd_op_add_interface,
1104 .remove_interface = zd_op_remove_interface,
1105 .config = zd_op_config,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001106 .prepare_multicast = zd_op_prepare_multicast,
Daniel Drake459c51a2007-11-19 15:00:29 +00001107 .configure_filter = zd_op_configure_filter,
Johannes Berg471b3ef2007-12-28 14:32:58 +01001108 .bss_info_changed = zd_op_bss_info_changed,
Alina Friedrichsen5fe73192009-02-25 00:49:18 +01001109 .get_tsf = zd_op_get_tsf,
Daniel Drake459c51a2007-11-19 15:00:29 +00001110};
1111
1112struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
1113{
1114 struct zd_mac *mac;
1115 struct ieee80211_hw *hw;
Daniel Drake459c51a2007-11-19 15:00:29 +00001116
1117 hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
1118 if (!hw) {
1119 dev_dbg_f(&intf->dev, "out of memory\n");
1120 return NULL;
1121 }
1122
1123 mac = zd_hw_mac(hw);
1124
1125 memset(mac, 0, sizeof(*mac));
1126 spin_lock_init(&mac->lock);
1127 mac->hw = hw;
1128
Johannes Berg05c914f2008-09-11 00:01:58 +02001129 mac->type = NL80211_IFTYPE_UNSPECIFIED;
Daniel Drake459c51a2007-11-19 15:00:29 +00001130
1131 memcpy(mac->channels, zd_channels, sizeof(zd_channels));
1132 memcpy(mac->rates, zd_rates, sizeof(zd_rates));
Johannes Berg8318d782008-01-24 19:38:38 +01001133 mac->band.n_bitrates = ARRAY_SIZE(zd_rates);
1134 mac->band.bitrates = mac->rates;
1135 mac->band.n_channels = ARRAY_SIZE(zd_channels);
1136 mac->band.channels = mac->channels;
Daniel Drake459c51a2007-11-19 15:00:29 +00001137
Johannes Berg8318d782008-01-24 19:38:38 +01001138 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band;
1139
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -08001140 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
Johannes Berg7fee5372009-01-30 11:13:06 +01001141 IEEE80211_HW_SIGNAL_UNSPEC;
Daniel Drake459c51a2007-11-19 15:00:29 +00001142
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07001143 hw->wiphy->interface_modes =
1144 BIT(NL80211_IFTYPE_MESH_POINT) |
1145 BIT(NL80211_IFTYPE_STATION) |
1146 BIT(NL80211_IFTYPE_ADHOC);
1147
Bruno Randolf566bfe52008-05-08 19:15:40 +02001148 hw->max_signal = 100;
Daniel Drake459c51a2007-11-19 15:00:29 +00001149 hw->queues = 1;
1150 hw->extra_tx_headroom = sizeof(struct zd_ctrlset);
1151
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +02001152 /*
1153 * Tell mac80211 that we support multi rate retries
1154 */
1155 hw->max_rates = IEEE80211_TX_MAX_RATES;
1156 hw->max_rate_tries = 18; /* 9 rates * 2 retries/rate */
1157
Daniel Drake459c51a2007-11-19 15:00:29 +00001158 skb_queue_head_init(&mac->ack_wait_queue);
Benoit PAPILLAULT7f4013f2009-10-22 12:04:52 +02001159 mac->ack_pending = 0;
Daniel Drake459c51a2007-11-19 15:00:29 +00001160
Daniel Drake459c51a2007-11-19 15:00:29 +00001161 zd_chip_init(&mac->chip, hw, intf);
1162 housekeeping_init(mac);
1163 INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
1164 INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
1165 INIT_WORK(&mac->set_rx_filter_work, set_rx_filter_handler);
Luis Carlos Cobo72e77a82008-03-03 12:32:15 -08001166 INIT_WORK(&mac->process_intr, zd_process_intr);
Daniel Drake459c51a2007-11-19 15:00:29 +00001167
1168 SET_IEEE80211_DEV(hw, &intf->dev);
1169 return hw;
Daniel Drakee85d0912006-06-02 17:11:32 +01001170}
1171
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001172#define LINK_LED_WORK_DELAY HZ
1173
David Howellsc4028952006-11-22 14:57:56 +00001174static void link_led_handler(struct work_struct *work)
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001175{
David Howellsc4028952006-11-22 14:57:56 +00001176 struct zd_mac *mac =
1177 container_of(work, struct zd_mac, housekeeping.link_led_work.work);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001178 struct zd_chip *chip = &mac->chip;
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001179 int is_associated;
1180 int r;
1181
1182 spin_lock_irq(&mac->lock);
Daniel Drake459c51a2007-11-19 15:00:29 +00001183 is_associated = mac->associated;
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001184 spin_unlock_irq(&mac->lock);
1185
1186 r = zd_chip_control_leds(chip,
Luis R. Rodriguez14b46c82009-08-04 14:04:17 -07001187 is_associated ? ZD_LED_ASSOCIATED : ZD_LED_SCANNING);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001188 if (r)
Daniel Drake459c51a2007-11-19 15:00:29 +00001189 dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001190
1191 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1192 LINK_LED_WORK_DELAY);
1193}
1194
1195static void housekeeping_init(struct zd_mac *mac)
1196{
David Howellsc4028952006-11-22 14:57:56 +00001197 INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001198}
1199
1200static void housekeeping_enable(struct zd_mac *mac)
1201{
1202 dev_dbg_f(zd_mac_dev(mac), "\n");
1203 queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
1204 0);
1205}
1206
1207static void housekeeping_disable(struct zd_mac *mac)
1208{
1209 dev_dbg_f(zd_mac_dev(mac), "\n");
1210 cancel_rearming_delayed_workqueue(zd_workqueue,
1211 &mac->housekeeping.link_led_work);
Luis R. Rodriguez14b46c82009-08-04 14:04:17 -07001212 zd_chip_control_leds(&mac->chip, ZD_LED_OFF);
Ulrich Kunitz583afd12006-09-13 02:42:38 +01001213}