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