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