blob: 7001856241e60354e9ff5cbed505ba6fc8bac415 [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
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000012#include <linux/hardirq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
14
John W. Linvilleedfcba12010-04-28 16:12:57 -040015#include <linux/etherdevice.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040016#include <linux/module.h>
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070017#include "libertas_tf.h"
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070018
19#define DRIVER_RELEASE_VERSION "004.p0"
20/* thinfirm version: 5.132.X.pX */
21#define LBTF_FW_VER_MIN 0x05840300
22#define LBTF_FW_VER_MAX 0x0584ffff
23#define QOS_CONTROL_LEN 2
24
Steve deRosiere9bd5bc2010-04-25 14:40:46 -070025/* Module parameters */
26unsigned int lbtf_debug;
27EXPORT_SYMBOL_GPL(lbtf_debug);
28module_param_named(libertas_tf_debug, lbtf_debug, int, 0644);
29
30static const char lbtf_driver_version[] = "THINFIRM-USB8388-" DRIVER_RELEASE_VERSION
31#ifdef DEBUG
32 "-dbg"
33#endif
34 "";
35
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -070036struct workqueue_struct *lbtf_wq;
37
38static const struct ieee80211_channel lbtf_channels[] = {
39 { .center_freq = 2412, .hw_value = 1 },
40 { .center_freq = 2417, .hw_value = 2 },
41 { .center_freq = 2422, .hw_value = 3 },
42 { .center_freq = 2427, .hw_value = 4 },
43 { .center_freq = 2432, .hw_value = 5 },
44 { .center_freq = 2437, .hw_value = 6 },
45 { .center_freq = 2442, .hw_value = 7 },
46 { .center_freq = 2447, .hw_value = 8 },
47 { .center_freq = 2452, .hw_value = 9 },
48 { .center_freq = 2457, .hw_value = 10 },
49 { .center_freq = 2462, .hw_value = 11 },
50 { .center_freq = 2467, .hw_value = 12 },
51 { .center_freq = 2472, .hw_value = 13 },
52 { .center_freq = 2484, .hw_value = 14 },
53};
54
55/* This table contains the hardware specific values for the modulation rates. */
56static const struct ieee80211_rate lbtf_rates[] = {
57 { .bitrate = 10,
58 .hw_value = 0, },
59 { .bitrate = 20,
60 .hw_value = 1,
61 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
62 { .bitrate = 55,
63 .hw_value = 2,
64 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
65 { .bitrate = 110,
66 .hw_value = 3,
67 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
68 { .bitrate = 60,
69 .hw_value = 5,
70 .flags = 0 },
71 { .bitrate = 90,
72 .hw_value = 6,
73 .flags = 0 },
74 { .bitrate = 120,
75 .hw_value = 7,
76 .flags = 0 },
77 { .bitrate = 180,
78 .hw_value = 8,
79 .flags = 0 },
80 { .bitrate = 240,
81 .hw_value = 9,
82 .flags = 0 },
83 { .bitrate = 360,
84 .hw_value = 10,
85 .flags = 0 },
86 { .bitrate = 480,
87 .hw_value = 11,
88 .flags = 0 },
89 { .bitrate = 540,
90 .hw_value = 12,
91 .flags = 0 },
92};
93
94static void lbtf_cmd_work(struct work_struct *work)
95{
96 struct lbtf_private *priv = container_of(work, struct lbtf_private,
97 cmd_work);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -070098
99 lbtf_deb_enter(LBTF_DEB_CMD);
100
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700101 spin_lock_irq(&priv->driver_lock);
102 /* command response? */
103 if (priv->cmd_response_rxed) {
104 priv->cmd_response_rxed = 0;
105 spin_unlock_irq(&priv->driver_lock);
106 lbtf_process_rx_command(priv);
107 spin_lock_irq(&priv->driver_lock);
108 }
109
110 if (priv->cmd_timed_out && priv->cur_cmd) {
111 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
112
113 if (++priv->nr_retries > 10) {
114 lbtf_complete_command(priv, cmdnode,
115 -ETIMEDOUT);
116 priv->nr_retries = 0;
117 } else {
118 priv->cur_cmd = NULL;
119
120 /* Stick it back at the _top_ of the pending
121 * queue for immediate resubmission */
122 list_add(&cmdnode->list, &priv->cmdpendingq);
123 }
124 }
125 priv->cmd_timed_out = 0;
126 spin_unlock_irq(&priv->driver_lock);
127
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700128 if (!priv->fw_ready) {
129 lbtf_deb_leave_args(LBTF_DEB_CMD, "fw not ready");
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700130 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700131 }
132
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700133 /* Execute the next command */
134 if (!priv->cur_cmd)
135 lbtf_execute_next_command(priv);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700136
137 lbtf_deb_leave(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700138}
139
140/**
141 * lbtf_setup_firmware: initialize firmware.
142 *
143 * @priv A pointer to struct lbtf_private structure
144 *
145 * Returns: 0 on success.
146 */
147static int lbtf_setup_firmware(struct lbtf_private *priv)
148{
149 int ret = -1;
150
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700151 lbtf_deb_enter(LBTF_DEB_FW);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700152 /*
153 * Read priv address from HW
154 */
155 memset(priv->current_addr, 0xff, ETH_ALEN);
156 ret = lbtf_update_hw_spec(priv);
157 if (ret) {
158 ret = -1;
159 goto done;
160 }
161
162 lbtf_set_mac_control(priv);
163 lbtf_set_radio_control(priv);
164
165 ret = 0;
166done:
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700167 lbtf_deb_leave_args(LBTF_DEB_FW, "ret: %d", ret);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700168 return ret;
169}
170
171/**
172 * This function handles the timeout of command sending.
173 * It will re-send the same command again.
174 */
175static void command_timer_fn(unsigned long data)
176{
177 struct lbtf_private *priv = (struct lbtf_private *)data;
178 unsigned long flags;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700179 lbtf_deb_enter(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700180
181 spin_lock_irqsave(&priv->driver_lock, flags);
182
183 if (!priv->cur_cmd) {
184 printk(KERN_DEBUG "libertastf: command timer expired; "
185 "no pending command\n");
186 goto out;
187 }
188
189 printk(KERN_DEBUG "libertas: command %x timed out\n",
190 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
191
192 priv->cmd_timed_out = 1;
193 queue_work(lbtf_wq, &priv->cmd_work);
194out:
195 spin_unlock_irqrestore(&priv->driver_lock, flags);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700196 lbtf_deb_leave(LBTF_DEB_CMD);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700197}
198
199static int lbtf_init_adapter(struct lbtf_private *priv)
200{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700201 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700202 memset(priv->current_addr, 0xff, ETH_ALEN);
203 mutex_init(&priv->lock);
204
205 priv->vif = NULL;
206 setup_timer(&priv->command_timer, command_timer_fn,
207 (unsigned long)priv);
208
209 INIT_LIST_HEAD(&priv->cmdfreeq);
210 INIT_LIST_HEAD(&priv->cmdpendingq);
211
212 spin_lock_init(&priv->driver_lock);
213
214 /* Allocate the command buffers */
215 if (lbtf_allocate_cmd_buffer(priv))
216 return -1;
217
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700218 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700219 return 0;
220}
221
222static void lbtf_free_adapter(struct lbtf_private *priv)
223{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700224 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700225 lbtf_free_cmd_buffer(priv);
226 del_timer(&priv->command_timer);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700227 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700228}
229
Thomas Huehn36323f82012-07-23 21:33:42 +0200230static void lbtf_op_tx(struct ieee80211_hw *hw,
231 struct ieee80211_tx_control *control,
232 struct sk_buff *skb)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700233{
234 struct lbtf_private *priv = hw->priv;
235
236 priv->skb_to_tx = skb;
237 queue_work(lbtf_wq, &priv->tx_work);
238 /*
239 * queue will be restarted when we receive transmission feedback if
240 * there are no buffered multicast frames to send
241 */
242 ieee80211_stop_queues(priv->hw);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700243}
244
245static void lbtf_tx_work(struct work_struct *work)
246{
247 struct lbtf_private *priv = container_of(work, struct lbtf_private,
248 tx_work);
249 unsigned int len;
250 struct ieee80211_tx_info *info;
251 struct txpd *txpd;
252 struct sk_buff *skb = NULL;
253 int err;
254
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700255 lbtf_deb_enter(LBTF_DEB_MACOPS | LBTF_DEB_TX);
256
Johannes Berg05c914f2008-09-11 00:01:58 +0200257 if ((priv->vif->type == NL80211_IFTYPE_AP) &&
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700258 (!skb_queue_empty(&priv->bc_ps_buf)))
259 skb = skb_dequeue(&priv->bc_ps_buf);
260 else if (priv->skb_to_tx) {
261 skb = priv->skb_to_tx;
262 priv->skb_to_tx = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700263 } else {
264 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700265 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700266 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700267
268 len = skb->len;
269 info = IEEE80211_SKB_CB(skb);
270 txpd = (struct txpd *) skb_push(skb, sizeof(struct txpd));
271
272 if (priv->surpriseremoved) {
273 dev_kfree_skb_any(skb);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700274 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700275 return;
276 }
277
278 memset(txpd, 0, sizeof(struct txpd));
279 /* Activate per-packet rate selection */
280 txpd->tx_control |= cpu_to_le32(MRVL_PER_PACKET_RATE |
281 ieee80211_get_tx_rate(priv->hw, info)->hw_value);
282
283 /* copy destination address from 802.11 header */
284 memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
285 ETH_ALEN);
286 txpd->tx_packet_length = cpu_to_le16(len);
287 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700288 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 -0700289 BUG_ON(priv->tx_skb);
290 spin_lock_irq(&priv->driver_lock);
291 priv->tx_skb = skb;
292 err = priv->hw_host_to_card(priv, MVMS_DAT, skb->data, skb->len);
293 spin_unlock_irq(&priv->driver_lock);
294 if (err) {
295 dev_kfree_skb_any(skb);
296 priv->tx_skb = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700297 pr_err("TX error: %d", err);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700298 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700299 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700300}
301
302static int lbtf_op_start(struct ieee80211_hw *hw)
303{
304 struct lbtf_private *priv = hw->priv;
305 void *card = priv->card;
306 int ret = -1;
307
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700308 lbtf_deb_enter(LBTF_DEB_MACOPS);
309
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700310 if (!priv->fw_ready)
311 /* Upload firmware */
312 if (priv->hw_prog_firmware(card))
313 goto err_prog_firmware;
314
315 /* poke the firmware */
316 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
317 priv->radioon = RADIO_ON;
318 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
319 ret = lbtf_setup_firmware(priv);
320 if (ret)
321 goto err_prog_firmware;
322
323 if ((priv->fwrelease < LBTF_FW_VER_MIN) ||
324 (priv->fwrelease > LBTF_FW_VER_MAX)) {
325 ret = -1;
326 goto err_prog_firmware;
327 }
328
329 printk(KERN_INFO "libertastf: Marvell WLAN 802.11 thinfirm adapter\n");
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700330 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700331 return 0;
332
333err_prog_firmware:
334 priv->hw_reset_device(card);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700335 lbtf_deb_leave_args(LBTF_DEB_MACOPS, "error programing fw; ret=%d", ret);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700336 return ret;
337}
338
339static void lbtf_op_stop(struct ieee80211_hw *hw)
340{
341 struct lbtf_private *priv = hw->priv;
342 unsigned long flags;
343 struct sk_buff *skb;
344
345 struct cmd_ctrl_node *cmdnode;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700346
347 lbtf_deb_enter(LBTF_DEB_MACOPS);
348
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700349 /* Flush pending command nodes */
350 spin_lock_irqsave(&priv->driver_lock, flags);
351 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
352 cmdnode->result = -ENOENT;
353 cmdnode->cmdwaitqwoken = 1;
354 wake_up_interruptible(&cmdnode->cmdwait_q);
355 }
356
357 spin_unlock_irqrestore(&priv->driver_lock, flags);
358 cancel_work_sync(&priv->cmd_work);
359 cancel_work_sync(&priv->tx_work);
360 while ((skb = skb_dequeue(&priv->bc_ps_buf)))
361 dev_kfree_skb_any(skb);
362 priv->radioon = RADIO_OFF;
363 lbtf_set_radio_control(priv);
364
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700365 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700366}
367
368static int lbtf_op_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100369 struct ieee80211_vif *vif)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700370{
371 struct lbtf_private *priv = hw->priv;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700372 lbtf_deb_enter(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700373 if (priv->vif != NULL)
374 return -EOPNOTSUPP;
375
Johannes Berg1ed32e42009-12-23 13:15:45 +0100376 priv->vif = vif;
377 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200378 case NL80211_IFTYPE_MESH_POINT:
379 case NL80211_IFTYPE_AP:
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700380 lbtf_set_mode(priv, LBTF_AP_MODE);
381 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200382 case NL80211_IFTYPE_STATION:
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700383 lbtf_set_mode(priv, LBTF_STA_MODE);
384 break;
385 default:
386 priv->vif = NULL;
387 return -EOPNOTSUPP;
388 }
Johannes Berg1ed32e42009-12-23 13:15:45 +0100389 lbtf_set_mac_address(priv, (u8 *) vif->addr);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700390 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700391 return 0;
392}
393
394static void lbtf_op_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +0100395 struct ieee80211_vif *vif)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700396{
397 struct lbtf_private *priv = hw->priv;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700398 lbtf_deb_enter(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700399
Johannes Berg05c914f2008-09-11 00:01:58 +0200400 if (priv->vif->type == NL80211_IFTYPE_AP ||
401 priv->vif->type == NL80211_IFTYPE_MESH_POINT)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700402 lbtf_beacon_ctrl(priv, 0, 0);
403 lbtf_set_mode(priv, LBTF_PASSIVE_MODE);
404 lbtf_set_bssid(priv, 0, NULL);
405 priv->vif = NULL;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700406 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700407}
408
Johannes Berge8975582008-10-09 12:18:51 +0200409static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700410{
411 struct lbtf_private *priv = hw->priv;
Johannes Berge8975582008-10-09 12:18:51 +0200412 struct ieee80211_conf *conf = &hw->conf;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700413 lbtf_deb_enter(LBTF_DEB_MACOPS);
Johannes Berge8975582008-10-09 12:18:51 +0200414
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700415 if (conf->channel->center_freq != priv->cur_freq) {
416 priv->cur_freq = conf->channel->center_freq;
417 lbtf_set_channel(priv, conf->channel->hw_value);
418 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700419 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700420 return 0;
421}
422
Johannes Berg3ac64be2009-08-17 16:16:53 +0200423static u64 lbtf_op_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad32010-04-01 21:22:57 +0000424 struct netdev_hw_addr_list *mc_list)
Johannes Berg3ac64be2009-08-17 16:16:53 +0200425{
426 struct lbtf_private *priv = hw->priv;
427 int i;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000428 struct netdev_hw_addr *ha;
429 int mc_count = netdev_hw_addr_list_count(mc_list);
Johannes Berg3ac64be2009-08-17 16:16:53 +0200430
431 if (!mc_count || mc_count > MRVDRV_MAX_MULTICAST_LIST_SIZE)
432 return mc_count;
433
434 priv->nr_of_multicastmacaddr = mc_count;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000435 i = 0;
436 netdev_hw_addr_list_for_each(ha, mc_list)
437 memcpy(&priv->multicastlist[i++], ha->addr, ETH_ALEN);
Johannes Berg3ac64be2009-08-17 16:16:53 +0200438
439 return mc_count;
440}
441
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700442#define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)
443static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
444 unsigned int changed_flags,
445 unsigned int *new_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +0200446 u64 multicast)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700447{
448 struct lbtf_private *priv = hw->priv;
449 int old_mac_control = priv->mac_control;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700450
451 lbtf_deb_enter(LBTF_DEB_MACOPS);
452
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700453 changed_flags &= SUPPORTED_FIF_FLAGS;
454 *new_flags &= SUPPORTED_FIF_FLAGS;
455
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700456 if (!changed_flags) {
457 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700458 return;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700459 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700460
461 if (*new_flags & (FIF_PROMISC_IN_BSS))
462 priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
463 else
464 priv->mac_control &= ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
465 if (*new_flags & (FIF_ALLMULTI) ||
Johannes Berg3ac64be2009-08-17 16:16:53 +0200466 multicast > MRVDRV_MAX_MULTICAST_LIST_SIZE) {
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700467 priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
468 priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
Johannes Berg3ac64be2009-08-17 16:16:53 +0200469 } else if (multicast) {
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700470 priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
471 priv->mac_control &= ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700472 lbtf_cmd_set_mac_multicast_addr(priv);
473 } else {
474 priv->mac_control &= ~(CMD_ACT_MAC_MULTICAST_ENABLE |
475 CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
476 if (priv->nr_of_multicastmacaddr) {
477 priv->nr_of_multicastmacaddr = 0;
478 lbtf_cmd_set_mac_multicast_addr(priv);
479 }
480 }
481
482
483 if (priv->mac_control != old_mac_control)
484 lbtf_set_mac_control(priv);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700485
486 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700487}
488
489static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
490 struct ieee80211_vif *vif,
491 struct ieee80211_bss_conf *bss_conf,
492 u32 changes)
493{
494 struct lbtf_private *priv = hw->priv;
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200495 struct sk_buff *beacon;
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700496 lbtf_deb_enter(LBTF_DEB_MACOPS);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200497
498 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
499 switch (priv->vif->type) {
500 case NL80211_IFTYPE_AP:
501 case NL80211_IFTYPE_MESH_POINT:
502 beacon = ieee80211_beacon_get(hw, vif);
503 if (beacon) {
504 lbtf_beacon_set(priv, beacon);
505 kfree_skb(beacon);
506 lbtf_beacon_ctrl(priv, 1,
507 bss_conf->beacon_int);
508 }
509 break;
510 default:
511 break;
512 }
513 }
514
515 if (changes & BSS_CHANGED_BSSID) {
516 bool activate = !is_zero_ether_addr(bss_conf->bssid);
517 lbtf_set_bssid(priv, activate, bss_conf->bssid);
518 }
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700519
520 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
521 if (bss_conf->use_short_preamble)
522 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
523 else
524 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
525 lbtf_set_radio_control(priv);
526 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700527
528 lbtf_deb_leave(LBTF_DEB_MACOPS);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700529}
530
John W. Linvillebef9cb52010-07-28 15:03:42 -0400531static int lbtf_op_get_survey(struct ieee80211_hw *hw, int idx,
532 struct survey_info *survey)
533{
534 struct lbtf_private *priv = hw->priv;
535 struct ieee80211_conf *conf = &hw->conf;
536
537 if (idx != 0)
538 return -ENOENT;
539
540 survey->channel = conf->channel;
541 survey->filled = SURVEY_INFO_NOISE_DBM;
542 survey->noise = priv->noise;
543
544 return 0;
545}
546
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700547static const struct ieee80211_ops lbtf_ops = {
548 .tx = lbtf_op_tx,
549 .start = lbtf_op_start,
550 .stop = lbtf_op_stop,
551 .add_interface = lbtf_op_add_interface,
552 .remove_interface = lbtf_op_remove_interface,
553 .config = lbtf_op_config,
Johannes Berg3ac64be2009-08-17 16:16:53 +0200554 .prepare_multicast = lbtf_op_prepare_multicast,
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700555 .configure_filter = lbtf_op_configure_filter,
556 .bss_info_changed = lbtf_op_bss_info_changed,
John W. Linvillebef9cb52010-07-28 15:03:42 -0400557 .get_survey = lbtf_op_get_survey,
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700558};
559
560int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
561{
562 struct ieee80211_rx_status stats;
563 struct rxpd *prxpd;
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700564 int need_padding;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700565 unsigned int flags;
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700566 struct ieee80211_hdr *hdr;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700567
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700568 lbtf_deb_enter(LBTF_DEB_RX);
569
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700570 prxpd = (struct rxpd *) skb->data;
571
Prarit Bhargava13deb232010-06-10 08:08:42 -0400572 memset(&stats, 0, sizeof(stats));
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700573 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
574 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
575 stats.freq = priv->cur_freq;
576 stats.band = IEEE80211_BAND_2GHZ;
577 stats.signal = prxpd->snr;
John W. Linvillebef9cb52010-07-28 15:03:42 -0400578 priv->noise = prxpd->nf;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700579 /* Marvell rate index has a hole at value 4 */
580 if (prxpd->rx_rate > 4)
581 --prxpd->rx_rate;
582 stats.rate_idx = prxpd->rx_rate;
583 skb_pull(skb, sizeof(struct rxpd));
584
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700585 hdr = (struct ieee80211_hdr *)skb->data;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700586 flags = le32_to_cpu(*(__le32 *)(skb->data + 4));
587
Harvey Harrisonde9cc7a2008-08-25 14:06:32 -0700588 need_padding = ieee80211_is_data_qos(hdr->frame_control);
589 need_padding ^= ieee80211_has_a4(hdr->frame_control);
590 need_padding ^= ieee80211_is_data_qos(hdr->frame_control) &&
591 (*ieee80211_get_qos_ctl(hdr) &
Johannes Berg04b7dcf2011-06-22 10:06:59 +0200592 IEEE80211_QOS_CTL_A_MSDU_PRESENT);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700593
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700594 if (need_padding) {
595 memmove(skb->data + 2, skb->data, skb->len);
596 skb_reserve(skb, 2);
597 }
598
Johannes Bergf1d58c22009-06-17 13:13:00 +0200599 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700600
601 lbtf_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
602 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
603 lbtf_deb_hex(LBTF_DEB_RX, "RX Data", skb->data,
604 min_t(unsigned int, skb->len, 100));
605
Johannes Bergf1d58c22009-06-17 13:13:00 +0200606 ieee80211_rx_irqsafe(priv->hw, skb);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700607
608 lbtf_deb_leave(LBTF_DEB_RX);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700609 return 0;
610}
611EXPORT_SYMBOL_GPL(lbtf_rx);
612
613/**
614 * lbtf_add_card: Add and initialize the card, no fw upload yet.
615 *
616 * @card A pointer to card
617 *
618 * Returns: pointer to struct lbtf_priv.
619 */
620struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev)
621{
622 struct ieee80211_hw *hw;
623 struct lbtf_private *priv = NULL;
624
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700625 lbtf_deb_enter(LBTF_DEB_MAIN);
626
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700627 hw = ieee80211_alloc_hw(sizeof(struct lbtf_private), &lbtf_ops);
628 if (!hw)
629 goto done;
630
631 priv = hw->priv;
632 if (lbtf_init_adapter(priv))
633 goto err_init_adapter;
634
635 priv->hw = hw;
636 priv->card = card;
637 priv->tx_skb = NULL;
638
639 hw->queues = 1;
640 hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
641 hw->extra_tx_headroom = sizeof(struct txpd);
642 memcpy(priv->channels, lbtf_channels, sizeof(lbtf_channels));
643 memcpy(priv->rates, lbtf_rates, sizeof(lbtf_rates));
644 priv->band.n_bitrates = ARRAY_SIZE(lbtf_rates);
645 priv->band.bitrates = priv->rates;
646 priv->band.n_channels = ARRAY_SIZE(lbtf_channels);
647 priv->band.channels = priv->channels;
648 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Deepak Saxenaf3233832010-02-09 13:35:43 -0800649 hw->wiphy->interface_modes =
650 BIT(NL80211_IFTYPE_STATION) |
651 BIT(NL80211_IFTYPE_ADHOC);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700652 skb_queue_head_init(&priv->bc_ps_buf);
653
654 SET_IEEE80211_DEV(hw, dmdev);
655
656 INIT_WORK(&priv->cmd_work, lbtf_cmd_work);
657 INIT_WORK(&priv->tx_work, lbtf_tx_work);
658 if (ieee80211_register_hw(hw))
659 goto err_init_adapter;
660
661 goto done;
662
663err_init_adapter:
664 lbtf_free_adapter(priv);
665 ieee80211_free_hw(hw);
666 priv = NULL;
667
668done:
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700669 lbtf_deb_leave_args(LBTF_DEB_MAIN, "priv %p", priv);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700670 return priv;
671}
672EXPORT_SYMBOL_GPL(lbtf_add_card);
673
674
675int lbtf_remove_card(struct lbtf_private *priv)
676{
677 struct ieee80211_hw *hw = priv->hw;
678
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700679 lbtf_deb_enter(LBTF_DEB_MAIN);
680
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700681 priv->surpriseremoved = 1;
682 del_timer(&priv->command_timer);
683 lbtf_free_adapter(priv);
684 priv->hw = NULL;
685 ieee80211_unregister_hw(hw);
686 ieee80211_free_hw(hw);
687
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700688 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700689 return 0;
690}
691EXPORT_SYMBOL_GPL(lbtf_remove_card);
692
693void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail)
694{
695 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200696
697 ieee80211_tx_info_clear_status(info);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700698 /*
699 * Commented out, otherwise we never go beyond 1Mbit/s using mac80211
700 * default pid rc algorithm.
701 *
702 * info->status.retry_count = MRVL_DEFAULT_RETRIES - retrycnt;
703 */
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700704 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && !fail)
705 info->flags |= IEEE80211_TX_STAT_ACK;
706 skb_pull(priv->tx_skb, sizeof(struct txpd));
707 ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb);
708 priv->tx_skb = NULL;
709 if (!priv->skb_to_tx && skb_queue_empty(&priv->bc_ps_buf))
710 ieee80211_wake_queues(priv->hw);
711 else
712 queue_work(lbtf_wq, &priv->tx_work);
713}
714EXPORT_SYMBOL_GPL(lbtf_send_tx_feedback);
715
716void lbtf_bcn_sent(struct lbtf_private *priv)
717{
718 struct sk_buff *skb = NULL;
719
Johannes Berg05c914f2008-09-11 00:01:58 +0200720 if (priv->vif->type != NL80211_IFTYPE_AP)
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700721 return;
722
723 if (skb_queue_empty(&priv->bc_ps_buf)) {
Rusty Russell3db1cd52011-12-19 13:56:45 +0000724 bool tx_buff_bc = false;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700725
726 while ((skb = ieee80211_get_buffered_bc(priv->hw, priv->vif))) {
727 skb_queue_tail(&priv->bc_ps_buf, skb);
Rusty Russell3db1cd52011-12-19 13:56:45 +0000728 tx_buff_bc = true;
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700729 }
730 if (tx_buff_bc) {
731 ieee80211_stop_queues(priv->hw);
732 queue_work(lbtf_wq, &priv->tx_work);
733 }
734 }
735
736 skb = ieee80211_beacon_get(priv->hw, priv->vif);
737
738 if (skb) {
739 lbtf_beacon_set(priv, skb);
740 kfree_skb(skb);
741 }
742}
743EXPORT_SYMBOL_GPL(lbtf_bcn_sent);
744
745static int __init lbtf_init_module(void)
746{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700747 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700748 lbtf_wq = create_workqueue("libertastf");
749 if (lbtf_wq == NULL) {
750 printk(KERN_ERR "libertastf: couldn't create workqueue\n");
751 return -ENOMEM;
752 }
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700753 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700754 return 0;
755}
756
757static void __exit lbtf_exit_module(void)
758{
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700759 lbtf_deb_enter(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700760 destroy_workqueue(lbtf_wq);
Steve deRosiere9bd5bc2010-04-25 14:40:46 -0700761 lbtf_deb_leave(LBTF_DEB_MAIN);
Luis Carlos Cobo06b16ae2008-08-14 10:40:57 -0700762}
763
764module_init(lbtf_init_module);
765module_exit(lbtf_exit_module);
766
767MODULE_DESCRIPTION("Libertas WLAN Thinfirm Driver Library");
768MODULE_AUTHOR("Cozybit Inc.");
769MODULE_LICENSE("GPL");