0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015
0016 #include "rt2x00.h"
0017 #include "rt2x00lib.h"
0018
0019 static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
0020 struct data_queue *queue,
0021 struct sk_buff *frag_skb)
0022 {
0023 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(frag_skb);
0024 struct ieee80211_tx_info *rts_info;
0025 struct sk_buff *skb;
0026 unsigned int data_length;
0027 int retval = 0;
0028
0029 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
0030 data_length = sizeof(struct ieee80211_cts);
0031 else
0032 data_length = sizeof(struct ieee80211_rts);
0033
0034 skb = dev_alloc_skb(data_length + rt2x00dev->hw->extra_tx_headroom);
0035 if (unlikely(!skb)) {
0036 rt2x00_warn(rt2x00dev, "Failed to create RTS/CTS frame\n");
0037 return -ENOMEM;
0038 }
0039
0040 skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom);
0041 skb_put(skb, data_length);
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb));
0053 rts_info = IEEE80211_SKB_CB(skb);
0054 rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_RTS_CTS;
0055 rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_CTS_PROTECT;
0056
0057 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
0058 rts_info->flags |= IEEE80211_TX_CTL_NO_ACK;
0059 else
0060 rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
0061
0062
0063 rts_info->control.hw_key = NULL;
0064
0065
0066
0067
0068
0069 data_length += rt2x00crypto_tx_overhead(rt2x00dev, skb);
0070
0071 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
0072 ieee80211_ctstoself_get(rt2x00dev->hw, tx_info->control.vif,
0073 frag_skb->data, data_length, tx_info,
0074 (struct ieee80211_cts *)(skb->data));
0075 else
0076 ieee80211_rts_get(rt2x00dev->hw, tx_info->control.vif,
0077 frag_skb->data, data_length, tx_info,
0078 (struct ieee80211_rts *)(skb->data));
0079
0080 retval = rt2x00queue_write_tx_frame(queue, skb, NULL, true);
0081 if (retval) {
0082 dev_kfree_skb_any(skb);
0083 rt2x00_warn(rt2x00dev, "Failed to send RTS/CTS frame\n");
0084 }
0085
0086 return retval;
0087 }
0088
0089 void rt2x00mac_tx(struct ieee80211_hw *hw,
0090 struct ieee80211_tx_control *control,
0091 struct sk_buff *skb)
0092 {
0093 struct rt2x00_dev *rt2x00dev = hw->priv;
0094 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
0095 enum data_queue_qid qid = skb_get_queue_mapping(skb);
0096 struct data_queue *queue = NULL;
0097
0098
0099
0100
0101
0102
0103
0104 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0105 goto exit_free_skb;
0106
0107
0108
0109
0110 if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM &&
0111 rt2x00_has_cap_flag(rt2x00dev, REQUIRE_ATIM_QUEUE))
0112 qid = QID_ATIM;
0113
0114 queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
0115 if (unlikely(!queue)) {
0116 rt2x00_err(rt2x00dev,
0117 "Attempt to send packet over invalid queue %d\n"
0118 "Please file bug report to %s\n", qid, DRV_PROJECT);
0119 goto exit_free_skb;
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 if (!rt2x00dev->ops->hw->set_rts_threshold &&
0132 (tx_info->control.rates[0].flags & (IEEE80211_TX_RC_USE_RTS_CTS |
0133 IEEE80211_TX_RC_USE_CTS_PROTECT))) {
0134 if (rt2x00queue_available(queue) <= 1) {
0135
0136
0137
0138
0139 spin_lock(&queue->tx_lock);
0140 if (rt2x00queue_threshold(queue))
0141 rt2x00queue_pause_queue(queue);
0142 spin_unlock(&queue->tx_lock);
0143
0144 goto exit_free_skb;
0145 }
0146
0147 if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb))
0148 goto exit_free_skb;
0149 }
0150
0151 if (unlikely(rt2x00queue_write_tx_frame(queue, skb, control->sta, false)))
0152 goto exit_free_skb;
0153
0154 return;
0155
0156 exit_free_skb:
0157 ieee80211_free_txskb(hw, skb);
0158 }
0159 EXPORT_SYMBOL_GPL(rt2x00mac_tx);
0160
0161 int rt2x00mac_start(struct ieee80211_hw *hw)
0162 {
0163 struct rt2x00_dev *rt2x00dev = hw->priv;
0164
0165 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0166 return 0;
0167
0168 if (test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) {
0169
0170
0171
0172
0173 set_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
0174 rt2x00dev->ops->lib->pre_reset_hw(rt2x00dev);
0175 rt2x00lib_stop(rt2x00dev);
0176 }
0177 return rt2x00lib_start(rt2x00dev);
0178 }
0179 EXPORT_SYMBOL_GPL(rt2x00mac_start);
0180
0181 void rt2x00mac_stop(struct ieee80211_hw *hw)
0182 {
0183 struct rt2x00_dev *rt2x00dev = hw->priv;
0184
0185 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0186 return;
0187
0188 rt2x00lib_stop(rt2x00dev);
0189 }
0190 EXPORT_SYMBOL_GPL(rt2x00mac_stop);
0191
0192 void
0193 rt2x00mac_reconfig_complete(struct ieee80211_hw *hw,
0194 enum ieee80211_reconfig_type reconfig_type)
0195 {
0196 struct rt2x00_dev *rt2x00dev = hw->priv;
0197
0198 if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
0199 clear_bit(DEVICE_STATE_RESET, &rt2x00dev->flags);
0200 }
0201 EXPORT_SYMBOL_GPL(rt2x00mac_reconfig_complete);
0202
0203 int rt2x00mac_add_interface(struct ieee80211_hw *hw,
0204 struct ieee80211_vif *vif)
0205 {
0206 struct rt2x00_dev *rt2x00dev = hw->priv;
0207 struct rt2x00_intf *intf = vif_to_intf(vif);
0208 struct data_queue *queue = rt2x00dev->bcn;
0209 struct queue_entry *entry = NULL;
0210 unsigned int i;
0211
0212
0213
0214
0215
0216 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
0217 !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
0218 return -ENODEV;
0219
0220
0221
0222
0223
0224
0225
0226 for (i = 0; i < queue->limit; i++) {
0227 entry = &queue->entries[i];
0228 if (!test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags))
0229 break;
0230 }
0231
0232 if (unlikely(i == queue->limit))
0233 return -ENOBUFS;
0234
0235
0236
0237
0238
0239
0240 if (vif->type == NL80211_IFTYPE_AP)
0241 rt2x00dev->intf_ap_count++;
0242 else
0243 rt2x00dev->intf_sta_count++;
0244
0245 mutex_init(&intf->beacon_skb_mutex);
0246 intf->beacon = entry;
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 rt2x00lib_config_intf(rt2x00dev, intf, vif->type,
0258 vif->addr, NULL);
0259
0260
0261
0262
0263
0264
0265 rt2x00dev->packet_filter = 0;
0266
0267 return 0;
0268 }
0269 EXPORT_SYMBOL_GPL(rt2x00mac_add_interface);
0270
0271 void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
0272 struct ieee80211_vif *vif)
0273 {
0274 struct rt2x00_dev *rt2x00dev = hw->priv;
0275 struct rt2x00_intf *intf = vif_to_intf(vif);
0276
0277
0278
0279
0280
0281
0282 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
0283 (vif->type == NL80211_IFTYPE_AP && !rt2x00dev->intf_ap_count) ||
0284 (vif->type != NL80211_IFTYPE_AP && !rt2x00dev->intf_sta_count))
0285 return;
0286
0287 if (vif->type == NL80211_IFTYPE_AP)
0288 rt2x00dev->intf_ap_count--;
0289 else
0290 rt2x00dev->intf_sta_count--;
0291
0292
0293
0294
0295
0296 clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags);
0297
0298
0299
0300
0301
0302 rt2x00lib_config_intf(rt2x00dev, intf,
0303 NL80211_IFTYPE_UNSPECIFIED, NULL, NULL);
0304 }
0305 EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface);
0306
0307 int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
0308 {
0309 struct rt2x00_dev *rt2x00dev = hw->priv;
0310 struct ieee80211_conf *conf = &hw->conf;
0311
0312
0313
0314
0315
0316 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0317 return 0;
0318
0319
0320
0321
0322
0323
0324
0325
0326 rt2x00queue_stop_queue(rt2x00dev->rx);
0327
0328
0329 mutex_lock(&rt2x00dev->conf_mutex);
0330
0331
0332
0333
0334
0335 rt2x00lib_config(rt2x00dev, conf, changed);
0336
0337
0338
0339
0340
0341
0342
0343
0344 rt2x00lib_config_antenna(rt2x00dev, rt2x00dev->default_ant);
0345
0346 mutex_unlock(&rt2x00dev->conf_mutex);
0347
0348
0349 rt2x00queue_start_queue(rt2x00dev->rx);
0350
0351 return 0;
0352 }
0353 EXPORT_SYMBOL_GPL(rt2x00mac_config);
0354
0355 void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
0356 unsigned int changed_flags,
0357 unsigned int *total_flags,
0358 u64 multicast)
0359 {
0360 struct rt2x00_dev *rt2x00dev = hw->priv;
0361
0362
0363
0364
0365
0366 *total_flags &=
0367 FIF_ALLMULTI |
0368 FIF_FCSFAIL |
0369 FIF_PLCPFAIL |
0370 FIF_CONTROL |
0371 FIF_PSPOLL |
0372 FIF_OTHER_BSS;
0373
0374
0375
0376
0377
0378
0379
0380 *total_flags |= FIF_ALLMULTI;
0381
0382
0383
0384
0385
0386
0387
0388
0389 if (!rt2x00_has_cap_control_filters(rt2x00dev)) {
0390 if (*total_flags & FIF_CONTROL || *total_flags & FIF_PSPOLL)
0391 *total_flags |= FIF_CONTROL | FIF_PSPOLL;
0392 }
0393 if (!rt2x00_has_cap_control_filter_pspoll(rt2x00dev)) {
0394 if (*total_flags & FIF_CONTROL)
0395 *total_flags |= FIF_PSPOLL;
0396 }
0397
0398 rt2x00dev->packet_filter = *total_flags;
0399
0400 rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags);
0401 }
0402 EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter);
0403
0404 static void rt2x00mac_set_tim_iter(void *data, u8 *mac,
0405 struct ieee80211_vif *vif)
0406 {
0407 struct rt2x00_intf *intf = vif_to_intf(vif);
0408
0409 if (vif->type != NL80211_IFTYPE_AP &&
0410 vif->type != NL80211_IFTYPE_ADHOC &&
0411 vif->type != NL80211_IFTYPE_MESH_POINT)
0412 return;
0413
0414 set_bit(DELAYED_UPDATE_BEACON, &intf->delayed_flags);
0415 }
0416
0417 int rt2x00mac_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
0418 bool set)
0419 {
0420 struct rt2x00_dev *rt2x00dev = hw->priv;
0421
0422 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
0423 return 0;
0424
0425 ieee80211_iterate_active_interfaces_atomic(
0426 rt2x00dev->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
0427 rt2x00mac_set_tim_iter, rt2x00dev);
0428
0429
0430 ieee80211_queue_work(rt2x00dev->hw, &rt2x00dev->intf_work);
0431 return 0;
0432 }
0433 EXPORT_SYMBOL_GPL(rt2x00mac_set_tim);
0434
0435 #ifdef CONFIG_RT2X00_LIB_CRYPTO
0436 static void memcpy_tkip(struct rt2x00lib_crypto *crypto, u8 *key, u8 key_len)
0437 {
0438 if (key_len > NL80211_TKIP_DATA_OFFSET_ENCR_KEY)
0439 memcpy(crypto->key,
0440 &key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY],
0441 sizeof(crypto->key));
0442
0443 if (key_len > NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY)
0444 memcpy(crypto->tx_mic,
0445 &key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
0446 sizeof(crypto->tx_mic));
0447
0448 if (key_len > NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY)
0449 memcpy(crypto->rx_mic,
0450 &key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
0451 sizeof(crypto->rx_mic));
0452 }
0453
0454 int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
0455 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
0456 struct ieee80211_key_conf *key)
0457 {
0458 struct rt2x00_dev *rt2x00dev = hw->priv;
0459 int (*set_key) (struct rt2x00_dev *rt2x00dev,
0460 struct rt2x00lib_crypto *crypto,
0461 struct ieee80211_key_conf *key);
0462 struct rt2x00lib_crypto crypto;
0463 static const u8 bcast_addr[ETH_ALEN] =
0464 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
0465 struct rt2x00_sta *sta_priv = NULL;
0466
0467 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0468 return 0;
0469
0470
0471 if (!rt2x00_has_cap_hw_crypto(rt2x00dev) || (sta && sta->mfp))
0472 return -EOPNOTSUPP;
0473
0474
0475
0476
0477
0478 if (vif->type == NL80211_IFTYPE_ADHOC &&
0479 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
0480 return -EOPNOTSUPP;
0481
0482 if (key->keylen > 32)
0483 return -ENOSPC;
0484
0485 memset(&crypto, 0, sizeof(crypto));
0486
0487 crypto.bssidx = rt2x00lib_get_bssidx(rt2x00dev, vif);
0488 crypto.cipher = rt2x00crypto_key_to_cipher(key);
0489 if (crypto.cipher == CIPHER_NONE)
0490 return -EOPNOTSUPP;
0491 if (crypto.cipher == CIPHER_TKIP && rt2x00_is_usb(rt2x00dev))
0492 return -EOPNOTSUPP;
0493
0494 crypto.cmd = cmd;
0495
0496 if (sta) {
0497 crypto.address = sta->addr;
0498 sta_priv = sta_to_rt2x00_sta(sta);
0499 crypto.wcid = sta_priv->wcid;
0500 } else
0501 crypto.address = bcast_addr;
0502
0503 if (crypto.cipher == CIPHER_TKIP)
0504 memcpy_tkip(&crypto, &key->key[0], key->keylen);
0505 else
0506 memcpy(crypto.key, &key->key[0], key->keylen);
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523 if (cmd == SET_KEY)
0524 key->hw_key_idx = 0;
0525
0526 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
0527 set_key = rt2x00dev->ops->lib->config_pairwise_key;
0528 else
0529 set_key = rt2x00dev->ops->lib->config_shared_key;
0530
0531 if (!set_key)
0532 return -EOPNOTSUPP;
0533
0534 return set_key(rt2x00dev, &crypto, key);
0535 }
0536 EXPORT_SYMBOL_GPL(rt2x00mac_set_key);
0537 #endif
0538
0539 void rt2x00mac_sw_scan_start(struct ieee80211_hw *hw,
0540 struct ieee80211_vif *vif,
0541 const u8 *mac_addr)
0542 {
0543 struct rt2x00_dev *rt2x00dev = hw->priv;
0544 set_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags);
0545 rt2x00link_stop_tuner(rt2x00dev);
0546 }
0547 EXPORT_SYMBOL_GPL(rt2x00mac_sw_scan_start);
0548
0549 void rt2x00mac_sw_scan_complete(struct ieee80211_hw *hw,
0550 struct ieee80211_vif *vif)
0551 {
0552 struct rt2x00_dev *rt2x00dev = hw->priv;
0553 clear_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags);
0554 rt2x00link_start_tuner(rt2x00dev);
0555 }
0556 EXPORT_SYMBOL_GPL(rt2x00mac_sw_scan_complete);
0557
0558 int rt2x00mac_get_stats(struct ieee80211_hw *hw,
0559 struct ieee80211_low_level_stats *stats)
0560 {
0561 struct rt2x00_dev *rt2x00dev = hw->priv;
0562
0563
0564
0565
0566
0567
0568 memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats));
0569
0570 return 0;
0571 }
0572 EXPORT_SYMBOL_GPL(rt2x00mac_get_stats);
0573
0574 void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
0575 struct ieee80211_vif *vif,
0576 struct ieee80211_bss_conf *bss_conf,
0577 u64 changes)
0578 {
0579 struct rt2x00_dev *rt2x00dev = hw->priv;
0580 struct rt2x00_intf *intf = vif_to_intf(vif);
0581
0582
0583
0584
0585
0586 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0587 return;
0588
0589
0590
0591
0592 if (changes & BSS_CHANGED_BSSID)
0593 rt2x00lib_config_intf(rt2x00dev, intf, vif->type, NULL,
0594 bss_conf->bssid);
0595
0596
0597
0598
0599 if (changes & BSS_CHANGED_BEACON_ENABLED) {
0600 mutex_lock(&intf->beacon_skb_mutex);
0601 if (!bss_conf->enable_beacon && intf->enable_beacon) {
0602 rt2x00dev->intf_beaconing--;
0603 intf->enable_beacon = false;
0604
0605 if (rt2x00dev->intf_beaconing == 0) {
0606
0607
0608
0609
0610 rt2x00queue_stop_queue(rt2x00dev->bcn);
0611 }
0612
0613
0614
0615
0616
0617 rt2x00queue_clear_beacon(rt2x00dev, vif);
0618 } else if (bss_conf->enable_beacon && !intf->enable_beacon) {
0619 rt2x00dev->intf_beaconing++;
0620 intf->enable_beacon = true;
0621
0622
0623
0624
0625 if (rt2x00_is_usb(rt2x00dev))
0626 rt2x00queue_update_beacon(rt2x00dev, vif);
0627
0628 if (rt2x00dev->intf_beaconing == 1) {
0629
0630
0631
0632
0633 rt2x00queue_start_queue(rt2x00dev->bcn);
0634 }
0635 }
0636 mutex_unlock(&intf->beacon_skb_mutex);
0637 }
0638
0639
0640
0641
0642
0643
0644
0645 if (changes & BSS_CHANGED_ASSOC) {
0646 rt2x00dev->link.count = 0;
0647
0648 if (vif->cfg.assoc)
0649 rt2x00dev->intf_associated++;
0650 else
0651 rt2x00dev->intf_associated--;
0652
0653 rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
0654 }
0655
0656
0657
0658
0659
0660 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE |
0661 BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BASIC_RATES |
0662 BSS_CHANGED_BEACON_INT | BSS_CHANGED_HT))
0663 rt2x00lib_config_erp(rt2x00dev, intf, bss_conf, changes);
0664 }
0665 EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed);
0666
0667 int rt2x00mac_conf_tx(struct ieee80211_hw *hw,
0668 struct ieee80211_vif *vif,
0669 unsigned int link_id, u16 queue_idx,
0670 const struct ieee80211_tx_queue_params *params)
0671 {
0672 struct rt2x00_dev *rt2x00dev = hw->priv;
0673 struct data_queue *queue;
0674
0675 queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
0676 if (unlikely(!queue))
0677 return -EINVAL;
0678
0679
0680
0681
0682
0683 if (params->cw_min > 0)
0684 queue->cw_min = fls(params->cw_min);
0685 else
0686 queue->cw_min = 5;
0687
0688 if (params->cw_max > 0)
0689 queue->cw_max = fls(params->cw_max);
0690 else
0691 queue->cw_max = 10;
0692
0693 queue->aifs = params->aifs;
0694 queue->txop = params->txop;
0695
0696 rt2x00_dbg(rt2x00dev,
0697 "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d, TXop: %d\n",
0698 queue_idx, queue->cw_min, queue->cw_max, queue->aifs,
0699 queue->txop);
0700
0701 return 0;
0702 }
0703 EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx);
0704
0705 void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw)
0706 {
0707 struct rt2x00_dev *rt2x00dev = hw->priv;
0708 bool active = !!rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
0709
0710 wiphy_rfkill_set_hw_state(hw->wiphy, !active);
0711 }
0712 EXPORT_SYMBOL_GPL(rt2x00mac_rfkill_poll);
0713
0714 void rt2x00mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
0715 u32 queues, bool drop)
0716 {
0717 struct rt2x00_dev *rt2x00dev = hw->priv;
0718 struct data_queue *queue;
0719
0720 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
0721 return;
0722
0723 set_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags);
0724
0725 tx_queue_for_each(rt2x00dev, queue)
0726 rt2x00queue_flush_queue(queue, drop);
0727
0728 clear_bit(DEVICE_STATE_FLUSHING, &rt2x00dev->flags);
0729 }
0730 EXPORT_SYMBOL_GPL(rt2x00mac_flush);
0731
0732 int rt2x00mac_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
0733 {
0734 struct rt2x00_dev *rt2x00dev = hw->priv;
0735 struct link_ant *ant = &rt2x00dev->link.ant;
0736 struct antenna_setup *def = &rt2x00dev->default_ant;
0737 struct antenna_setup setup;
0738
0739
0740
0741 if (!tx_ant || (tx_ant & ~3) || !rx_ant || (rx_ant & ~3))
0742 return -EINVAL;
0743
0744
0745
0746
0747 if (ant->flags & ANTENNA_TX_DIVERSITY && tx_ant != 3)
0748 ant->flags &= ~ANTENNA_TX_DIVERSITY;
0749 if (ant->flags & ANTENNA_RX_DIVERSITY && rx_ant != 3)
0750 ant->flags &= ~ANTENNA_RX_DIVERSITY;
0751
0752
0753
0754
0755
0756 if (tx_ant == 3 && def->tx == ANTENNA_SW_DIVERSITY) {
0757 tx_ant = ANTENNA_SW_DIVERSITY;
0758 ant->flags |= ANTENNA_TX_DIVERSITY;
0759 }
0760
0761 if (rx_ant == 3 && def->rx == ANTENNA_SW_DIVERSITY) {
0762 rx_ant = ANTENNA_SW_DIVERSITY;
0763 ant->flags |= ANTENNA_RX_DIVERSITY;
0764 }
0765
0766 setup.tx = tx_ant;
0767 setup.rx = rx_ant;
0768 setup.rx_chain_num = 0;
0769 setup.tx_chain_num = 0;
0770
0771 rt2x00lib_config_antenna(rt2x00dev, setup);
0772
0773 return 0;
0774 }
0775 EXPORT_SYMBOL_GPL(rt2x00mac_set_antenna);
0776
0777 int rt2x00mac_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
0778 {
0779 struct rt2x00_dev *rt2x00dev = hw->priv;
0780 struct link_ant *ant = &rt2x00dev->link.ant;
0781 struct antenna_setup *active = &rt2x00dev->link.ant.active;
0782
0783
0784
0785 if (ant->flags & ANTENNA_TX_DIVERSITY)
0786 *tx_ant = ANTENNA_HW_DIVERSITY;
0787 else
0788 *tx_ant = active->tx;
0789
0790 if (ant->flags & ANTENNA_RX_DIVERSITY)
0791 *rx_ant = ANTENNA_HW_DIVERSITY;
0792 else
0793 *rx_ant = active->rx;
0794
0795 return 0;
0796 }
0797 EXPORT_SYMBOL_GPL(rt2x00mac_get_antenna);
0798
0799 void rt2x00mac_get_ringparam(struct ieee80211_hw *hw,
0800 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
0801 {
0802 struct rt2x00_dev *rt2x00dev = hw->priv;
0803 struct data_queue *queue;
0804
0805 tx_queue_for_each(rt2x00dev, queue) {
0806 *tx += queue->length;
0807 *tx_max += queue->limit;
0808 }
0809
0810 *rx = rt2x00dev->rx->length;
0811 *rx_max = rt2x00dev->rx->limit;
0812 }
0813 EXPORT_SYMBOL_GPL(rt2x00mac_get_ringparam);
0814
0815 bool rt2x00mac_tx_frames_pending(struct ieee80211_hw *hw)
0816 {
0817 struct rt2x00_dev *rt2x00dev = hw->priv;
0818 struct data_queue *queue;
0819
0820 tx_queue_for_each(rt2x00dev, queue) {
0821 if (!rt2x00queue_empty(queue))
0822 return true;
0823 }
0824
0825 return false;
0826 }
0827 EXPORT_SYMBOL_GPL(rt2x00mac_tx_frames_pending);