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