blob: 895b557d664e0accfba2bf82dfd09f1a97bf7820 [file] [log] [blame]
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -07001/*
2 * Copyright (C) 2008, cozybit Inc.
3 * Copyright (C) 2003-2006, Marvell International Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 */
John W. Linvilleedfcba12010-04-28 16:12:57 -040010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12#include <linux/etherdevice.h>
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070013#include "libertas_tf.h"
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070014
15#define DRIVER_RELEASE_VERSION "004.p0"
16/* thinfirm version: 5.132.X.pX */
17#define LBTF_FW_VER_MIN 0x05840300
18#define LBTF_FW_VER_MAX 0x0584ffff
19#define QOS_CONTROL_LEN 2
20
Steve deRosiere9bd5bc2010-04-25 14:40:46 -070021/* Module parameters */
22unsigned int lbtf_debug;
23EXPORT_SYMBOL_GPL(lbtf_debug);
24module_param_named(libertas_tf_debug, lbtf_debug, int, 0644);
25
26static const char lbtf_driver_version[] = "THINFIRM-USB8388-" DRIVER_RELEASE_VERSION
27#ifdef DEBUG
28 "-dbg"
29#endif
30 "";
31
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070032struct workqueue_struct *lbtf_wq;
33
34static const struct ieee80211_channel lbtf_channels[] = {
35 { .center_freq = 2412, .hw_value = 1 },
36 { .center_freq = 2417, .hw_value = 2 },
37 { .center_freq = 2422, .hw_value = 3 },
38 { .center_freq = 2427, .hw_value = 4 },
39 { .center_freq = 2432, .hw_value = 5 },
40 { .center_freq = 2437, .hw_value = 6 },
41 { .center_freq = 2442, .hw_value = 7 },
42 { .center_freq = 2447, .hw_value = 8 },
43 { .center_freq = 2452, .hw_value = 9 },
44 { .center_freq = 2457, .hw_value = 10 },
45 { .center_freq = 2462, .hw_value = 11 },
46 { .center_freq = 2467, .hw_value = 12 },
47 { .center_freq = 2472, .hw_value = 13 },
48 { .center_freq = 2484, .hw_value = 14 },
49};
50
51/* This table contains the hardware specific values for the modulation rates. */
52static const struct ieee80211_rate lbtf_rates[] = {
53 { .bitrate = 10,
54 .hw_value = 0, },
55 { .bitrate = 20,
56 .hw_value = 1,
57 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
58 { .bitrate = 55,
59 .hw_value = 2,
60 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
61 { .bitrate = 110,
62 .hw_value = 3,
63 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
64 { .bitrate = 60,
65 .hw_value = 5,
66 .flags = 0 },
67 { .bitrate = 90,
68 .hw_value = 6,
69 .flags = 0 },
70 { .bitrate = 120,
71 .hw_value = 7,
72 .flags = 0 },
73 { .bitrate = 180,
74 .hw_value = 8,
75 .flags = 0 },
76 { .bitrate = 240,
77 .hw_value = 9,
78 .flags = 0 },
79 { .bitrate = 360,
80 .hw_value = 10,
81 .flags = 0 },
82 { .bitrate = 480,
83 .hw_value = 11,
84 .flags = 0 },
85 { .bitrate = 540,
86 .hw_value = 12,
87 .flags = 0 },
88};
89
90static void lbtf_cmd_work(struct work_struct *work)
91{
92 struct lbtf_private *priv = container_of(work, struct lbtf_private,
93 cmd_work);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -070094
95 lbtf_deb_enter(LBTF_DEB_CMD);
96
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070097 spin_lock_irq(&priv->driver_lock);
98 /* command response? */
99 if (priv->cmd_response_rxed) {
100 priv->cmd_response_rxed = 0;
101 spin_unlock_irq(&priv->driver_lock);
102 lbtf_process_rx_command(priv);
103 spin_lock_irq(&priv->driver_lock);
104 }
105
106 if (priv->cmd_timed_out && priv->cur_cmd) {
107 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
108
109 if (++priv->nr_retries > 10) {
110 lbtf_complete_command(priv, cmdnode,
111 -ETIMEDOUT);
112 priv->nr_retries = 0;
113 } else {
114 priv->cur_cmd = NULL;
115
116 /* Stick it back at the _top_ of the pending
117 * queue for immediate resubmission */
118 list_add(&cmdnode->list, &priv->cmdpendingq);
119 }
120 }
121 priv->cmd_timed_out = 0;
122 spin_unlock_irq(&priv->driver_lock);
123
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700124 if (!priv->fw_ready) {
125 lbtf_deb_leave_args(LBTF_DEB_CMD, "fw not ready");
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700126 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700127 }
128
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700129 /* Execute the next command */
130 if (!priv->cur_cmd)
131 lbtf_execute_next_command(priv);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700132
133 lbtf_deb_leave(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700134}
135
136/**
137 * lbtf_setup_firmware: initialize firmware.
138 *
139 * @priv A pointer to struct lbtf_private structure
140 *
141 * Returns: 0 on success.
142 */
143static int lbtf_setup_firmware(struct lbtf_private *priv)
144{
145 int ret = -1;
146
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700147 lbtf_deb_enter(LBTF_DEB_FW);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700148 /*
149 * Read priv address from HW
150 */
151 memset(priv->current_addr, 0xff, ETH_ALEN);
152 ret = lbtf_update_hw_spec(priv);
153 if (ret) {
154 ret = -1;
155 goto done;
156 }
157
158 lbtf_set_mac_control(priv);
159 lbtf_set_radio_control(priv);
160
161 ret = 0;
162done:
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700163 lbtf_deb_leave_args(LBTF_DEB_FW, "ret: %d", ret);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700164 return ret;
165}
166
167/**
168 * This function handles the timeout of command sending.
169 * It will re-send the same command again.
170 */
171static void command_timer_fn(unsigned long data)
172{
173 struct lbtf_private *priv = (struct lbtf_private *)data;
174 unsigned long flags;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700175 lbtf_deb_enter(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700176
177 spin_lock_irqsave(&priv->driver_lock, flags);
178
179 if (!priv->cur_cmd) {
180 printk(KERN_DEBUG "libertastf: command timer expired; "
181 "no pending command\n");
182 goto out;
183 }
184
185 printk(KERN_DEBUG "libertas: command %x timed out\n",
186 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
187
188 priv->cmd_timed_out = 1;
189 queue_work(lbtf_wq, &priv->cmd_work);
190out:
191 spin_unlock_irqrestore(&priv->driver_lock, flags);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700192 lbtf_deb_leave(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700193}
194
195static int lbtf_init_adapter(struct lbtf_private *priv)
196{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700197 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700198 memset(priv->current_addr, 0xff, ETH_ALEN);
199 mutex_init(&priv->lock);
200
201 priv->vif = NULL;
202 setup_timer(&priv->command_timer, command_timer_fn,
203 (unsigned long)priv);
204
205 INIT_LIST_HEAD(&priv->cmdfreeq);
206 INIT_LIST_HEAD(&priv->cmdpendingq);
207
208 spin_lock_init(&priv->driver_lock);
209
210 /* Allocate the command buffers */
211 if (lbtf_allocate_cmd_buffer(priv))
212 return -1;
213
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700214 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700215 return 0;
216}
217
218static void lbtf_free_adapter(struct lbtf_private *priv)
219{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700220 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700221 lbtf_free_cmd_buffer(priv);
222 del_timer(&priv->command_timer);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700223 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700224}
225
226static int lbtf_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
227{
228 struct lbtf_private *priv = hw->priv;
229
230 priv->skb_to_tx = skb;
231 queue_work(lbtf_wq, &priv->tx_work);
232 /*
233 * queue will be restarted when we receive transmission feedback if
234 * there are no buffered multicast frames to send
235 */
236 ieee80211_stop_queues(priv->hw);
Andrey Yurovsky51e99152009-01-05 14:37:31 -0800237 return NETDEV_TX_OK;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700238}
239
240static void lbtf_tx_work(struct work_struct *work)
241{
242 struct lbtf_private *priv = container_of(work, struct lbtf_private,
243 tx_work);
244 unsigned int len;
245 struct ieee80211_tx_info *info;
246 struct txpd *txpd;
247 struct sk_buff *skb = NULL;
248 int err;
249
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700250 lbtf_deb_enter(LBTF_DEB_MACOPS | LBTF_DEB_TX);
251
Johannes Berg05c914f2008-09-11 00:01:58 +0200252 if ((priv->vif->type == NL80211_IFTYPE_AP) &&
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700253 (!skb_queue_empty(&priv->bc_ps_buf)))
254 skb = skb_dequeue(&priv->bc_ps_buf);
255 else if (priv->skb_to_tx) {
256 skb = priv->skb_to_tx;
257 priv->skb_to_tx = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700258 } else {
259 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700260 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700261 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700262
263 len = skb->len;
264 info = IEEE80211_SKB_CB(skb);
265 txpd = (struct txpd *) skb_push(skb, sizeof(struct txpd));
266
267 if (priv->surpriseremoved) {
268 dev_kfree_skb_any(skb);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700269 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700270 return;
271 }
272
273 memset(txpd, 0, sizeof(struct txpd));
274 /* Activate per-packet rate selection */
275 txpd->tx_control |= cpu_to_le32(MRVL_PER_PACKET_RATE |
276 ieee80211_get_tx_rate(priv->hw, info)->hw_value);
277
278 /* copy destination address from 802.11 header */
279 memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
280 ETH_ALEN);
281 txpd->tx_packet_length = cpu_to_le16(len);
282 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700283 lbtf_deb_hex(LBTF_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700284 BUG_ON(priv->tx_skb);
285 spin_lock_irq(&priv->driver_lock);
286 priv->tx_skb = skb;
287 err = priv->hw_host_to_card(priv, MVMS_DAT, skb->data, skb->len);
288 spin_unlock_irq(&priv->driver_lock);
289 if (err) {
290 dev_kfree_skb_any(skb);
291 priv->tx_skb = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700292 pr_err("TX error: %d", err);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700293 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700294 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700295}
296
297static int lbtf_op_start(struct ieee80211_hw *hw)
298{
299 struct lbtf_private *priv = hw->priv;
300 void *card = priv->card;
301 int ret = -1;
302
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700303 lbtf_deb_enter(LBTF_DEB_MACOPS);
304
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700305 if (!priv->fw_ready)
306 /* Upload firmware */
307 if (priv->hw_prog_firmware(card))
308 goto err_prog_firmware;
309
310 /* poke the firmware */
311 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
312 priv->radioon = RADIO_ON;
313 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
314 ret = lbtf_setup_firmware(priv);
315 if (ret)
316 goto err_prog_firmware;
317
318 if ((priv->fwrelease < LBTF_FW_VER_MIN) ||
319 (priv->fwrelease > LBTF_FW_VER_MAX)) {
320 ret = -1;
321 goto err_prog_firmware;
322 }
323
324 printk(KERN_INFO "libertastf: Marvell WLAN 802.11 thinfirm adapter\n");
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700325 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700326 return 0;
327
328err_prog_firmware:
329 priv->hw_reset_device(card);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700330 lbtf_deb_leave_args(LBTF_DEB_MACOPS, "error programing fw; ret=%d", ret);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700331 return ret;
332}
333
334static void lbtf_op_stop(struct ieee80211_hw *hw)
335{
336 struct lbtf_private *priv = hw->priv;
337 unsigned long flags;
338 struct sk_buff *skb;
339
340 struct cmd_ctrl_node *cmdnode;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700341
342 lbtf_deb_enter(LBTF_DEB_MACOPS);
343
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700344 /* Flush pending command nodes */
345 spin_lock_irqsave(&priv->driver_lock, flags);
346 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
347 cmdnode->result = -ENOENT;
348 cmdnode->cmdwaitqwoken = 1;
349 wake_up_interruptible(&cmdnode->cmdwait_q);
350 }
351
352 spin_unlock_irqrestore(&priv->driver_lock, flags);
353 cancel_work_sync(&priv->cmd_work);
354 cancel_work_sync(&priv->tx_work);
355 while ((skb = skb_dequeue(&priv->bc_ps_buf)))
356 dev_kfree_skb_any(skb);
357 priv->radioon = RADIO_OFF;
358 lbtf_set_radio_control(priv);
359
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700360 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700361 return;
362}
363
364static int lbtf_op_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100365 struct ieee80211_vif *vif)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700366{
367 struct lbtf_private *priv = hw->priv;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700368 lbtf_deb_enter(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700369 if (priv->vif != NULL)
370 return -EOPNOTSUPP;
371
Johannes Berg1ed32e42009-12-23 13:15:45 +0100372 priv->vif = vif;
373 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200374 case NL80211_IFTYPE_MESH_POINT:
375 case NL80211_IFTYPE_AP:
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700376 lbtf_set_mode(priv, LBTF_AP_MODE);
377 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200378 case NL80211_IFTYPE_STATION:
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700379 lbtf_set_mode(priv, LBTF_STA_MODE);
380 break;
381 default:
382 priv->vif = NULL;
383 return -EOPNOTSUPP;
384 }
Johannes Berg1ed32e42009-12-23 13:15:45 +0100385 lbtf_set_mac_address(priv, (u8 *) vif->addr);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700386 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700387 return 0;
388}
389
390static void lbtf_op_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100391 struct ieee80211_vif *vif)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700392{
393 struct lbtf_private *priv = hw->priv;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700394 lbtf_deb_enter(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700395
Johannes Berg05c914f2008-09-11 00:01:58 +0200396 if (priv->vif->type == NL80211_IFTYPE_AP ||
397 priv->vif->type == NL80211_IFTYPE_MESH_POINT)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700398 lbtf_beacon_ctrl(priv, 0, 0);
399 lbtf_set_mode(priv, LBTF_PASSIVE_MODE);
400 lbtf_set_bssid(priv, 0, NULL);
401 priv->vif = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700402 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700403}
404
Johannes Berge8975582008-10-09 12:18:51 +0200405static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700406{
407 struct lbtf_private *priv = hw->priv;
Johannes Berge8975582008-10-09 12:18:51 +0200408 struct ieee80211_conf *conf = &hw->conf;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700409 lbtf_deb_enter(LBTF_DEB_MACOPS);
Johannes Berge8975582008-10-09 12:18:51 +0200410
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700411 if (conf->channel->center_freq != priv->cur_freq) {
412 priv->cur_freq = conf->channel->center_freq;
413 lbtf_set_channel(priv, conf->channel->hw_value);
414 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700415 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700416 return 0;
417}
418
Johannes Berg3ac64be2009-08-17 16:16:53 +0200419static u64 lbtf_op_prepare_multicast(struct ieee80211_hw *hw,
420 int mc_count, struct dev_addr_list *mclist)
421{
422 struct lbtf_private *priv = hw->priv;
423 int i;
424
425 if (!mc_count || mc_count > MRVDRV_MAX_MULTICAST_LIST_SIZE)
426 return mc_count;
427
428 priv->nr_of_multicastmacaddr = mc_count;
429 for (i = 0; i < mc_count; i++) {
430 if (!mclist)
431 break;
432 memcpy(&priv->multicastlist[i], mclist->da_addr,
433 ETH_ALEN);
434 mclist = mclist->next;
435 }
436
437 return mc_count;
438}
439
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700440#define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)
441static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
442 unsigned int changed_flags,
443 unsigned int *new_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +0200444 u64 multicast)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700445{
446 struct lbtf_private *priv = hw->priv;
447 int old_mac_control = priv->mac_control;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700448
449 lbtf_deb_enter(LBTF_DEB_MACOPS);
450
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700451 changed_flags &= SUPPORTED_FIF_FLAGS;
452 *new_flags &= SUPPORTED_FIF_FLAGS;
453
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700454 if (!changed_flags) {
455 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700456 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700457 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700458
459 if (*new_flags & (FIF_PROMISC_IN_BSS))
460 priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
461 else
462 priv->mac_control &= ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
463 if (*new_flags & (FIF_ALLMULTI) ||
Johannes Berg3ac64be2009-08-17 16:16:53 +0200464 multicast > MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700465 priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
466 priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
Johannes Berg3ac64be2009-08-17 16:16:53 +0200467 } else if (multicast) {
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700468 priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
469 priv->mac_control &= ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700470 lbtf_cmd_set_mac_multicast_addr(priv);
471 } else {
472 priv->mac_control &= ~(CMD_ACT_MAC_MULTICAST_ENABLE |
473 CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
474 if (priv->nr_of_multicastmacaddr) {
475 priv->nr_of_multicastmacaddr = 0;
476 lbtf_cmd_set_mac_multicast_addr(priv);
477 }
478 }
479
480
481 if (priv->mac_control != old_mac_control)
482 lbtf_set_mac_control(priv);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700483
484 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700485}
486
487static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
488 struct ieee80211_vif *vif,
489 struct ieee80211_bss_conf *bss_conf,
490 u32 changes)
491{
492 struct lbtf_private *priv = hw->priv;
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200493 struct sk_buff *beacon;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700494 lbtf_deb_enter(LBTF_DEB_MACOPS);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200495
496 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
497 switch (priv->vif->type) {
498 case NL80211_IFTYPE_AP:
499 case NL80211_IFTYPE_MESH_POINT:
500 beacon = ieee80211_beacon_get(hw, vif);
501 if (beacon) {
502 lbtf_beacon_set(priv, beacon);
503 kfree_skb(beacon);
504 lbtf_beacon_ctrl(priv, 1,
505 bss_conf->beacon_int);
506 }
507 break;
508 default:
509 break;
510 }
511 }
512
513 if (changes & BSS_CHANGED_BSSID) {
514 bool activate = !is_zero_ether_addr(bss_conf->bssid);
515 lbtf_set_bssid(priv, activate, bss_conf->bssid);
516 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700517
518 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
519 if (bss_conf->use_short_preamble)
520 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
521 else
522 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
523 lbtf_set_radio_control(priv);
524 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700525
526 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700527}
528
529static const struct ieee80211_ops lbtf_ops = {
530 .tx = lbtf_op_tx,
531 .start = lbtf_op_start,
532 .stop = lbtf_op_stop,
533 .add_interface = lbtf_op_add_interface,
534 .remove_interface = lbtf_op_remove_interface,
535 .config = lbtf_op_config,
Johannes Berg3ac64be2009-08-17 16:16:53 +0200536 .prepare_multicast = lbtf_op_prepare_multicast,
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700537 .configure_filter = lbtf_op_configure_filter,
538 .bss_info_changed = lbtf_op_bss_info_changed,
539};
540
541int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
542{
543 struct ieee80211_rx_status stats;
544 struct rxpd *prxpd;
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700545 int need_padding;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700546 unsigned int flags;
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700547 struct ieee80211_hdr *hdr;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700548
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700549 lbtf_deb_enter(LBTF_DEB_RX);
550
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700551 prxpd = (struct rxpd *) skb->data;
552
553 stats.flag = 0;
554 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
555 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
556 stats.freq = priv->cur_freq;
557 stats.band = IEEE80211_BAND_2GHZ;
558 stats.signal = prxpd->snr;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700559 /* Marvell rate index has a hole at value 4 */
560 if (prxpd->rx_rate > 4)
561 --prxpd->rx_rate;
562 stats.rate_idx = prxpd->rx_rate;
563 skb_pull(skb, sizeof(struct rxpd));
564
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700565 hdr = (struct ieee80211_hdr *)skb->data;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700566 flags = le32_to_cpu(*(__le32 *)(skb->data + 4));
567
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700568 need_padding = ieee80211_is_data_qos(hdr->frame_control);
569 need_padding ^= ieee80211_has_a4(hdr->frame_control);
570 need_padding ^= ieee80211_is_data_qos(hdr->frame_control) &&
571 (*ieee80211_get_qos_ctl(hdr) &
572 IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700573
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700574 if (need_padding) {
575 memmove(skb->data + 2, skb->data, skb->len);
576 skb_reserve(skb, 2);
577 }
578
Johannes Bergf1d58c22009-06-17 13:13:00 +0200579 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700580
581 lbtf_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
582 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
583 lbtf_deb_hex(LBTF_DEB_RX, "RX Data", skb->data,
584 min_t(unsigned int, skb->len, 100));
585
Johannes Bergf1d58c22009-06-17 13:13:00 +0200586 ieee80211_rx_irqsafe(priv->hw, skb);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700587
588 lbtf_deb_leave(LBTF_DEB_RX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700589 return 0;
590}
591EXPORT_SYMBOL_GPL(lbtf_rx);
592
593/**
594 * lbtf_add_card: Add and initialize the card, no fw upload yet.
595 *
596 * @card A pointer to card
597 *
598 * Returns: pointer to struct lbtf_priv.
599 */
600struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev)
601{
602 struct ieee80211_hw *hw;
603 struct lbtf_private *priv = NULL;
604
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700605 lbtf_deb_enter(LBTF_DEB_MAIN);
606
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700607 hw = ieee80211_alloc_hw(sizeof(struct lbtf_private), &lbtf_ops);
608 if (!hw)
609 goto done;
610
611 priv = hw->priv;
612 if (lbtf_init_adapter(priv))
613 goto err_init_adapter;
614
615 priv->hw = hw;
616 priv->card = card;
617 priv->tx_skb = NULL;
618
619 hw->queues = 1;
620 hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
621 hw->extra_tx_headroom = sizeof(struct txpd);
622 memcpy(priv->channels, lbtf_channels, sizeof(lbtf_channels));
623 memcpy(priv->rates, lbtf_rates, sizeof(lbtf_rates));
624 priv->band.n_bitrates = ARRAY_SIZE(lbtf_rates);
625 priv->band.bitrates = priv->rates;
626 priv->band.n_channels = ARRAY_SIZE(lbtf_channels);
627 priv->band.channels = priv->channels;
628 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Deepak Saxenaf3233832010-02-09 13:35:43 -0800629 hw->wiphy->interface_modes =
630 BIT(NL80211_IFTYPE_STATION) |
631 BIT(NL80211_IFTYPE_ADHOC);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700632 skb_queue_head_init(&priv->bc_ps_buf);
633
634 SET_IEEE80211_DEV(hw, dmdev);
635
636 INIT_WORK(&priv->cmd_work, lbtf_cmd_work);
637 INIT_WORK(&priv->tx_work, lbtf_tx_work);
638 if (ieee80211_register_hw(hw))
639 goto err_init_adapter;
640
641 goto done;
642
643err_init_adapter:
644 lbtf_free_adapter(priv);
645 ieee80211_free_hw(hw);
646 priv = NULL;
647
648done:
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700649 lbtf_deb_leave_args(LBTF_DEB_MAIN, "priv %p", priv);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700650 return priv;
651}
652EXPORT_SYMBOL_GPL(lbtf_add_card);
653
654
655int lbtf_remove_card(struct lbtf_private *priv)
656{
657 struct ieee80211_hw *hw = priv->hw;
658
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700659 lbtf_deb_enter(LBTF_DEB_MAIN);
660
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700661 priv->surpriseremoved = 1;
662 del_timer(&priv->command_timer);
663 lbtf_free_adapter(priv);
664 priv->hw = NULL;
665 ieee80211_unregister_hw(hw);
666 ieee80211_free_hw(hw);
667
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700668 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700669 return 0;
670}
671EXPORT_SYMBOL_GPL(lbtf_remove_card);
672
673void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail)
674{
675 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200676
677 ieee80211_tx_info_clear_status(info);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700678 /*
679 * Commented out, otherwise we never go beyond 1Mbit/s using mac80211
680 * default pid rc algorithm.
681 *
682 * info->status.retry_count = MRVL_DEFAULT_RETRIES - retrycnt;
683 */
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700684 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && !fail)
685 info->flags |= IEEE80211_TX_STAT_ACK;
686 skb_pull(priv->tx_skb, sizeof(struct txpd));
687 ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb);
688 priv->tx_skb = NULL;
689 if (!priv->skb_to_tx && skb_queue_empty(&priv->bc_ps_buf))
690 ieee80211_wake_queues(priv->hw);
691 else
692 queue_work(lbtf_wq, &priv->tx_work);
693}
694EXPORT_SYMBOL_GPL(lbtf_send_tx_feedback);
695
696void lbtf_bcn_sent(struct lbtf_private *priv)
697{
698 struct sk_buff *skb = NULL;
699
Johannes Berg05c914f2008-09-11 00:01:58 +0200700 if (priv->vif->type != NL80211_IFTYPE_AP)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700701 return;
702
703 if (skb_queue_empty(&priv->bc_ps_buf)) {
704 bool tx_buff_bc = 0;
705
706 while ((skb = ieee80211_get_buffered_bc(priv->hw, priv->vif))) {
707 skb_queue_tail(&priv->bc_ps_buf, skb);
708 tx_buff_bc = 1;
709 }
710 if (tx_buff_bc) {
711 ieee80211_stop_queues(priv->hw);
712 queue_work(lbtf_wq, &priv->tx_work);
713 }
714 }
715
716 skb = ieee80211_beacon_get(priv->hw, priv->vif);
717
718 if (skb) {
719 lbtf_beacon_set(priv, skb);
720 kfree_skb(skb);
721 }
722}
723EXPORT_SYMBOL_GPL(lbtf_bcn_sent);
724
725static int __init lbtf_init_module(void)
726{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700727 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700728 lbtf_wq = create_workqueue("libertastf");
729 if (lbtf_wq == NULL) {
730 printk(KERN_ERR "libertastf: couldn't create workqueue\n");
731 return -ENOMEM;
732 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700733 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700734 return 0;
735}
736
737static void __exit lbtf_exit_module(void)
738{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700739 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700740 destroy_workqueue(lbtf_wq);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700741 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700742}
743
744module_init(lbtf_init_module);
745module_exit(lbtf_exit_module);
746
747MODULE_DESCRIPTION("Libertas WLAN Thinfirm Driver Library");
748MODULE_AUTHOR("Cozybit Inc.");
749MODULE_LICENSE("GPL");