WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / wireless / intersil / p54 / main.c
bloba3ca6620dc0c67092faf5cefecfb9407da43ca8e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * mac80211 glue code for mac80211 Prism54 drivers
5 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
6 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
7 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
9 * Based on:
10 * - the islsm (softmac prism54) driver, which is:
11 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
12 * - stlc45xx driver
13 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
16 #include <linux/slab.h>
17 #include <linux/firmware.h>
18 #include <linux/etherdevice.h>
19 #include <linux/module.h>
21 #include <net/mac80211.h>
23 #include "p54.h"
24 #include "lmac.h"
26 static bool modparam_nohwcrypt;
27 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444);
28 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
29 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
30 MODULE_DESCRIPTION("Softmac Prism54 common code");
31 MODULE_LICENSE("GPL");
32 MODULE_ALIAS("prism54common");
34 static int p54_sta_add_remove(struct ieee80211_hw *hw,
35 struct ieee80211_vif *vif,
36 struct ieee80211_sta *sta)
38 struct p54_common *priv = hw->priv;
41 * Notify the firmware that we don't want or we don't
42 * need to buffer frames for this station anymore.
45 p54_sta_unlock(priv, sta->addr);
47 return 0;
50 static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
51 enum sta_notify_cmd notify_cmd,
52 struct ieee80211_sta *sta)
54 struct p54_common *priv = dev->priv;
56 switch (notify_cmd) {
57 case STA_NOTIFY_AWAKE:
58 /* update the firmware's filter table */
59 p54_sta_unlock(priv, sta->addr);
60 break;
61 default:
62 break;
66 static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
67 bool set)
69 struct p54_common *priv = dev->priv;
71 return p54_update_beacon_tim(priv, sta->aid, set);
74 u8 *p54_find_ie(struct sk_buff *skb, u8 ie)
76 struct ieee80211_mgmt *mgmt = (void *)skb->data;
77 u8 *pos, *end;
79 if (skb->len <= sizeof(mgmt))
80 return NULL;
82 pos = (u8 *)mgmt->u.beacon.variable;
83 end = skb->data + skb->len;
84 while (pos < end) {
85 if (pos + 2 + pos[1] > end)
86 return NULL;
88 if (pos[0] == ie)
89 return pos;
91 pos += 2 + pos[1];
93 return NULL;
96 static int p54_beacon_format_ie_tim(struct sk_buff *skb)
99 * the good excuse for this mess is ... the firmware.
100 * The dummy TIM MUST be at the end of the beacon frame,
101 * because it'll be overwritten!
103 u8 *tim;
104 u8 dtim_len;
105 u8 dtim_period;
106 u8 *next;
108 tim = p54_find_ie(skb, WLAN_EID_TIM);
109 if (!tim)
110 return 0;
112 dtim_len = tim[1];
113 dtim_period = tim[3];
114 next = tim + 2 + dtim_len;
116 if (dtim_len < 3)
117 return -EINVAL;
119 memmove(tim, next, skb_tail_pointer(skb) - next);
120 tim = skb_tail_pointer(skb) - (dtim_len + 2);
122 /* add the dummy at the end */
123 tim[0] = WLAN_EID_TIM;
124 tim[1] = 3;
125 tim[2] = 0;
126 tim[3] = dtim_period;
127 tim[4] = 0;
129 if (dtim_len > 3)
130 skb_trim(skb, skb->len - (dtim_len - 3));
132 return 0;
135 static int p54_beacon_update(struct p54_common *priv,
136 struct ieee80211_vif *vif)
138 struct ieee80211_tx_control control = { };
139 struct sk_buff *beacon;
140 int ret;
142 beacon = ieee80211_beacon_get(priv->hw, vif);
143 if (!beacon)
144 return -ENOMEM;
145 ret = p54_beacon_format_ie_tim(beacon);
146 if (ret)
147 return ret;
150 * During operation, the firmware takes care of beaconing.
151 * The driver only needs to upload a new beacon template, once
152 * the template was changed by the stack or userspace.
154 * LMAC API 3.2.2 also specifies that the driver does not need
155 * to cancel the old beacon template by hand, instead the firmware
156 * will release the previous one through the feedback mechanism.
158 p54_tx_80211(priv->hw, &control, beacon);
159 priv->tsf_high32 = 0;
160 priv->tsf_low32 = 0;
162 return 0;
165 static int p54_start(struct ieee80211_hw *dev)
167 struct p54_common *priv = dev->priv;
168 int err;
170 mutex_lock(&priv->conf_mutex);
171 err = priv->open(dev);
172 if (err)
173 goto out;
174 P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
175 P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
176 P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
177 P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
178 err = p54_set_edcf(priv);
179 if (err)
180 goto out;
182 eth_broadcast_addr(priv->bssid);
183 priv->mode = NL80211_IFTYPE_MONITOR;
184 err = p54_setup_mac(priv);
185 if (err) {
186 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
187 goto out;
190 ieee80211_queue_delayed_work(dev, &priv->work, 0);
192 priv->softled_state = 0;
193 err = p54_set_leds(priv);
195 out:
196 mutex_unlock(&priv->conf_mutex);
197 return err;
200 static void p54_stop(struct ieee80211_hw *dev)
202 struct p54_common *priv = dev->priv;
203 int i;
205 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
206 priv->softled_state = 0;
207 cancel_delayed_work_sync(&priv->work);
208 mutex_lock(&priv->conf_mutex);
209 p54_set_leds(priv);
210 priv->stop(dev);
211 skb_queue_purge(&priv->tx_pending);
212 skb_queue_purge(&priv->tx_queue);
213 for (i = 0; i < P54_QUEUE_NUM; i++) {
214 priv->tx_stats[i].count = 0;
215 priv->tx_stats[i].len = 0;
218 priv->beacon_req_id = cpu_to_le32(0);
219 priv->tsf_high32 = priv->tsf_low32 = 0;
220 mutex_unlock(&priv->conf_mutex);
223 static int p54_add_interface(struct ieee80211_hw *dev,
224 struct ieee80211_vif *vif)
226 struct p54_common *priv = dev->priv;
227 int err;
229 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
231 mutex_lock(&priv->conf_mutex);
232 if (priv->mode != NL80211_IFTYPE_MONITOR) {
233 mutex_unlock(&priv->conf_mutex);
234 return -EOPNOTSUPP;
237 priv->vif = vif;
239 switch (vif->type) {
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;
245 break;
246 default:
247 mutex_unlock(&priv->conf_mutex);
248 return -EOPNOTSUPP;
251 memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
252 err = p54_setup_mac(priv);
253 mutex_unlock(&priv->conf_mutex);
254 return err;
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);
263 priv->vif = NULL;
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 eth_zero_addr(priv->mac_addr);
275 eth_zero_addr(priv->bssid);
276 p54_setup_mac(priv);
277 mutex_unlock(&priv->conf_mutex);
280 static int p54_wait_for_stats(struct ieee80211_hw *dev)
282 struct p54_common *priv = dev->priv;
283 int ret;
285 priv->update_stats = true;
286 ret = p54_fetch_statistics(priv);
287 if (ret)
288 return ret;
290 ret = wait_for_completion_interruptible_timeout(&priv->stat_comp, HZ);
291 if (ret == 0)
292 return -ETIMEDOUT;
294 return 0;
297 static void p54_reset_stats(struct p54_common *priv)
299 struct ieee80211_channel *chan = priv->curchan;
301 if (chan) {
302 struct survey_info *info = &priv->survey[chan->hw_value];
304 /* only reset channel statistics, don't touch .filled, etc. */
305 info->time = 0;
306 info->time_busy = 0;
307 info->time_tx = 0;
310 priv->update_stats = true;
311 priv->survey_raw.active = 0;
312 priv->survey_raw.cca = 0;
313 priv->survey_raw.tx = 0;
316 static int p54_config(struct ieee80211_hw *dev, u32 changed)
318 int ret = 0;
319 struct p54_common *priv = dev->priv;
320 struct ieee80211_conf *conf = &dev->conf;
322 mutex_lock(&priv->conf_mutex);
323 if (changed & IEEE80211_CONF_CHANGE_POWER)
324 priv->output_power = conf->power_level << 2;
325 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
326 struct ieee80211_channel *oldchan;
327 WARN_ON(p54_wait_for_stats(dev));
328 oldchan = priv->curchan;
329 priv->curchan = NULL;
330 ret = p54_scan(priv, P54_SCAN_EXIT, 0);
331 if (ret) {
332 priv->curchan = oldchan;
333 goto out;
336 * TODO: Use the LM_SCAN_TRAP to determine the current
337 * operating channel.
339 priv->curchan = priv->hw->conf.chandef.chan;
340 p54_reset_stats(priv);
341 WARN_ON(p54_fetch_statistics(priv));
343 if (changed & IEEE80211_CONF_CHANGE_PS) {
344 WARN_ON(p54_wait_for_stats(dev));
345 ret = p54_set_ps(priv);
346 if (ret)
347 goto out;
348 WARN_ON(p54_wait_for_stats(dev));
350 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
351 WARN_ON(p54_wait_for_stats(dev));
352 ret = p54_setup_mac(priv);
353 if (ret)
354 goto out;
355 WARN_ON(p54_wait_for_stats(dev));
358 out:
359 mutex_unlock(&priv->conf_mutex);
360 return ret;
363 static u64 p54_prepare_multicast(struct ieee80211_hw *dev,
364 struct netdev_hw_addr_list *mc_list)
366 struct p54_common *priv = dev->priv;
367 struct netdev_hw_addr *ha;
368 int i;
370 BUILD_BUG_ON(ARRAY_SIZE(priv->mc_maclist) !=
371 ARRAY_SIZE(((struct p54_group_address_table *)NULL)->mac_list));
373 * The first entry is reserved for the global broadcast MAC.
374 * Otherwise the firmware will drop it and ARP will no longer work.
376 i = 1;
377 priv->mc_maclist_num = netdev_hw_addr_list_count(mc_list) + i;
378 netdev_hw_addr_list_for_each(ha, mc_list) {
379 memcpy(&priv->mc_maclist[i], ha->addr, ETH_ALEN);
380 i++;
381 if (i >= ARRAY_SIZE(priv->mc_maclist))
382 break;
385 return 1; /* update */
388 static void p54_configure_filter(struct ieee80211_hw *dev,
389 unsigned int changed_flags,
390 unsigned int *total_flags,
391 u64 multicast)
393 struct p54_common *priv = dev->priv;
395 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS;
397 priv->filter_flags = *total_flags;
399 if (changed_flags & FIF_OTHER_BSS)
400 p54_setup_mac(priv);
402 if (changed_flags & FIF_ALLMULTI || multicast)
403 p54_set_groupfilter(priv);
406 static int p54_conf_tx(struct ieee80211_hw *dev,
407 struct ieee80211_vif *vif, u16 queue,
408 const struct ieee80211_tx_queue_params *params)
410 struct p54_common *priv = dev->priv;
411 int ret;
413 mutex_lock(&priv->conf_mutex);
414 P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
415 params->cw_min, params->cw_max, params->txop);
416 ret = p54_set_edcf(priv);
417 mutex_unlock(&priv->conf_mutex);
418 return ret;
421 static void p54_work(struct work_struct *work)
423 struct p54_common *priv = container_of(work, struct p54_common,
424 work.work);
426 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
427 return ;
430 * TODO: walk through tx_queue and do the following tasks
431 * 1. initiate bursts.
432 * 2. cancel stuck frames / reset the device if necessary.
435 mutex_lock(&priv->conf_mutex);
436 WARN_ON_ONCE(p54_fetch_statistics(priv));
437 mutex_unlock(&priv->conf_mutex);
440 static int p54_get_stats(struct ieee80211_hw *dev,
441 struct ieee80211_low_level_stats *stats)
443 struct p54_common *priv = dev->priv;
445 memcpy(stats, &priv->stats, sizeof(*stats));
446 return 0;
449 static void p54_bss_info_changed(struct ieee80211_hw *dev,
450 struct ieee80211_vif *vif,
451 struct ieee80211_bss_conf *info,
452 u32 changed)
454 struct p54_common *priv = dev->priv;
456 mutex_lock(&priv->conf_mutex);
457 if (changed & BSS_CHANGED_BSSID) {
458 memcpy(priv->bssid, info->bssid, ETH_ALEN);
459 p54_setup_mac(priv);
462 if (changed & BSS_CHANGED_BEACON) {
463 p54_scan(priv, P54_SCAN_EXIT, 0);
464 p54_setup_mac(priv);
465 p54_beacon_update(priv, vif);
466 p54_set_edcf(priv);
469 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) {
470 priv->use_short_slot = info->use_short_slot;
471 p54_set_edcf(priv);
473 if (changed & BSS_CHANGED_BASIC_RATES) {
474 if (dev->conf.chandef.chan->band == NL80211_BAND_5GHZ)
475 priv->basic_rate_mask = (info->basic_rates << 4);
476 else
477 priv->basic_rate_mask = info->basic_rates;
478 p54_setup_mac(priv);
479 if (priv->fw_var >= 0x500)
480 p54_scan(priv, P54_SCAN_EXIT, 0);
482 if (changed & BSS_CHANGED_ASSOC) {
483 if (info->assoc) {
484 priv->aid = info->aid;
485 priv->wakeup_timer = info->beacon_int *
486 info->dtim_period * 5;
487 p54_setup_mac(priv);
488 } else {
489 priv->wakeup_timer = 500;
490 priv->aid = 0;
494 mutex_unlock(&priv->conf_mutex);
497 static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
498 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
499 struct ieee80211_key_conf *key)
501 struct p54_common *priv = dev->priv;
502 int slot, ret = 0;
503 u8 algo = 0;
504 u8 *addr = NULL;
506 if (modparam_nohwcrypt)
507 return -EOPNOTSUPP;
509 if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT) {
511 * Unfortunately most/all firmwares are trying to decrypt
512 * incoming management frames if a suitable key can be found.
513 * However, in doing so the data in these frames gets
514 * corrupted. So, we can't have firmware supported crypto
515 * offload in this case.
517 return -EOPNOTSUPP;
520 mutex_lock(&priv->conf_mutex);
521 if (cmd == SET_KEY) {
522 switch (key->cipher) {
523 case WLAN_CIPHER_SUITE_TKIP:
524 if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
525 BR_DESC_PRIV_CAP_TKIP))) {
526 ret = -EOPNOTSUPP;
527 goto out_unlock;
529 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
530 algo = P54_CRYPTO_TKIPMICHAEL;
531 break;
532 case WLAN_CIPHER_SUITE_WEP40:
533 case WLAN_CIPHER_SUITE_WEP104:
534 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) {
535 ret = -EOPNOTSUPP;
536 goto out_unlock;
538 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
539 algo = P54_CRYPTO_WEP;
540 break;
541 case WLAN_CIPHER_SUITE_CCMP:
542 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) {
543 ret = -EOPNOTSUPP;
544 goto out_unlock;
546 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
547 algo = P54_CRYPTO_AESCCMP;
548 break;
549 default:
550 ret = -EOPNOTSUPP;
551 goto out_unlock;
553 slot = bitmap_find_free_region(priv->used_rxkeys,
554 priv->rx_keycache_size, 0);
556 if (slot < 0) {
558 * The device supports the chosen algorithm, but the
559 * firmware does not provide enough key slots to store
560 * all of them.
561 * But encryption offload for outgoing frames is always
562 * possible, so we just pretend that the upload was
563 * successful and do the decryption in software.
566 /* mark the key as invalid. */
567 key->hw_key_idx = 0xff;
568 goto out_unlock;
571 key->flags |= IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
572 } else {
573 slot = key->hw_key_idx;
575 if (slot == 0xff) {
576 /* This key was not uploaded into the rx key cache. */
578 goto out_unlock;
581 bitmap_release_region(priv->used_rxkeys, slot, 0);
582 algo = 0;
585 if (sta)
586 addr = sta->addr;
588 ret = p54_upload_key(priv, algo, slot, key->keyidx,
589 key->keylen, addr, key->key);
590 if (ret) {
591 bitmap_release_region(priv->used_rxkeys, slot, 0);
592 ret = -EOPNOTSUPP;
593 goto out_unlock;
596 key->hw_key_idx = slot;
598 out_unlock:
599 mutex_unlock(&priv->conf_mutex);
600 return ret;
603 static int p54_get_survey(struct ieee80211_hw *dev, int idx,
604 struct survey_info *survey)
606 struct p54_common *priv = dev->priv;
607 struct ieee80211_channel *chan;
608 int err, tries;
609 bool in_use = false;
611 if (idx >= priv->chan_num)
612 return -ENOENT;
614 #define MAX_TRIES 1
615 for (tries = 0; tries < MAX_TRIES; tries++) {
616 chan = priv->curchan;
617 if (chan && chan->hw_value == idx) {
618 mutex_lock(&priv->conf_mutex);
619 err = p54_wait_for_stats(dev);
620 mutex_unlock(&priv->conf_mutex);
621 if (err)
622 return err;
624 in_use = true;
627 memcpy(survey, &priv->survey[idx], sizeof(*survey));
629 if (in_use) {
630 /* test if the reported statistics are valid. */
631 if (survey->time != 0) {
632 survey->filled |= SURVEY_INFO_IN_USE;
633 } else {
635 * hw/fw has not accumulated enough sample sets.
636 * Wait for 100ms, this ought to be enough to
637 * to get at least one non-null set of channel
638 * usage statistics.
640 msleep(100);
641 continue;
644 return 0;
646 return -ETIMEDOUT;
647 #undef MAX_TRIES
650 static unsigned int p54_flush_count(struct p54_common *priv)
652 unsigned int total = 0, i;
654 BUILD_BUG_ON(P54_QUEUE_NUM > ARRAY_SIZE(priv->tx_stats));
657 * Because the firmware has the sole control over any frames
658 * in the P54_QUEUE_BEACON or P54_QUEUE_SCAN queues, they
659 * don't really count as pending or active.
661 for (i = P54_QUEUE_MGMT; i < P54_QUEUE_NUM; i++)
662 total += priv->tx_stats[i].len;
663 return total;
666 static void p54_flush(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
667 u32 queues, bool drop)
669 struct p54_common *priv = dev->priv;
670 unsigned int total, i;
673 * Currently, it wouldn't really matter if we wait for one second
674 * or 15 minutes. But once someone gets around and completes the
675 * TODOs [ancel stuck frames / reset device] in p54_work, it will
676 * suddenly make sense to wait that long.
678 i = P54_STATISTICS_UPDATE * 2 / 20;
681 * In this case no locking is required because as we speak the
682 * queues have already been stopped and no new frames can sneak
683 * up from behind.
685 while ((total = p54_flush_count(priv) && i--)) {
686 /* waste time */
687 msleep(20);
690 WARN(total, "tx flush timeout, unresponsive firmware");
693 static void p54_set_coverage_class(struct ieee80211_hw *dev,
694 s16 coverage_class)
696 struct p54_common *priv = dev->priv;
698 mutex_lock(&priv->conf_mutex);
699 /* support all coverage class values as in 802.11-2007 Table 7-27 */
700 priv->coverage_class = clamp_t(u8, coverage_class, 0, 31);
701 p54_set_edcf(priv);
702 mutex_unlock(&priv->conf_mutex);
705 static const struct ieee80211_ops p54_ops = {
706 .tx = p54_tx_80211,
707 .start = p54_start,
708 .stop = p54_stop,
709 .add_interface = p54_add_interface,
710 .remove_interface = p54_remove_interface,
711 .set_tim = p54_set_tim,
712 .sta_notify = p54_sta_notify,
713 .sta_add = p54_sta_add_remove,
714 .sta_remove = p54_sta_add_remove,
715 .set_key = p54_set_key,
716 .config = p54_config,
717 .flush = p54_flush,
718 .bss_info_changed = p54_bss_info_changed,
719 .prepare_multicast = p54_prepare_multicast,
720 .configure_filter = p54_configure_filter,
721 .conf_tx = p54_conf_tx,
722 .get_stats = p54_get_stats,
723 .get_survey = p54_get_survey,
724 .set_coverage_class = p54_set_coverage_class,
727 struct ieee80211_hw *p54_init_common(size_t priv_data_len)
729 struct ieee80211_hw *dev;
730 struct p54_common *priv;
732 dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
733 if (!dev)
734 return NULL;
736 priv = dev->priv;
737 priv->hw = dev;
738 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
739 priv->basic_rate_mask = 0x15f;
740 spin_lock_init(&priv->tx_stats_lock);
741 skb_queue_head_init(&priv->tx_queue);
742 skb_queue_head_init(&priv->tx_pending);
743 ieee80211_hw_set(dev, REPORTS_TX_ACK_STATUS);
744 ieee80211_hw_set(dev, MFP_CAPABLE);
745 ieee80211_hw_set(dev, PS_NULLFUNC_STACK);
746 ieee80211_hw_set(dev, SUPPORTS_PS);
747 ieee80211_hw_set(dev, RX_INCLUDES_FCS);
748 ieee80211_hw_set(dev, SIGNAL_DBM);
750 dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
751 BIT(NL80211_IFTYPE_ADHOC) |
752 BIT(NL80211_IFTYPE_AP) |
753 BIT(NL80211_IFTYPE_MESH_POINT);
755 priv->beacon_req_id = cpu_to_le32(0);
756 priv->tx_stats[P54_QUEUE_BEACON].limit = 1;
757 priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1;
758 priv->tx_stats[P54_QUEUE_MGMT].limit = 3;
759 priv->tx_stats[P54_QUEUE_CAB].limit = 3;
760 priv->tx_stats[P54_QUEUE_DATA].limit = 5;
761 dev->queues = 1;
762 priv->noise = -94;
764 * We support at most 8 tries no matter which rate they're at,
765 * we cannot support max_rates * max_rate_tries as we set it
766 * here, but setting it correctly to 4/2 or so would limit us
767 * artificially if the RC algorithm wants just two rates, so
768 * let's say 4/7, we'll redistribute it at TX time, see the
769 * comments there.
771 dev->max_rates = 4;
772 dev->max_rate_tries = 7;
773 dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
774 sizeof(struct p54_tx_data);
777 * For now, disable PS by default because it affects
778 * link stability significantly.
780 dev->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
782 mutex_init(&priv->conf_mutex);
783 mutex_init(&priv->eeprom_mutex);
784 init_completion(&priv->stat_comp);
785 init_completion(&priv->eeprom_comp);
786 init_completion(&priv->beacon_comp);
787 INIT_DELAYED_WORK(&priv->work, p54_work);
789 eth_broadcast_addr(priv->mc_maclist[0]);
790 priv->curchan = NULL;
791 p54_reset_stats(priv);
792 return dev;
794 EXPORT_SYMBOL_GPL(p54_init_common);
796 int p54_register_common(struct ieee80211_hw *dev, struct device *pdev)
798 struct p54_common __maybe_unused *priv = dev->priv;
799 int err;
801 err = ieee80211_register_hw(dev);
802 if (err) {
803 dev_err(pdev, "Cannot register device (%d).\n", err);
804 return err;
806 priv->registered = true;
808 #ifdef CONFIG_P54_LEDS
809 err = p54_init_leds(priv);
810 if (err) {
811 p54_unregister_common(dev);
812 return err;
814 #endif /* CONFIG_P54_LEDS */
816 dev_info(pdev, "is registered as '%s'\n", wiphy_name(dev->wiphy));
817 return 0;
819 EXPORT_SYMBOL_GPL(p54_register_common);
821 void p54_free_common(struct ieee80211_hw *dev)
823 struct p54_common *priv = dev->priv;
824 unsigned int i;
826 for (i = 0; i < NUM_NL80211_BANDS; i++)
827 kfree(priv->band_table[i]);
829 kfree(priv->iq_autocal);
830 kfree(priv->output_limit);
831 kfree(priv->curve_data);
832 kfree(priv->rssi_db);
833 kfree(priv->used_rxkeys);
834 kfree(priv->survey);
835 priv->iq_autocal = NULL;
836 priv->output_limit = NULL;
837 priv->curve_data = NULL;
838 priv->rssi_db = NULL;
839 priv->used_rxkeys = NULL;
840 priv->survey = NULL;
841 ieee80211_free_hw(dev);
843 EXPORT_SYMBOL_GPL(p54_free_common);
845 void p54_unregister_common(struct ieee80211_hw *dev)
847 struct p54_common *priv = dev->priv;
849 if (priv->registered) {
850 priv->registered = false;
851 #ifdef CONFIG_P54_LEDS
852 p54_unregister_leds(priv);
853 #endif /* CONFIG_P54_LEDS */
854 ieee80211_unregister_hw(dev);
857 mutex_destroy(&priv->conf_mutex);
858 mutex_destroy(&priv->eeprom_mutex);
860 EXPORT_SYMBOL_GPL(p54_unregister_common);