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