1531 lines · 38.2 KB · C
RawDownload
/*	Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>	Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com>	<http://rt2x00.serialmonkey.com> 	This program is free software; you can redistribute it and/or modify	it under the terms of the GNU General Public License as published by	the Free Software Foundation; either version 2 of the License, or	(at your option) any later version. 	This program is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the	GNU General Public License for more details. 	You should have received a copy of the GNU General Public License	along with this program; if not, write to the	Free Software Foundation, Inc.,	59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*	Module: rt2x00lib	Abstract: rt2x00 generic device routines. */ #include <linux/kernel.h>#include <linux/module.h>#include <linux/slab.h>#include <linux/log2.h> #include "rt2x00.h"#include "rt2x00lib.h" /* * Utility functions. */u32 rt2x00lib_get_bssidx(struct rt2x00_dev *rt2x00dev,			 struct ieee80211_vif *vif){	/*	 * When in STA mode, bssidx is always 0 otherwise local_address[5]	 * contains the bss number, see BSS_ID_MASK comments for details.	 */	if (rt2x00dev->intf_sta_count)		return 0;	return vif->addr[5] & (rt2x00dev->ops->max_ap_intf - 1);}EXPORT_SYMBOL_GPL(rt2x00lib_get_bssidx); /* * Radio control handlers. */int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev){	int status; 	/*	 * Don't enable the radio twice.	 * And check if the hardware button has been disabled.	 */	if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))		return 0; 	/*	 * Initialize all data queues.	 */	rt2x00queue_init_queues(rt2x00dev); 	/*	 * Enable radio.	 */	status =	    rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_ON);	if (status)		return status; 	rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON); 	rt2x00leds_led_radio(rt2x00dev, true);	rt2x00led_led_activity(rt2x00dev, true); 	set_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags); 	/*	 * Enable queues.	 */	rt2x00queue_start_queues(rt2x00dev);	rt2x00link_start_tuner(rt2x00dev);	rt2x00link_start_agc(rt2x00dev);	if (rt2x00_has_cap_vco_recalibration(rt2x00dev))		rt2x00link_start_vcocal(rt2x00dev); 	/*	 * Start watchdog monitoring.	 */	rt2x00link_start_watchdog(rt2x00dev); 	return 0;} void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev){	if (!test_and_clear_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))		return; 	/*	 * Stop watchdog monitoring.	 */	rt2x00link_stop_watchdog(rt2x00dev); 	/*	 * Stop all queues	 */	rt2x00link_stop_agc(rt2x00dev);	if (rt2x00_has_cap_vco_recalibration(rt2x00dev))		rt2x00link_stop_vcocal(rt2x00dev);	rt2x00link_stop_tuner(rt2x00dev);	rt2x00queue_stop_queues(rt2x00dev);	rt2x00queue_flush_queues(rt2x00dev, true); 	/*	 * Disable radio.	 */	rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);	rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);	rt2x00led_led_activity(rt2x00dev, false);	rt2x00leds_led_radio(rt2x00dev, false);} static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,					  struct ieee80211_vif *vif){	struct rt2x00_dev *rt2x00dev = data;	struct rt2x00_intf *intf = vif_to_intf(vif); 	/*	 * It is possible the radio was disabled while the work had been	 * scheduled. If that happens we should return here immediately,	 * note that in the spinlock protected area above the delayed_flags	 * have been cleared correctly.	 */	if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))		return; 	if (test_and_clear_bit(DELAYED_UPDATE_BEACON, &intf->delayed_flags))		rt2x00queue_update_beacon(rt2x00dev, vif);} static void rt2x00lib_intf_scheduled(struct work_struct *work){	struct rt2x00_dev *rt2x00dev =	    container_of(work, struct rt2x00_dev, intf_work); 	/*	 * Iterate over each interface and perform the	 * requested configurations.	 */	ieee80211_iterate_active_interfaces(rt2x00dev->hw,					    IEEE80211_IFACE_ITER_RESUME_ALL,					    rt2x00lib_intf_scheduled_iter,					    rt2x00dev);} static void rt2x00lib_autowakeup(struct work_struct *work){	struct rt2x00_dev *rt2x00dev =	    container_of(work, struct rt2x00_dev, autowakeup_work.work); 	if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))		return; 	if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))		rt2x00_err(rt2x00dev, "Device failed to wakeup\n");	clear_bit(CONFIG_POWERSAVING, &rt2x00dev->flags);} /* * Interrupt context handlers. */static void rt2x00lib_bc_buffer_iter(void *data, u8 *mac,				     struct ieee80211_vif *vif){	struct ieee80211_tx_control control = {};	struct rt2x00_dev *rt2x00dev = data;	struct sk_buff *skb; 	/*	 * Only AP mode interfaces do broad- and multicast buffering	 */	if (vif->type != NL80211_IFTYPE_AP)		return; 	/*	 * Send out buffered broad- and multicast frames	 */	skb = ieee80211_get_buffered_bc(rt2x00dev->hw, vif);	while (skb) {		rt2x00mac_tx(rt2x00dev->hw, &control, skb);		skb = ieee80211_get_buffered_bc(rt2x00dev->hw, vif);	}} static void rt2x00lib_beaconupdate_iter(void *data, u8 *mac,					struct ieee80211_vif *vif){	struct rt2x00_dev *rt2x00dev = data; 	if (vif->type != NL80211_IFTYPE_AP &&	    vif->type != NL80211_IFTYPE_ADHOC &&	    vif->type != NL80211_IFTYPE_MESH_POINT &&	    vif->type != NL80211_IFTYPE_WDS)		return; 	/*	 * Update the beacon without locking. This is safe on PCI devices	 * as they only update the beacon periodically here. This should	 * never be called for USB devices.	 */	WARN_ON(rt2x00_is_usb(rt2x00dev));	rt2x00queue_update_beacon_locked(rt2x00dev, vif);} void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev){	if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))		return; 	/* send buffered bc/mc frames out for every bssid */	ieee80211_iterate_active_interfaces_atomic(		rt2x00dev->hw, IEEE80211_IFACE_ITER_RESUME_ALL,		rt2x00lib_bc_buffer_iter, rt2x00dev);	/*	 * Devices with pre tbtt interrupt don't need to update the beacon	 * here as they will fetch the next beacon directly prior to	 * transmission.	 */	if (rt2x00_has_cap_pre_tbtt_interrupt(rt2x00dev))		return; 	/* fetch next beacon */	ieee80211_iterate_active_interfaces_atomic(		rt2x00dev->hw, IEEE80211_IFACE_ITER_RESUME_ALL,		rt2x00lib_beaconupdate_iter, rt2x00dev);}EXPORT_SYMBOL_GPL(rt2x00lib_beacondone); void rt2x00lib_pretbtt(struct rt2x00_dev *rt2x00dev){	if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))		return; 	/* fetch next beacon */	ieee80211_iterate_active_interfaces_atomic(		rt2x00dev->hw, IEEE80211_IFACE_ITER_RESUME_ALL,		rt2x00lib_beaconupdate_iter, rt2x00dev);}EXPORT_SYMBOL_GPL(rt2x00lib_pretbtt); void rt2x00lib_dmastart(struct queue_entry *entry){	set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);	rt2x00queue_index_inc(entry, Q_INDEX);}EXPORT_SYMBOL_GPL(rt2x00lib_dmastart); void rt2x00lib_dmadone(struct queue_entry *entry){	set_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags);	clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);	rt2x00queue_index_inc(entry, Q_INDEX_DMA_DONE);}EXPORT_SYMBOL_GPL(rt2x00lib_dmadone); static inline int rt2x00lib_txdone_bar_status(struct queue_entry *entry){	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;	struct ieee80211_bar *bar = (void *) entry->skb->data;	struct rt2x00_bar_list_entry *bar_entry;	int ret; 	if (likely(!ieee80211_is_back_req(bar->frame_control)))		return 0; 	/*	 * Unlike all other frames, the status report for BARs does	 * not directly come from the hardware as it is incapable of	 * matching a BA to a previously send BAR. The hardware will	 * report all BARs as if they weren't acked at all.	 *	 * Instead the RX-path will scan for incoming BAs and set the	 * block_acked flag if it sees one that was likely caused by	 * a BAR from us.	 *	 * Remove remaining BARs here and return their status for	 * TX done processing.	 */	ret = 0;	rcu_read_lock();	list_for_each_entry_rcu(bar_entry, &rt2x00dev->bar_list, list) {		if (bar_entry->entry != entry)			continue; 		spin_lock_bh(&rt2x00dev->bar_list_lock);		/* Return whether this BAR was blockacked or not */		ret = bar_entry->block_acked;		/* Remove the BAR from our checklist */		list_del_rcu(&bar_entry->list);		spin_unlock_bh(&rt2x00dev->bar_list_lock);		kfree_rcu(bar_entry, head); 		break;	}	rcu_read_unlock(); 	return ret;} void rt2x00lib_txdone(struct queue_entry *entry,		      struct txdone_entry_desc *txdesc){	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);	unsigned int header_length, i;	u8 rate_idx, rate_flags, retry_rates;	u8 skbdesc_flags = skbdesc->flags;	bool success; 	/*	 * Unmap the skb.	 */	rt2x00queue_unmap_skb(entry); 	/*	 * Remove the extra tx headroom from the skb.	 */	skb_pull(entry->skb, rt2x00dev->extra_tx_headroom); 	/*	 * Signal that the TX descriptor is no longer in the skb.	 */	skbdesc->flags &= ~SKBDESC_DESC_IN_SKB; 	/*	 * Determine the length of 802.11 header.	 */	header_length = ieee80211_get_hdrlen_from_skb(entry->skb); 	/*	 * Remove L2 padding which was added during	 */	if (test_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags))		rt2x00queue_remove_l2pad(entry->skb, header_length); 	/*	 * If the IV/EIV data was stripped from the frame before it was	 * passed to the hardware, we should now reinsert it again because	 * mac80211 will expect the same data to be present it the	 * frame as it was passed to us.	 */	if (rt2x00_has_cap_hw_crypto(rt2x00dev))		rt2x00crypto_tx_insert_iv(entry->skb, header_length); 	/*	 * Send frame to debugfs immediately, after this call is completed	 * we are going to overwrite the skb->cb array.	 */	rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry->skb); 	/*	 * Determine if the frame has been successfully transmitted and	 * remove BARs from our check list while checking for their	 * TX status.	 */	success =	    rt2x00lib_txdone_bar_status(entry) ||	    test_bit(TXDONE_SUCCESS, &txdesc->flags) ||	    test_bit(TXDONE_UNKNOWN, &txdesc->flags); 	/*	 * Update TX statistics.	 */	rt2x00dev->link.qual.tx_success += success;	rt2x00dev->link.qual.tx_failed += !success; 	rate_idx = skbdesc->tx_rate_idx;	rate_flags = skbdesc->tx_rate_flags;	retry_rates = test_bit(TXDONE_FALLBACK, &txdesc->flags) ?	    (txdesc->retry + 1) : 1; 	/*	 * Initialize TX status	 */	memset(&tx_info->status, 0, sizeof(tx_info->status));	tx_info->status.ack_signal = 0; 	/*	 * Frame was send with retries, hardware tried	 * different rates to send out the frame, at each	 * retry it lowered the rate 1 step except when the	 * lowest rate was used.	 */	for (i = 0; i < retry_rates && i < IEEE80211_TX_MAX_RATES; i++) {		tx_info->status.rates[i].idx = rate_idx - i;		tx_info->status.rates[i].flags = rate_flags; 		if (rate_idx - i == 0) {			/*			 * The lowest rate (index 0) was used until the			 * number of max retries was reached.			 */			tx_info->status.rates[i].count = retry_rates - i;			i++;			break;		}		tx_info->status.rates[i].count = 1;	}	if (i < (IEEE80211_TX_MAX_RATES - 1))		tx_info->status.rates[i].idx = -1; /* terminate */ 	if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) {		if (success)			tx_info->flags |= IEEE80211_TX_STAT_ACK;		else			rt2x00dev->low_level_stats.dot11ACKFailureCount++;	} 	/*	 * Every single frame has it's own tx status, hence report	 * every frame as ampdu of size 1.	 *	 * TODO: if we can find out how many frames were aggregated	 * by the hw we could provide the real ampdu_len to mac80211	 * which would allow the rc algorithm to better decide on	 * which rates are suitable.	 */	if (test_bit(TXDONE_AMPDU, &txdesc->flags) ||	    tx_info->flags & IEEE80211_TX_CTL_AMPDU) {		tx_info->flags |= IEEE80211_TX_STAT_AMPDU;		tx_info->status.ampdu_len = 1;		tx_info->status.ampdu_ack_len = success ? 1 : 0; 		if (!success)			tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;	} 	if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {		if (success)			rt2x00dev->low_level_stats.dot11RTSSuccessCount++;		else			rt2x00dev->low_level_stats.dot11RTSFailureCount++;	} 	/*	 * Only send the status report to mac80211 when it's a frame	 * that originated in mac80211. If this was a extra frame coming	 * through a mac80211 library call (RTS/CTS) then we should not	 * send the status report back.	 */	if (!(skbdesc_flags & SKBDESC_NOT_MAC80211)) {		if (test_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags))			ieee80211_tx_status(rt2x00dev->hw, entry->skb);		else			ieee80211_tx_status_ni(rt2x00dev->hw, entry->skb);	} else		dev_kfree_skb_any(entry->skb); 	/*	 * Make this entry available for reuse.	 */	entry->skb = NULL;	entry->flags = 0; 	rt2x00dev->ops->lib->clear_entry(entry); 	rt2x00queue_index_inc(entry, Q_INDEX_DONE); 	/*	 * If the data queue was below the threshold before the txdone	 * handler we must make sure the packet queue in the mac80211 stack	 * is reenabled when the txdone handler has finished. This has to be	 * serialized with rt2x00mac_tx(), otherwise we can wake up queue	 * before it was stopped.	 */	spin_lock_bh(&entry->queue->tx_lock);	if (!rt2x00queue_threshold(entry->queue))		rt2x00queue_unpause_queue(entry->queue);	spin_unlock_bh(&entry->queue->tx_lock);}EXPORT_SYMBOL_GPL(rt2x00lib_txdone); void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status){	struct txdone_entry_desc txdesc; 	txdesc.flags = 0;	__set_bit(status, &txdesc.flags);	txdesc.retry = 0; 

Lines 1–500 of 1531.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t