net: remove interrupt.h inclusion from netdevice.h
[deliverable/linux.git] / drivers / net / wireless / libertas_tf / main.c
CommitLineData
06b16ae5
LCC
1/*
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 */
edfcba15
JL
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
a6b7a407 12#include <linux/hardirq.h>
5a0e3ad6
TH
13#include <linux/slab.h>
14
edfcba15 15#include <linux/etherdevice.h>
06b16ae5 16#include "libertas_tf.h"
06b16ae5
LCC
17
18#define DRIVER_RELEASE_VERSION "004.p0"
19/* thinfirm version: 5.132.X.pX */
20#define LBTF_FW_VER_MIN 0x05840300
21#define LBTF_FW_VER_MAX 0x0584ffff
22#define QOS_CONTROL_LEN 2
23
e9bd5bcd
S
24/* Module parameters */
25unsigned int lbtf_debug;
26EXPORT_SYMBOL_GPL(lbtf_debug);
27module_param_named(libertas_tf_debug, lbtf_debug, int, 0644);
28
29static const char lbtf_driver_version[] = "THINFIRM-USB8388-" DRIVER_RELEASE_VERSION
30#ifdef DEBUG
31 "-dbg"
32#endif
33 "";
34
06b16ae5
LCC
35struct workqueue_struct *lbtf_wq;
36
37static const struct ieee80211_channel lbtf_channels[] = {
38 { .center_freq = 2412, .hw_value = 1 },
39 { .center_freq = 2417, .hw_value = 2 },
40 { .center_freq = 2422, .hw_value = 3 },
41 { .center_freq = 2427, .hw_value = 4 },
42 { .center_freq = 2432, .hw_value = 5 },
43 { .center_freq = 2437, .hw_value = 6 },
44 { .center_freq = 2442, .hw_value = 7 },
45 { .center_freq = 2447, .hw_value = 8 },
46 { .center_freq = 2452, .hw_value = 9 },
47 { .center_freq = 2457, .hw_value = 10 },
48 { .center_freq = 2462, .hw_value = 11 },
49 { .center_freq = 2467, .hw_value = 12 },
50 { .center_freq = 2472, .hw_value = 13 },
51 { .center_freq = 2484, .hw_value = 14 },
52};
53
54/* This table contains the hardware specific values for the modulation rates. */
55static const struct ieee80211_rate lbtf_rates[] = {
56 { .bitrate = 10,
57 .hw_value = 0, },
58 { .bitrate = 20,
59 .hw_value = 1,
60 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
61 { .bitrate = 55,
62 .hw_value = 2,
63 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
64 { .bitrate = 110,
65 .hw_value = 3,
66 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
67 { .bitrate = 60,
68 .hw_value = 5,
69 .flags = 0 },
70 { .bitrate = 90,
71 .hw_value = 6,
72 .flags = 0 },
73 { .bitrate = 120,
74 .hw_value = 7,
75 .flags = 0 },
76 { .bitrate = 180,
77 .hw_value = 8,
78 .flags = 0 },
79 { .bitrate = 240,
80 .hw_value = 9,
81 .flags = 0 },
82 { .bitrate = 360,
83 .hw_value = 10,
84 .flags = 0 },
85 { .bitrate = 480,
86 .hw_value = 11,
87 .flags = 0 },
88 { .bitrate = 540,
89 .hw_value = 12,
90 .flags = 0 },
91};
92
93static void lbtf_cmd_work(struct work_struct *work)
94{
95 struct lbtf_private *priv = container_of(work, struct lbtf_private,
96 cmd_work);
e9bd5bcd
S
97
98 lbtf_deb_enter(LBTF_DEB_CMD);
99
06b16ae5
LCC
100 spin_lock_irq(&priv->driver_lock);
101 /* command response? */
102 if (priv->cmd_response_rxed) {
103 priv->cmd_response_rxed = 0;
104 spin_unlock_irq(&priv->driver_lock);
105 lbtf_process_rx_command(priv);
106 spin_lock_irq(&priv->driver_lock);
107 }
108
109 if (priv->cmd_timed_out && priv->cur_cmd) {
110 struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
111
112 if (++priv->nr_retries > 10) {
113 lbtf_complete_command(priv, cmdnode,
114 -ETIMEDOUT);
115 priv->nr_retries = 0;
116 } else {
117 priv->cur_cmd = NULL;
118
119 /* Stick it back at the _top_ of the pending
120 * queue for immediate resubmission */
121 list_add(&cmdnode->list, &priv->cmdpendingq);
122 }
123 }
124 priv->cmd_timed_out = 0;
125 spin_unlock_irq(&priv->driver_lock);
126
e9bd5bcd
S
127 if (!priv->fw_ready) {
128 lbtf_deb_leave_args(LBTF_DEB_CMD, "fw not ready");
06b16ae5 129 return;
e9bd5bcd
S
130 }
131
06b16ae5
LCC
132 /* Execute the next command */
133 if (!priv->cur_cmd)
134 lbtf_execute_next_command(priv);
e9bd5bcd
S
135
136 lbtf_deb_leave(LBTF_DEB_CMD);
06b16ae5
LCC
137}
138
139/**
140 * lbtf_setup_firmware: initialize firmware.
141 *
142 * @priv A pointer to struct lbtf_private structure
143 *
144 * Returns: 0 on success.
145 */
146static int lbtf_setup_firmware(struct lbtf_private *priv)
147{
148 int ret = -1;
149
e9bd5bcd 150 lbtf_deb_enter(LBTF_DEB_FW);
06b16ae5
LCC
151 /*
152 * Read priv address from HW
153 */
154 memset(priv->current_addr, 0xff, ETH_ALEN);
155 ret = lbtf_update_hw_spec(priv);
156 if (ret) {
157 ret = -1;
158 goto done;
159 }
160
161 lbtf_set_mac_control(priv);
162 lbtf_set_radio_control(priv);
163
164 ret = 0;
165done:
e9bd5bcd 166 lbtf_deb_leave_args(LBTF_DEB_FW, "ret: %d", ret);
06b16ae5
LCC
167 return ret;
168}
169
170/**
171 * This function handles the timeout of command sending.
172 * It will re-send the same command again.
173 */
174static void command_timer_fn(unsigned long data)
175{
176 struct lbtf_private *priv = (struct lbtf_private *)data;
177 unsigned long flags;
e9bd5bcd 178 lbtf_deb_enter(LBTF_DEB_CMD);
06b16ae5
LCC
179
180 spin_lock_irqsave(&priv->driver_lock, flags);
181
182 if (!priv->cur_cmd) {
183 printk(KERN_DEBUG "libertastf: command timer expired; "
184 "no pending command\n");
185 goto out;
186 }
187
188 printk(KERN_DEBUG "libertas: command %x timed out\n",
189 le16_to_cpu(priv->cur_cmd->cmdbuf->command));
190
191 priv->cmd_timed_out = 1;
192 queue_work(lbtf_wq, &priv->cmd_work);
193out:
194 spin_unlock_irqrestore(&priv->driver_lock, flags);
e9bd5bcd 195 lbtf_deb_leave(LBTF_DEB_CMD);
06b16ae5
LCC
196}
197
198static int lbtf_init_adapter(struct lbtf_private *priv)
199{
e9bd5bcd 200 lbtf_deb_enter(LBTF_DEB_MAIN);
06b16ae5
LCC
201 memset(priv->current_addr, 0xff, ETH_ALEN);
202 mutex_init(&priv->lock);
203
204 priv->vif = NULL;
205 setup_timer(&priv->command_timer, command_timer_fn,
206 (unsigned long)priv);
207
208 INIT_LIST_HEAD(&priv->cmdfreeq);
209 INIT_LIST_HEAD(&priv->cmdpendingq);
210
211 spin_lock_init(&priv->driver_lock);
212
213 /* Allocate the command buffers */
214 if (lbtf_allocate_cmd_buffer(priv))
215 return -1;
216
e9bd5bcd 217 lbtf_deb_leave(LBTF_DEB_MAIN);
06b16ae5
LCC
218 return 0;
219}
220
221static void lbtf_free_adapter(struct lbtf_private *priv)
222{
e9bd5bcd 223 lbtf_deb_enter(LBTF_DEB_MAIN);
06b16ae5
LCC
224 lbtf_free_cmd_buffer(priv);
225 del_timer(&priv->command_timer);
e9bd5bcd 226 lbtf_deb_leave(LBTF_DEB_MAIN);
06b16ae5
LCC
227}
228
7bb45683 229static void lbtf_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
06b16ae5
LCC
230{
231 struct lbtf_private *priv = hw->priv;
232
233 priv->skb_to_tx = skb;
234 queue_work(lbtf_wq, &priv->tx_work);
235 /*
236 * queue will be restarted when we receive transmission feedback if
237 * there are no buffered multicast frames to send
238 */
239 ieee80211_stop_queues(priv->hw);
06b16ae5
LCC
240}
241
242static void lbtf_tx_work(struct work_struct *work)
243{
244 struct lbtf_private *priv = container_of(work, struct lbtf_private,
245 tx_work);
246 unsigned int len;
247 struct ieee80211_tx_info *info;
248 struct txpd *txpd;
249 struct sk_buff *skb = NULL;
250 int err;
251
e9bd5bcd
S
252 lbtf_deb_enter(LBTF_DEB_MACOPS | LBTF_DEB_TX);
253
05c914fe 254 if ((priv->vif->type == NL80211_IFTYPE_AP) &&
06b16ae5
LCC
255 (!skb_queue_empty(&priv->bc_ps_buf)))
256 skb = skb_dequeue(&priv->bc_ps_buf);
257 else if (priv->skb_to_tx) {
258 skb = priv->skb_to_tx;
259 priv->skb_to_tx = NULL;
e9bd5bcd
S
260 } else {
261 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
06b16ae5 262 return;
e9bd5bcd 263 }
06b16ae5
LCC
264
265 len = skb->len;
266 info = IEEE80211_SKB_CB(skb);
267 txpd = (struct txpd *) skb_push(skb, sizeof(struct txpd));
268
269 if (priv->surpriseremoved) {
270 dev_kfree_skb_any(skb);
e9bd5bcd 271 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
06b16ae5
LCC
272 return;
273 }
274
275 memset(txpd, 0, sizeof(struct txpd));
276 /* Activate per-packet rate selection */
277 txpd->tx_control |= cpu_to_le32(MRVL_PER_PACKET_RATE |
278 ieee80211_get_tx_rate(priv->hw, info)->hw_value);
279
280 /* copy destination address from 802.11 header */
281 memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
282 ETH_ALEN);
283 txpd->tx_packet_length = cpu_to_le16(len);
284 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
e9bd5bcd 285 lbtf_deb_hex(LBTF_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
06b16ae5
LCC
286 BUG_ON(priv->tx_skb);
287 spin_lock_irq(&priv->driver_lock);
288 priv->tx_skb = skb;
289 err = priv->hw_host_to_card(priv, MVMS_DAT, skb->data, skb->len);
290 spin_unlock_irq(&priv->driver_lock);
291 if (err) {
292 dev_kfree_skb_any(skb);
293 priv->tx_skb = NULL;
e9bd5bcd 294 pr_err("TX error: %d", err);
06b16ae5 295 }
e9bd5bcd 296 lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
06b16ae5
LCC
297}
298
299static int lbtf_op_start(struct ieee80211_hw *hw)
300{
301 struct lbtf_private *priv = hw->priv;
302 void *card = priv->card;
303 int ret = -1;
304
e9bd5bcd
S
305 lbtf_deb_enter(LBTF_DEB_MACOPS);
306
06b16ae5
LCC
307 if (!priv->fw_ready)
308 /* Upload firmware */
309 if (priv->hw_prog_firmware(card))
310 goto err_prog_firmware;
311
312 /* poke the firmware */
313 priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
314 priv->radioon = RADIO_ON;
315 priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
316 ret = lbtf_setup_firmware(priv);
317 if (ret)
318 goto err_prog_firmware;
319
320 if ((priv->fwrelease < LBTF_FW_VER_MIN) ||
321 (priv->fwrelease > LBTF_FW_VER_MAX)) {
322 ret = -1;
323 goto err_prog_firmware;
324 }
325
326 printk(KERN_INFO "libertastf: Marvell WLAN 802.11 thinfirm adapter\n");
e9bd5bcd 327 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
328 return 0;
329
330err_prog_firmware:
331 priv->hw_reset_device(card);
e9bd5bcd 332 lbtf_deb_leave_args(LBTF_DEB_MACOPS, "error programing fw; ret=%d", ret);
06b16ae5
LCC
333 return ret;
334}
335
336static void lbtf_op_stop(struct ieee80211_hw *hw)
337{
338 struct lbtf_private *priv = hw->priv;
339 unsigned long flags;
340 struct sk_buff *skb;
341
342 struct cmd_ctrl_node *cmdnode;
e9bd5bcd
S
343
344 lbtf_deb_enter(LBTF_DEB_MACOPS);
345
06b16ae5
LCC
346 /* Flush pending command nodes */
347 spin_lock_irqsave(&priv->driver_lock, flags);
348 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
349 cmdnode->result = -ENOENT;
350 cmdnode->cmdwaitqwoken = 1;
351 wake_up_interruptible(&cmdnode->cmdwait_q);
352 }
353
354 spin_unlock_irqrestore(&priv->driver_lock, flags);
355 cancel_work_sync(&priv->cmd_work);
356 cancel_work_sync(&priv->tx_work);
357 while ((skb = skb_dequeue(&priv->bc_ps_buf)))
358 dev_kfree_skb_any(skb);
359 priv->radioon = RADIO_OFF;
360 lbtf_set_radio_control(priv);
361
e9bd5bcd 362 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
363}
364
365static int lbtf_op_add_interface(struct ieee80211_hw *hw,
1ed32e4f 366 struct ieee80211_vif *vif)
06b16ae5
LCC
367{
368 struct lbtf_private *priv = hw->priv;
e9bd5bcd 369 lbtf_deb_enter(LBTF_DEB_MACOPS);
06b16ae5
LCC
370 if (priv->vif != NULL)
371 return -EOPNOTSUPP;
372
1ed32e4f
JB
373 priv->vif = vif;
374 switch (vif->type) {
05c914fe
JB
375 case NL80211_IFTYPE_MESH_POINT:
376 case NL80211_IFTYPE_AP:
06b16ae5
LCC
377 lbtf_set_mode(priv, LBTF_AP_MODE);
378 break;
05c914fe 379 case NL80211_IFTYPE_STATION:
06b16ae5
LCC
380 lbtf_set_mode(priv, LBTF_STA_MODE);
381 break;
382 default:
383 priv->vif = NULL;
384 return -EOPNOTSUPP;
385 }
1ed32e4f 386 lbtf_set_mac_address(priv, (u8 *) vif->addr);
e9bd5bcd 387 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
388 return 0;
389}
390
391static void lbtf_op_remove_interface(struct ieee80211_hw *hw,
1ed32e4f 392 struct ieee80211_vif *vif)
06b16ae5
LCC
393{
394 struct lbtf_private *priv = hw->priv;
e9bd5bcd 395 lbtf_deb_enter(LBTF_DEB_MACOPS);
06b16ae5 396
05c914fe
JB
397 if (priv->vif->type == NL80211_IFTYPE_AP ||
398 priv->vif->type == NL80211_IFTYPE_MESH_POINT)
06b16ae5
LCC
399 lbtf_beacon_ctrl(priv, 0, 0);
400 lbtf_set_mode(priv, LBTF_PASSIVE_MODE);
401 lbtf_set_bssid(priv, 0, NULL);
402 priv->vif = NULL;
e9bd5bcd 403 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
404}
405
e8975581 406static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
06b16ae5
LCC
407{
408 struct lbtf_private *priv = hw->priv;
e8975581 409 struct ieee80211_conf *conf = &hw->conf;
e9bd5bcd 410 lbtf_deb_enter(LBTF_DEB_MACOPS);
e8975581 411
06b16ae5
LCC
412 if (conf->channel->center_freq != priv->cur_freq) {
413 priv->cur_freq = conf->channel->center_freq;
414 lbtf_set_channel(priv, conf->channel->hw_value);
415 }
e9bd5bcd 416 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
417 return 0;
418}
419
3ac64bee 420static u64 lbtf_op_prepare_multicast(struct ieee80211_hw *hw,
22bedad3 421 struct netdev_hw_addr_list *mc_list)
3ac64bee
JB
422{
423 struct lbtf_private *priv = hw->priv;
424 int i;
22bedad3
JP
425 struct netdev_hw_addr *ha;
426 int mc_count = netdev_hw_addr_list_count(mc_list);
3ac64bee
JB
427
428 if (!mc_count || mc_count > MRVDRV_MAX_MULTICAST_LIST_SIZE)
429 return mc_count;
430
431 priv->nr_of_multicastmacaddr = mc_count;
22bedad3
JP
432 i = 0;
433 netdev_hw_addr_list_for_each(ha, mc_list)
434 memcpy(&priv->multicastlist[i++], ha->addr, ETH_ALEN);
3ac64bee
JB
435
436 return mc_count;
437}
438
06b16ae5
LCC
439#define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)
440static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
441 unsigned int changed_flags,
442 unsigned int *new_flags,
3ac64bee 443 u64 multicast)
06b16ae5
LCC
444{
445 struct lbtf_private *priv = hw->priv;
446 int old_mac_control = priv->mac_control;
e9bd5bcd
S
447
448 lbtf_deb_enter(LBTF_DEB_MACOPS);
449
06b16ae5
LCC
450 changed_flags &= SUPPORTED_FIF_FLAGS;
451 *new_flags &= SUPPORTED_FIF_FLAGS;
452
e9bd5bcd
S
453 if (!changed_flags) {
454 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5 455 return;
e9bd5bcd 456 }
06b16ae5
LCC
457
458 if (*new_flags & (FIF_PROMISC_IN_BSS))
459 priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
460 else
461 priv->mac_control &= ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
462 if (*new_flags & (FIF_ALLMULTI) ||
3ac64bee 463 multicast > MRVDRV_MAX_MULTICAST_LIST_SIZE) {
06b16ae5
LCC
464 priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
465 priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
3ac64bee 466 } else if (multicast) {
06b16ae5
LCC
467 priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
468 priv->mac_control &= ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
06b16ae5
LCC
469 lbtf_cmd_set_mac_multicast_addr(priv);
470 } else {
471 priv->mac_control &= ~(CMD_ACT_MAC_MULTICAST_ENABLE |
472 CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
473 if (priv->nr_of_multicastmacaddr) {
474 priv->nr_of_multicastmacaddr = 0;
475 lbtf_cmd_set_mac_multicast_addr(priv);
476 }
477 }
478
479
480 if (priv->mac_control != old_mac_control)
481 lbtf_set_mac_control(priv);
e9bd5bcd
S
482
483 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
484}
485
486static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
487 struct ieee80211_vif *vif,
488 struct ieee80211_bss_conf *bss_conf,
489 u32 changes)
490{
491 struct lbtf_private *priv = hw->priv;
2d0ddec5 492 struct sk_buff *beacon;
e9bd5bcd 493 lbtf_deb_enter(LBTF_DEB_MACOPS);
2d0ddec5
JB
494
495 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
496 switch (priv->vif->type) {
497 case NL80211_IFTYPE_AP:
498 case NL80211_IFTYPE_MESH_POINT:
499 beacon = ieee80211_beacon_get(hw, vif);
500 if (beacon) {
501 lbtf_beacon_set(priv, beacon);
502 kfree_skb(beacon);
503 lbtf_beacon_ctrl(priv, 1,
504 bss_conf->beacon_int);
505 }
506 break;
507 default:
508 break;
509 }
510 }
511
512 if (changes & BSS_CHANGED_BSSID) {
513 bool activate = !is_zero_ether_addr(bss_conf->bssid);
514 lbtf_set_bssid(priv, activate, bss_conf->bssid);
515 }
06b16ae5
LCC
516
517 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
518 if (bss_conf->use_short_preamble)
519 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
520 else
521 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
522 lbtf_set_radio_control(priv);
523 }
e9bd5bcd
S
524
525 lbtf_deb_leave(LBTF_DEB_MACOPS);
06b16ae5
LCC
526}
527
bef9cb58
JL
528static int lbtf_op_get_survey(struct ieee80211_hw *hw, int idx,
529 struct survey_info *survey)
530{
531 struct lbtf_private *priv = hw->priv;
532 struct ieee80211_conf *conf = &hw->conf;
533
534 if (idx != 0)
535 return -ENOENT;
536
537 survey->channel = conf->channel;
538 survey->filled = SURVEY_INFO_NOISE_DBM;
539 survey->noise = priv->noise;
540
541 return 0;
542}
543
06b16ae5
LCC
544static const struct ieee80211_ops lbtf_ops = {
545 .tx = lbtf_op_tx,
546 .start = lbtf_op_start,
547 .stop = lbtf_op_stop,
548 .add_interface = lbtf_op_add_interface,
549 .remove_interface = lbtf_op_remove_interface,
550 .config = lbtf_op_config,
3ac64bee 551 .prepare_multicast = lbtf_op_prepare_multicast,
06b16ae5
LCC
552 .configure_filter = lbtf_op_configure_filter,
553 .bss_info_changed = lbtf_op_bss_info_changed,
bef9cb58 554 .get_survey = lbtf_op_get_survey,
06b16ae5
LCC
555};
556
557int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
558{
559 struct ieee80211_rx_status stats;
560 struct rxpd *prxpd;
de9cc7a4 561 int need_padding;
06b16ae5 562 unsigned int flags;
de9cc7a4 563 struct ieee80211_hdr *hdr;
06b16ae5 564
e9bd5bcd
S
565 lbtf_deb_enter(LBTF_DEB_RX);
566
06b16ae5
LCC
567 prxpd = (struct rxpd *) skb->data;
568
13deb23a 569 memset(&stats, 0, sizeof(stats));
06b16ae5
LCC
570 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
571 stats.flag |= RX_FLAG_FAILED_FCS_CRC;
572 stats.freq = priv->cur_freq;
573 stats.band = IEEE80211_BAND_2GHZ;
574 stats.signal = prxpd->snr;
bef9cb58 575 priv->noise = prxpd->nf;
06b16ae5
LCC
576 /* Marvell rate index has a hole at value 4 */
577 if (prxpd->rx_rate > 4)
578 --prxpd->rx_rate;
579 stats.rate_idx = prxpd->rx_rate;
580 skb_pull(skb, sizeof(struct rxpd));
581
de9cc7a4 582 hdr = (struct ieee80211_hdr *)skb->data;
06b16ae5
LCC
583 flags = le32_to_cpu(*(__le32 *)(skb->data + 4));
584
de9cc7a4
HH
585 need_padding = ieee80211_is_data_qos(hdr->frame_control);
586 need_padding ^= ieee80211_has_a4(hdr->frame_control);
587 need_padding ^= ieee80211_is_data_qos(hdr->frame_control) &&
588 (*ieee80211_get_qos_ctl(hdr) &
589 IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
06b16ae5 590
06b16ae5
LCC
591 if (need_padding) {
592 memmove(skb->data + 2, skb->data, skb->len);
593 skb_reserve(skb, 2);
594 }
595
f1d58c25 596 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
e9bd5bcd
S
597
598 lbtf_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
599 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
600 lbtf_deb_hex(LBTF_DEB_RX, "RX Data", skb->data,
601 min_t(unsigned int, skb->len, 100));
602
f1d58c25 603 ieee80211_rx_irqsafe(priv->hw, skb);
e9bd5bcd
S
604
605 lbtf_deb_leave(LBTF_DEB_RX);
06b16ae5
LCC
606 return 0;
607}
608EXPORT_SYMBOL_GPL(lbtf_rx);
609
610/**
611 * lbtf_add_card: Add and initialize the card, no fw upload yet.
612 *
613 * @card A pointer to card
614 *
615 * Returns: pointer to struct lbtf_priv.
616 */
617struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev)
618{
619 struct ieee80211_hw *hw;
620 struct lbtf_private *priv = NULL;
621
e9bd5bcd
S
622 lbtf_deb_enter(LBTF_DEB_MAIN);
623
06b16ae5
LCC
624 hw = ieee80211_alloc_hw(sizeof(struct lbtf_private), &lbtf_ops);
625 if (!hw)
626 goto done;
627
628 priv = hw->priv;
629 if (lbtf_init_adapter(priv))
630 goto err_init_adapter;
631
632 priv->hw = hw;
633 priv->card = card;
634 priv->tx_skb = NULL;
635
636 hw->queues = 1;
637 hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
638 hw->extra_tx_headroom = sizeof(struct txpd);
639 memcpy(priv->channels, lbtf_channels, sizeof(lbtf_channels));
640 memcpy(priv->rates, lbtf_rates, sizeof(lbtf_rates));
641 priv->band.n_bitrates = ARRAY_SIZE(lbtf_rates);
642 priv->band.bitrates = priv->rates;
643 priv->band.n_channels = ARRAY_SIZE(lbtf_channels);
644 priv->band.channels = priv->channels;
645 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
f3233831
DS
646 hw->wiphy->interface_modes =
647 BIT(NL80211_IFTYPE_STATION) |
648 BIT(NL80211_IFTYPE_ADHOC);
06b16ae5
LCC
649 skb_queue_head_init(&priv->bc_ps_buf);
650
651 SET_IEEE80211_DEV(hw, dmdev);
652
653 INIT_WORK(&priv->cmd_work, lbtf_cmd_work);
654 INIT_WORK(&priv->tx_work, lbtf_tx_work);
655 if (ieee80211_register_hw(hw))
656 goto err_init_adapter;
657
658 goto done;
659
660err_init_adapter:
661 lbtf_free_adapter(priv);
662 ieee80211_free_hw(hw);
663 priv = NULL;
664
665done:
e9bd5bcd 666 lbtf_deb_leave_args(LBTF_DEB_MAIN, "priv %p", priv);
06b16ae5
LCC
667 return priv;
668}
669EXPORT_SYMBOL_GPL(lbtf_add_card);
670
671
672int lbtf_remove_card(struct lbtf_private *priv)
673{
674 struct ieee80211_hw *hw = priv->hw;
675
e9bd5bcd
S
676 lbtf_deb_enter(LBTF_DEB_MAIN);
677
06b16ae5
LCC
678 priv->surpriseremoved = 1;
679 del_timer(&priv->command_timer);
680 lbtf_free_adapter(priv);
681 priv->hw = NULL;
682 ieee80211_unregister_hw(hw);
683 ieee80211_free_hw(hw);
684
e9bd5bcd 685 lbtf_deb_leave(LBTF_DEB_MAIN);
06b16ae5
LCC
686 return 0;
687}
688EXPORT_SYMBOL_GPL(lbtf_remove_card);
689
690void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail)
691{
692 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb);
e6a9854b
JB
693
694 ieee80211_tx_info_clear_status(info);
06b16ae5
LCC
695 /*
696 * Commented out, otherwise we never go beyond 1Mbit/s using mac80211
697 * default pid rc algorithm.
698 *
699 * info->status.retry_count = MRVL_DEFAULT_RETRIES - retrycnt;
700 */
06b16ae5
LCC
701 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && !fail)
702 info->flags |= IEEE80211_TX_STAT_ACK;
703 skb_pull(priv->tx_skb, sizeof(struct txpd));
704 ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb);
705 priv->tx_skb = NULL;
706 if (!priv->skb_to_tx && skb_queue_empty(&priv->bc_ps_buf))
707 ieee80211_wake_queues(priv->hw);
708 else
709 queue_work(lbtf_wq, &priv->tx_work);
710}
711EXPORT_SYMBOL_GPL(lbtf_send_tx_feedback);
712
713void lbtf_bcn_sent(struct lbtf_private *priv)
714{
715 struct sk_buff *skb = NULL;
716
05c914fe 717 if (priv->vif->type != NL80211_IFTYPE_AP)
06b16ae5
LCC
718 return;
719
720 if (skb_queue_empty(&priv->bc_ps_buf)) {
721 bool tx_buff_bc = 0;
722
723 while ((skb = ieee80211_get_buffered_bc(priv->hw, priv->vif))) {
724 skb_queue_tail(&priv->bc_ps_buf, skb);
725 tx_buff_bc = 1;
726 }
727 if (tx_buff_bc) {
728 ieee80211_stop_queues(priv->hw);
729 queue_work(lbtf_wq, &priv->tx_work);
730 }
731 }
732
733 skb = ieee80211_beacon_get(priv->hw, priv->vif);
734
735 if (skb) {
736 lbtf_beacon_set(priv, skb);
737 kfree_skb(skb);
738 }
739}
740EXPORT_SYMBOL_GPL(lbtf_bcn_sent);
741
742static int __init lbtf_init_module(void)
743{
e9bd5bcd 744 lbtf_deb_enter(LBTF_DEB_MAIN);
06b16ae5
LCC
745 lbtf_wq = create_workqueue("libertastf");
746 if (lbtf_wq == NULL) {
747 printk(KERN_ERR "libertastf: couldn't create workqueue\n");
748 return -ENOMEM;
749 }
e9bd5bcd 750 lbtf_deb_leave(LBTF_DEB_MAIN);
06b16ae5
LCC
751 return 0;
752}
753
754static void __exit lbtf_exit_module(void)
755{
e9bd5bcd 756 lbtf_deb_enter(LBTF_DEB_MAIN);
06b16ae5 757 destroy_workqueue(lbtf_wq);
e9bd5bcd 758 lbtf_deb_leave(LBTF_DEB_MAIN);
06b16ae5
LCC
759}
760
761module_init(lbtf_init_module);
762module_exit(lbtf_exit_module);
763
764MODULE_DESCRIPTION("Libertas WLAN Thinfirm Driver Library");
765MODULE_AUTHOR("Cozybit Inc.");
766MODULE_LICENSE("GPL");
This page took 0.362608 seconds and 5 git commands to generate.