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