2 * mac80211 glue code for mac80211 Prism54 drivers
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
19 #include <linux/init.h>
20 #include <linux/firmware.h>
21 #include <linux/etherdevice.h>
23 #include <net/mac80211.h>
28 static int modparam_nohwcrypt
;
29 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, S_IRUGO
);
30 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
31 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
32 MODULE_DESCRIPTION("Softmac Prism54 common code");
33 MODULE_LICENSE("GPL");
34 MODULE_ALIAS("prism54common");
36 static int p54_sta_add_remove(struct ieee80211_hw
*hw
,
37 struct ieee80211_vif
*vif
,
38 struct ieee80211_sta
*sta
)
40 struct p54_common
*priv
= hw
->priv
;
43 * Notify the firmware that we don't want or we don't
44 * need to buffer frames for this station anymore.
47 p54_sta_unlock(priv
, sta
->addr
);
52 static void p54_sta_notify(struct ieee80211_hw
*dev
, struct ieee80211_vif
*vif
,
53 enum sta_notify_cmd notify_cmd
,
54 struct ieee80211_sta
*sta
)
56 struct p54_common
*priv
= dev
->priv
;
59 case STA_NOTIFY_AWAKE
:
60 /* update the firmware's filter table */
61 p54_sta_unlock(priv
, sta
->addr
);
68 static int p54_set_tim(struct ieee80211_hw
*dev
, struct ieee80211_sta
*sta
,
71 struct p54_common
*priv
= dev
->priv
;
73 return p54_update_beacon_tim(priv
, sta
->aid
, set
);
76 u8
*p54_find_ie(struct sk_buff
*skb
, u8 ie
)
78 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
81 if (skb
->len
<= sizeof(mgmt
))
84 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
85 end
= skb
->data
+ skb
->len
;
87 if (pos
+ 2 + pos
[1] > end
)
98 static int p54_beacon_format_ie_tim(struct sk_buff
*skb
)
101 * the good excuse for this mess is ... the firmware.
102 * The dummy TIM MUST be at the end of the beacon frame,
103 * because it'll be overwritten!
110 tim
= p54_find_ie(skb
, WLAN_EID_TIM
);
115 dtim_period
= tim
[3];
116 next
= tim
+ 2 + dtim_len
;
121 memmove(tim
, next
, skb_tail_pointer(skb
) - next
);
122 tim
= skb_tail_pointer(skb
) - (dtim_len
+ 2);
124 /* add the dummy at the end */
125 tim
[0] = WLAN_EID_TIM
;
128 tim
[3] = dtim_period
;
132 skb_trim(skb
, skb
->len
- (dtim_len
- 3));
137 static int p54_beacon_update(struct p54_common
*priv
,
138 struct ieee80211_vif
*vif
)
140 struct sk_buff
*beacon
;
143 beacon
= ieee80211_beacon_get(priv
->hw
, vif
);
146 ret
= p54_beacon_format_ie_tim(beacon
);
151 * During operation, the firmware takes care of beaconing.
152 * The driver only needs to upload a new beacon template, once
153 * the template was changed by the stack or userspace.
155 * LMAC API 3.2.2 also specifies that the driver does not need
156 * to cancel the old beacon template by hand, instead the firmware
157 * will release the previous one through the feedback mechanism.
159 WARN_ON(p54_tx_80211(priv
->hw
, beacon
));
160 priv
->tsf_high32
= 0;
166 static int p54_start(struct ieee80211_hw
*dev
)
168 struct p54_common
*priv
= dev
->priv
;
171 mutex_lock(&priv
->conf_mutex
);
172 err
= priv
->open(dev
);
175 P54_SET_QUEUE(priv
->qos_params
[0], 0x0002, 0x0003, 0x0007, 47);
176 P54_SET_QUEUE(priv
->qos_params
[1], 0x0002, 0x0007, 0x000f, 94);
177 P54_SET_QUEUE(priv
->qos_params
[2], 0x0003, 0x000f, 0x03ff, 0);
178 P54_SET_QUEUE(priv
->qos_params
[3], 0x0007, 0x000f, 0x03ff, 0);
179 err
= p54_set_edcf(priv
);
183 memset(priv
->bssid
, ~0, ETH_ALEN
);
184 priv
->mode
= NL80211_IFTYPE_MONITOR
;
185 err
= p54_setup_mac(priv
);
187 priv
->mode
= NL80211_IFTYPE_UNSPECIFIED
;
191 ieee80211_queue_delayed_work(dev
, &priv
->work
, 0);
193 priv
->softled_state
= 0;
194 err
= p54_set_leds(priv
);
197 mutex_unlock(&priv
->conf_mutex
);
201 static void p54_stop(struct ieee80211_hw
*dev
)
203 struct p54_common
*priv
= dev
->priv
;
206 mutex_lock(&priv
->conf_mutex
);
207 priv
->mode
= NL80211_IFTYPE_UNSPECIFIED
;
208 priv
->softled_state
= 0;
211 cancel_delayed_work_sync(&priv
->work
);
214 skb_queue_purge(&priv
->tx_pending
);
215 skb_queue_purge(&priv
->tx_queue
);
216 for (i
= 0; i
< P54_QUEUE_NUM
; i
++) {
217 priv
->tx_stats
[i
].count
= 0;
218 priv
->tx_stats
[i
].len
= 0;
221 priv
->beacon_req_id
= cpu_to_le32(0);
222 priv
->tsf_high32
= priv
->tsf_low32
= 0;
223 mutex_unlock(&priv
->conf_mutex
);
226 static int p54_add_interface(struct ieee80211_hw
*dev
,
227 struct ieee80211_vif
*vif
)
229 struct p54_common
*priv
= dev
->priv
;
231 mutex_lock(&priv
->conf_mutex
);
232 if (priv
->mode
!= NL80211_IFTYPE_MONITOR
) {
233 mutex_unlock(&priv
->conf_mutex
);
240 case NL80211_IFTYPE_STATION
:
241 case NL80211_IFTYPE_ADHOC
:
242 case NL80211_IFTYPE_AP
:
243 case NL80211_IFTYPE_MESH_POINT
:
244 priv
->mode
= vif
->type
;
247 mutex_unlock(&priv
->conf_mutex
);
251 memcpy(priv
->mac_addr
, vif
->addr
, ETH_ALEN
);
253 mutex_unlock(&priv
->conf_mutex
);
257 static void p54_remove_interface(struct ieee80211_hw
*dev
,
258 struct ieee80211_vif
*vif
)
260 struct p54_common
*priv
= dev
->priv
;
262 mutex_lock(&priv
->conf_mutex
);
266 * LMAC API 3.2.2 states that any active beacon template must be
267 * canceled by the driver before attempting a mode transition.
269 if (le32_to_cpu(priv
->beacon_req_id
) != 0) {
270 p54_tx_cancel(priv
, priv
->beacon_req_id
);
271 wait_for_completion_interruptible_timeout(&priv
->beacon_comp
, HZ
);
273 priv
->mode
= NL80211_IFTYPE_MONITOR
;
274 memset(priv
->mac_addr
, 0, ETH_ALEN
);
275 memset(priv
->bssid
, 0, ETH_ALEN
);
277 mutex_unlock(&priv
->conf_mutex
);
280 static int p54_config(struct ieee80211_hw
*dev
, u32 changed
)
283 struct p54_common
*priv
= dev
->priv
;
284 struct ieee80211_conf
*conf
= &dev
->conf
;
286 mutex_lock(&priv
->conf_mutex
);
287 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
288 priv
->output_power
= conf
->power_level
<< 2;
289 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
290 ret
= p54_scan(priv
, P54_SCAN_EXIT
, 0);
294 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
295 ret
= p54_set_ps(priv
);
299 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
300 ret
= p54_setup_mac(priv
);
306 mutex_unlock(&priv
->conf_mutex
);
310 static void p54_configure_filter(struct ieee80211_hw
*dev
,
311 unsigned int changed_flags
,
312 unsigned int *total_flags
,
315 struct p54_common
*priv
= dev
->priv
;
317 *total_flags
&= FIF_PROMISC_IN_BSS
|
320 priv
->filter_flags
= *total_flags
;
322 if (changed_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
))
326 static int p54_conf_tx(struct ieee80211_hw
*dev
, u16 queue
,
327 const struct ieee80211_tx_queue_params
*params
)
329 struct p54_common
*priv
= dev
->priv
;
332 mutex_lock(&priv
->conf_mutex
);
333 if (queue
< dev
->queues
) {
334 P54_SET_QUEUE(priv
->qos_params
[queue
], params
->aifs
,
335 params
->cw_min
, params
->cw_max
, params
->txop
);
336 ret
= p54_set_edcf(priv
);
339 mutex_unlock(&priv
->conf_mutex
);
343 static void p54_work(struct work_struct
*work
)
345 struct p54_common
*priv
= container_of(work
, struct p54_common
,
348 if (unlikely(priv
->mode
== NL80211_IFTYPE_UNSPECIFIED
))
352 * TODO: walk through tx_queue and do the following tasks
353 * 1. initiate bursts.
354 * 2. cancel stuck frames / reset the device if necessary.
357 p54_fetch_statistics(priv
);
360 static int p54_get_stats(struct ieee80211_hw
*dev
,
361 struct ieee80211_low_level_stats
*stats
)
363 struct p54_common
*priv
= dev
->priv
;
365 memcpy(stats
, &priv
->stats
, sizeof(*stats
));
369 static void p54_bss_info_changed(struct ieee80211_hw
*dev
,
370 struct ieee80211_vif
*vif
,
371 struct ieee80211_bss_conf
*info
,
374 struct p54_common
*priv
= dev
->priv
;
376 mutex_lock(&priv
->conf_mutex
);
377 if (changed
& BSS_CHANGED_BSSID
) {
378 memcpy(priv
->bssid
, info
->bssid
, ETH_ALEN
);
382 if (changed
& BSS_CHANGED_BEACON
) {
383 p54_scan(priv
, P54_SCAN_EXIT
, 0);
385 p54_beacon_update(priv
, vif
);
389 if (changed
& (BSS_CHANGED_ERP_SLOT
| BSS_CHANGED_BEACON
)) {
390 priv
->use_short_slot
= info
->use_short_slot
;
393 if (changed
& BSS_CHANGED_BASIC_RATES
) {
394 if (dev
->conf
.channel
->band
== IEEE80211_BAND_5GHZ
)
395 priv
->basic_rate_mask
= (info
->basic_rates
<< 4);
397 priv
->basic_rate_mask
= info
->basic_rates
;
399 if (priv
->fw_var
>= 0x500)
400 p54_scan(priv
, P54_SCAN_EXIT
, 0);
402 if (changed
& BSS_CHANGED_ASSOC
) {
404 priv
->aid
= info
->aid
;
405 priv
->wakeup_timer
= info
->beacon_int
*
406 info
->dtim_period
* 5;
409 priv
->wakeup_timer
= 500;
414 mutex_unlock(&priv
->conf_mutex
);
417 static int p54_set_key(struct ieee80211_hw
*dev
, enum set_key_cmd cmd
,
418 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
419 struct ieee80211_key_conf
*key
)
421 struct p54_common
*priv
= dev
->priv
;
426 if (modparam_nohwcrypt
)
429 mutex_lock(&priv
->conf_mutex
);
430 if (cmd
== SET_KEY
) {
433 if (!(priv
->privacy_caps
& (BR_DESC_PRIV_CAP_MICHAEL
|
434 BR_DESC_PRIV_CAP_TKIP
))) {
438 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
439 algo
= P54_CRYPTO_TKIPMICHAEL
;
442 if (!(priv
->privacy_caps
& BR_DESC_PRIV_CAP_WEP
)) {
446 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
447 algo
= P54_CRYPTO_WEP
;
450 if (!(priv
->privacy_caps
& BR_DESC_PRIV_CAP_AESCCMP
)) {
454 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
455 algo
= P54_CRYPTO_AESCCMP
;
461 slot
= bitmap_find_free_region(priv
->used_rxkeys
,
462 priv
->rx_keycache_size
, 0);
466 * The device supports the choosen algorithm, but the
467 * firmware does not provide enough key slots to store
469 * But encryption offload for outgoing frames is always
470 * possible, so we just pretend that the upload was
471 * successful and do the decryption in software.
474 /* mark the key as invalid. */
475 key
->hw_key_idx
= 0xff;
479 slot
= key
->hw_key_idx
;
482 /* This key was not uploaded into the rx key cache. */
487 bitmap_release_region(priv
->used_rxkeys
, slot
, 0);
494 ret
= p54_upload_key(priv
, algo
, slot
, key
->keyidx
,
495 key
->keylen
, addr
, key
->key
);
497 bitmap_release_region(priv
->used_rxkeys
, slot
, 0);
502 key
->hw_key_idx
= slot
;
505 mutex_unlock(&priv
->conf_mutex
);
509 static const struct ieee80211_ops p54_ops
= {
513 .add_interface
= p54_add_interface
,
514 .remove_interface
= p54_remove_interface
,
515 .set_tim
= p54_set_tim
,
516 .sta_notify
= p54_sta_notify
,
517 .sta_add
= p54_sta_add_remove
,
518 .sta_remove
= p54_sta_add_remove
,
519 .set_key
= p54_set_key
,
520 .config
= p54_config
,
521 .bss_info_changed
= p54_bss_info_changed
,
522 .configure_filter
= p54_configure_filter
,
523 .conf_tx
= p54_conf_tx
,
524 .get_stats
= p54_get_stats
,
527 struct ieee80211_hw
*p54_init_common(size_t priv_data_len
)
529 struct ieee80211_hw
*dev
;
530 struct p54_common
*priv
;
532 dev
= ieee80211_alloc_hw(priv_data_len
, &p54_ops
);
538 priv
->mode
= NL80211_IFTYPE_UNSPECIFIED
;
539 priv
->basic_rate_mask
= 0x15f;
540 spin_lock_init(&priv
->tx_stats_lock
);
541 skb_queue_head_init(&priv
->tx_queue
);
542 skb_queue_head_init(&priv
->tx_pending
);
543 dev
->flags
= IEEE80211_HW_RX_INCLUDES_FCS
|
544 IEEE80211_HW_SIGNAL_DBM
|
545 IEEE80211_HW_SUPPORTS_PS
|
546 IEEE80211_HW_PS_NULLFUNC_STACK
|
547 IEEE80211_HW_BEACON_FILTER
|
548 IEEE80211_HW_REPORTS_TX_ACK_STATUS
;
550 dev
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
551 BIT(NL80211_IFTYPE_ADHOC
) |
552 BIT(NL80211_IFTYPE_AP
) |
553 BIT(NL80211_IFTYPE_MESH_POINT
);
555 dev
->channel_change_time
= 1000; /* TODO: find actual value */
556 priv
->beacon_req_id
= cpu_to_le32(0);
557 priv
->tx_stats
[P54_QUEUE_BEACON
].limit
= 1;
558 priv
->tx_stats
[P54_QUEUE_FWSCAN
].limit
= 1;
559 priv
->tx_stats
[P54_QUEUE_MGMT
].limit
= 3;
560 priv
->tx_stats
[P54_QUEUE_CAB
].limit
= 3;
561 priv
->tx_stats
[P54_QUEUE_DATA
].limit
= 5;
565 * We support at most 8 tries no matter which rate they're at,
566 * we cannot support max_rates * max_rate_tries as we set it
567 * here, but setting it correctly to 4/2 or so would limit us
568 * artificially if the RC algorithm wants just two rates, so
569 * let's say 4/7, we'll redistribute it at TX time, see the
573 dev
->max_rate_tries
= 7;
574 dev
->extra_tx_headroom
= sizeof(struct p54_hdr
) + 4 +
575 sizeof(struct p54_tx_data
);
578 * For now, disable PS by default because it affects
579 * link stability significantly.
581 dev
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
583 mutex_init(&priv
->conf_mutex
);
584 mutex_init(&priv
->eeprom_mutex
);
585 init_completion(&priv
->eeprom_comp
);
586 init_completion(&priv
->beacon_comp
);
587 INIT_DELAYED_WORK(&priv
->work
, p54_work
);
591 EXPORT_SYMBOL_GPL(p54_init_common
);
593 int p54_register_common(struct ieee80211_hw
*dev
, struct device
*pdev
)
595 struct p54_common
*priv
= dev
->priv
;
598 err
= ieee80211_register_hw(dev
);
600 dev_err(pdev
, "Cannot register device (%d).\n", err
);
604 #ifdef CONFIG_P54_LEDS
605 err
= p54_init_leds(priv
);
608 #endif /* CONFIG_P54_LEDS */
610 dev_info(pdev
, "is registered as '%s'\n", wiphy_name(dev
->wiphy
));
613 EXPORT_SYMBOL_GPL(p54_register_common
);
615 void p54_free_common(struct ieee80211_hw
*dev
)
617 struct p54_common
*priv
= dev
->priv
;
620 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
621 kfree(priv
->band_table
[i
]);
623 kfree(priv
->iq_autocal
);
624 kfree(priv
->output_limit
);
625 kfree(priv
->curve_data
);
626 kfree(priv
->used_rxkeys
);
627 priv
->iq_autocal
= NULL
;
628 priv
->output_limit
= NULL
;
629 priv
->curve_data
= NULL
;
630 priv
->used_rxkeys
= NULL
;
631 ieee80211_free_hw(dev
);
633 EXPORT_SYMBOL_GPL(p54_free_common
);
635 void p54_unregister_common(struct ieee80211_hw
*dev
)
637 struct p54_common
*priv
= dev
->priv
;
639 #ifdef CONFIG_P54_LEDS
640 p54_unregister_leds(priv
);
641 #endif /* CONFIG_P54_LEDS */
643 ieee80211_unregister_hw(dev
);
644 mutex_destroy(&priv
->conf_mutex
);
645 mutex_destroy(&priv
->eeprom_mutex
);
647 EXPORT_SYMBOL_GPL(p54_unregister_common
);