| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Atheros AR9170 driver | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * mac80211 interaction code | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> | 
					
						
							|  |  |  |  * Copyright 2009, Christian Lamparter <chunkeey@web.de> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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; see the file COPYING.  If not, see | 
					
						
							|  |  |  |  * http://www.gnu.org/licenses/.
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file incorporates work covered by the following copyright and | 
					
						
							|  |  |  |  * permission notice: | 
					
						
							|  |  |  |  *    Copyright (c) 2007-2008 Atheros Communications, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    Permission to use, copy, modify, and/or distribute this software for any | 
					
						
							|  |  |  |  *    purpose with or without fee is hereby granted, provided that the above | 
					
						
							|  |  |  |  *    copyright notice and this permission notice appear in all copies. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
					
						
							|  |  |  |  *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
					
						
							|  |  |  |  *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 
					
						
							|  |  |  |  *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
					
						
							|  |  |  |  *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
					
						
							|  |  |  |  *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 
					
						
							|  |  |  |  *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							| 
									
										
											  
											
												include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files.  percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed.  Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability.  As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
  http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
  only the necessary includes are there.  ie. if only gfp is used,
  gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
  blocks and try to put the new include such that its order conforms
  to its surrounding.  It's put in the include block which contains
  core kernel includes, in the same order that the rest are ordered -
  alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
  doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
  because the file doesn't have fitting include block), it prints out
  an error message indicating which .h file needs to be added to the
  file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
   over 4000 files, deleting around 700 includes and adding ~480 gfp.h
   and ~3000 slab.h inclusions.  The script emitted errors for ~400
   files.
2. Each error was manually checked.  Some didn't need the inclusion,
   some needed manual addition while adding it to implementation .h or
   embedding .c file was more appropriate for others.  This step added
   inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
   from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
   e.g. lib/decompress_*.c used malloc/free() wrappers around slab
   APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
   editing them as sprinkling gfp.h and slab.h inclusions around .h
   files could easily lead to inclusion dependency hell.  Most gfp.h
   inclusion directives were ignored as stuff from gfp.h was usually
   wildly available and often used in preprocessor macros.  Each
   slab.h inclusion directive was examined and added manually as
   necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
   were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
   distributed build env didn't work with gcov compiles) and a few
   more options had to be turned off depending on archs to make things
   build (like ipr on powerpc/64 which failed due to missing writeq).
   * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
   * powerpc and powerpc64 SMP allmodconfig
   * sparc and sparc64 SMP allmodconfig
   * ia64 SMP allmodconfig
   * s390 SMP allmodconfig
   * alpha SMP allmodconfig
   * um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
   a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
											
										 
											2010-03-24 17:04:11 +09:00
										 |  |  | #include <linux/slab.h>
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/etherdevice.h>
 | 
					
						
							|  |  |  | #include <net/mac80211.h>
 | 
					
						
							|  |  |  | #include "ar9170.h"
 | 
					
						
							|  |  |  | #include "hw.h"
 | 
					
						
							|  |  |  | #include "cmd.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int modparam_nohwcrypt; | 
					
						
							|  |  |  | module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); | 
					
						
							|  |  |  | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define RATE(_bitrate, _hw_rate, _txpidx, _flags) {	\
 | 
					
						
							|  |  |  | 	.bitrate	= (_bitrate),			\ | 
					
						
							|  |  |  | 	.flags		= (_flags),			\ | 
					
						
							|  |  |  | 	.hw_value	= (_hw_rate) | (_txpidx) << 4,	\ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ieee80211_rate __ar9170_ratetable[] = { | 
					
						
							|  |  |  | 	RATE(10, 0, 0, 0), | 
					
						
							|  |  |  | 	RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE), | 
					
						
							|  |  |  | 	RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE), | 
					
						
							|  |  |  | 	RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE), | 
					
						
							|  |  |  | 	RATE(60, 0xb, 0, 0), | 
					
						
							|  |  |  | 	RATE(90, 0xf, 0, 0), | 
					
						
							|  |  |  | 	RATE(120, 0xa, 0, 0), | 
					
						
							|  |  |  | 	RATE(180, 0xe, 0, 0), | 
					
						
							|  |  |  | 	RATE(240, 0x9, 0, 0), | 
					
						
							|  |  |  | 	RATE(360, 0xd, 1, 0), | 
					
						
							|  |  |  | 	RATE(480, 0x8, 2, 0), | 
					
						
							|  |  |  | 	RATE(540, 0xc, 3, 0), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #undef RATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define ar9170_g_ratetable	(__ar9170_ratetable + 0)
 | 
					
						
							|  |  |  | #define ar9170_g_ratetable_size	12
 | 
					
						
							|  |  |  | #define ar9170_a_ratetable	(__ar9170_ratetable + 4)
 | 
					
						
							|  |  |  | #define ar9170_a_ratetable_size	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * NB: The hw_value is used as an index into the ar9170_phy_freq_params | 
					
						
							|  |  |  |  *     array in phy.c so that we don't have to do frequency lookups! | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define CHAN(_freq, _idx) {		\
 | 
					
						
							|  |  |  | 	.center_freq	= (_freq),	\ | 
					
						
							|  |  |  | 	.hw_value	= (_idx),	\ | 
					
						
							|  |  |  | 	.max_power	= 18, /* XXX */	\ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ieee80211_channel ar9170_2ghz_chantable[] = { | 
					
						
							|  |  |  | 	CHAN(2412,  0), | 
					
						
							|  |  |  | 	CHAN(2417,  1), | 
					
						
							|  |  |  | 	CHAN(2422,  2), | 
					
						
							|  |  |  | 	CHAN(2427,  3), | 
					
						
							|  |  |  | 	CHAN(2432,  4), | 
					
						
							|  |  |  | 	CHAN(2437,  5), | 
					
						
							|  |  |  | 	CHAN(2442,  6), | 
					
						
							|  |  |  | 	CHAN(2447,  7), | 
					
						
							|  |  |  | 	CHAN(2452,  8), | 
					
						
							|  |  |  | 	CHAN(2457,  9), | 
					
						
							|  |  |  | 	CHAN(2462, 10), | 
					
						
							|  |  |  | 	CHAN(2467, 11), | 
					
						
							|  |  |  | 	CHAN(2472, 12), | 
					
						
							|  |  |  | 	CHAN(2484, 13), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ieee80211_channel ar9170_5ghz_chantable[] = { | 
					
						
							|  |  |  | 	CHAN(4920, 14), | 
					
						
							|  |  |  | 	CHAN(4940, 15), | 
					
						
							|  |  |  | 	CHAN(4960, 16), | 
					
						
							|  |  |  | 	CHAN(4980, 17), | 
					
						
							|  |  |  | 	CHAN(5040, 18), | 
					
						
							|  |  |  | 	CHAN(5060, 19), | 
					
						
							|  |  |  | 	CHAN(5080, 20), | 
					
						
							|  |  |  | 	CHAN(5180, 21), | 
					
						
							|  |  |  | 	CHAN(5200, 22), | 
					
						
							|  |  |  | 	CHAN(5220, 23), | 
					
						
							|  |  |  | 	CHAN(5240, 24), | 
					
						
							|  |  |  | 	CHAN(5260, 25), | 
					
						
							|  |  |  | 	CHAN(5280, 26), | 
					
						
							|  |  |  | 	CHAN(5300, 27), | 
					
						
							|  |  |  | 	CHAN(5320, 28), | 
					
						
							|  |  |  | 	CHAN(5500, 29), | 
					
						
							|  |  |  | 	CHAN(5520, 30), | 
					
						
							|  |  |  | 	CHAN(5540, 31), | 
					
						
							|  |  |  | 	CHAN(5560, 32), | 
					
						
							|  |  |  | 	CHAN(5580, 33), | 
					
						
							|  |  |  | 	CHAN(5600, 34), | 
					
						
							|  |  |  | 	CHAN(5620, 35), | 
					
						
							|  |  |  | 	CHAN(5640, 36), | 
					
						
							|  |  |  | 	CHAN(5660, 37), | 
					
						
							|  |  |  | 	CHAN(5680, 38), | 
					
						
							|  |  |  | 	CHAN(5700, 39), | 
					
						
							|  |  |  | 	CHAN(5745, 40), | 
					
						
							|  |  |  | 	CHAN(5765, 41), | 
					
						
							|  |  |  | 	CHAN(5785, 42), | 
					
						
							|  |  |  | 	CHAN(5805, 43), | 
					
						
							|  |  |  | 	CHAN(5825, 44), | 
					
						
							|  |  |  | 	CHAN(5170, 45), | 
					
						
							|  |  |  | 	CHAN(5190, 46), | 
					
						
							|  |  |  | 	CHAN(5210, 47), | 
					
						
							|  |  |  | 	CHAN(5230, 48), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #undef CHAN
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | #define AR9170_HT_CAP							\
 | 
					
						
							|  |  |  | {									\ | 
					
						
							|  |  |  | 	.ht_supported	= true,						\ | 
					
						
							|  |  |  | 	.cap		= IEEE80211_HT_CAP_MAX_AMSDU |			\ | 
					
						
							|  |  |  | 			  IEEE80211_HT_CAP_SUP_WIDTH_20_40 |		\ | 
					
						
							|  |  |  | 			  IEEE80211_HT_CAP_SGI_40 |			\ | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 			  IEEE80211_HT_CAP_GRN_FLD |			\ | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 			  IEEE80211_HT_CAP_DSSSCCK40 |			\ | 
					
						
							|  |  |  | 			  IEEE80211_HT_CAP_SM_PS,			\ | 
					
						
							| 
									
										
										
										
											2009-04-24 21:35:57 +02:00
										 |  |  | 	.ampdu_factor	= 3,						\ | 
					
						
							|  |  |  | 	.ampdu_density	= 6,						\ | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 	.mcs		= {						\ | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 		.rx_mask = { 0xff, 0xff, 0, 0, 0x1, 0, 0, 0, 0, 0, },	\ | 
					
						
							|  |  |  | 		.rx_highest = cpu_to_le16(300),				\ | 
					
						
							|  |  |  | 		.tx_params = IEEE80211_HT_MCS_TX_DEFINED,		\ | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 	},								\ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static struct ieee80211_supported_band ar9170_band_2GHz = { | 
					
						
							|  |  |  | 	.channels	= ar9170_2ghz_chantable, | 
					
						
							|  |  |  | 	.n_channels	= ARRAY_SIZE(ar9170_2ghz_chantable), | 
					
						
							|  |  |  | 	.bitrates	= ar9170_g_ratetable, | 
					
						
							|  |  |  | 	.n_bitrates	= ar9170_g_ratetable_size, | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 	.ht_cap		= AR9170_HT_CAP, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ieee80211_supported_band ar9170_band_5GHz = { | 
					
						
							|  |  |  | 	.channels	= ar9170_5ghz_chantable, | 
					
						
							|  |  |  | 	.n_channels	= ARRAY_SIZE(ar9170_5ghz_chantable), | 
					
						
							|  |  |  | 	.bitrates	= ar9170_a_ratetable, | 
					
						
							|  |  |  | 	.n_bitrates	= ar9170_a_ratetable_size, | 
					
						
							|  |  |  | 	.ht_cap		= AR9170_HT_CAP, | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void ar9170_tx(struct ar9170 *ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | static inline u16 ar9170_get_seq_h(struct ieee80211_hdr *hdr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return le16_to_cpu(hdr->seq_ctrl) >> 4; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline u16 ar9170_get_seq(struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170_tx_control *txc = (void *) skb->data; | 
					
						
							|  |  |  | 	return ar9170_get_seq_h((void *) txc->frame_data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static void ar9170_print_txheader(struct ar9170 *ar, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170_tx_control *txc = (void *) skb->data; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	struct ar9170_tx_info *arinfo = (void *) txinfo->rate_driver_data; | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr = (void *) txc->frame_data; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 	wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 		    "=> FRAME [skb:%p, q:%d, DA:[%pM] s:%d " | 
					
						
							|  |  |  | 		    "mac_ctrl:%04x, phy_ctrl:%08x, timeout:[%d ms]]\n", | 
					
						
							|  |  |  | 		    skb, skb_get_queue_mapping(skb), | 
					
						
							|  |  |  | 		    ieee80211_get_DA(hdr), ar9170_get_seq_h(hdr), | 
					
						
							|  |  |  | 		    le16_to_cpu(txc->mac_control), le32_to_cpu(txc->phy_control), | 
					
						
							|  |  |  | 		    jiffies_to_msecs(arinfo->timeout - jiffies)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void __ar9170_dump_txqueue(struct ar9170 *ar, | 
					
						
							|  |  |  | 				struct sk_buff_head *queue) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_DEBUG "---[ cut here ]---\n"); | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 	wiphy_debug(ar->hw->wiphy, "%d entries in queue.\n", | 
					
						
							|  |  |  | 		    skb_queue_len(queue)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_walk(queue, skb) { | 
					
						
							| 
									
										
										
										
											2010-03-31 15:07:48 +01:00
										 |  |  | 		printk(KERN_DEBUG "index:%d =>\n", i++); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		ar9170_print_txheader(ar, skb); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	if (i != skb_queue_len(queue)) | 
					
						
							|  |  |  | 		printk(KERN_DEBUG "WARNING: queue frame counter " | 
					
						
							|  |  |  | 		       "mismatch %d != %d\n", skb_queue_len(queue), i); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	printk(KERN_DEBUG "---[ end ]---\n"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void ar9170_dump_txqueue(struct ar9170 *ar, | 
					
						
							|  |  |  | 				struct sk_buff_head *queue) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&queue->lock, flags); | 
					
						
							|  |  |  | 	__ar9170_dump_txqueue(ar, queue); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&queue->lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | #ifdef AR9170_QUEUE_STOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void __ar9170_dump_txstats(struct ar9170 *ar) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-11 19:11:19 -07:00
										 |  |  | 	wiphy_debug(ar->hw->wiphy, "QoS queue stats\n"); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 			    "queue:%d limit:%d len:%d waitack:%d stopped:%d\n", | 
					
						
							|  |  |  | 			    i, ar->tx_stats[i].limit, ar->tx_stats[i].len, | 
					
						
							|  |  |  | 			    skb_queue_len(&ar->tx_status[i]), | 
					
						
							|  |  |  | 			    ieee80211_queue_stopped(ar->hw, i)); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | #endif /* AR9170_QUEUE_STOP_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* caller must guarantee exclusive access for _bin_ queue. */ | 
					
						
							|  |  |  | static void ar9170_recycle_expired(struct ar9170 *ar, | 
					
						
							|  |  |  | 				   struct sk_buff_head *queue, | 
					
						
							|  |  |  | 				   struct sk_buff_head *bin) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb, *old = NULL; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&queue->lock, flags); | 
					
						
							|  |  |  | 	while ((skb = skb_peek(queue))) { | 
					
						
							|  |  |  | 		struct ieee80211_tx_info *txinfo; | 
					
						
							|  |  |  | 		struct ar9170_tx_info *arinfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txinfo = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 		arinfo = (void *) txinfo->rate_driver_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (time_is_before_jiffies(arinfo->timeout)) { | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 				    "[%ld > %ld] frame expired => recycle\n", | 
					
						
							|  |  |  | 				    jiffies, arinfo->timeout); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ar9170_print_txheader(ar, skb); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 			__skb_unlink(skb, queue); | 
					
						
							|  |  |  | 			__skb_queue_tail(bin, skb); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (unlikely(old == skb)) { | 
					
						
							|  |  |  | 			/* bail out - queue is shot. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			WARN_ON(1); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		old = skb; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&queue->lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ar9170_tx_status(struct ar9170 *ar, struct sk_buff *skb, | 
					
						
							|  |  |  | 				    u16 tx_status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *txinfo; | 
					
						
							|  |  |  | 	unsigned int retries = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	txinfo = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	ieee80211_tx_info_clear_status(txinfo); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (tx_status) { | 
					
						
							|  |  |  | 	case AR9170_TX_STATUS_RETRY: | 
					
						
							|  |  |  | 		retries = 2; | 
					
						
							|  |  |  | 	case AR9170_TX_STATUS_COMPLETE: | 
					
						
							|  |  |  | 		txinfo->flags |= IEEE80211_TX_STAT_ACK; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case AR9170_TX_STATUS_FAILED: | 
					
						
							|  |  |  | 		retries = ar->hw->conf.long_frame_max_tx_count; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 			  "invalid tx_status response (%x)\n", tx_status); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	txinfo->status.rates[0].count = retries + 1; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	skb_pull(skb, sizeof(struct ar9170_tx_control)); | 
					
						
							|  |  |  | 	ieee80211_tx_status_irqsafe(ar->hw, skb); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | void ar9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	struct ar9170_tx_info *arinfo = (void *) info->rate_driver_data; | 
					
						
							|  |  |  | 	unsigned int queue = skb_get_queue_mapping(skb); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	spin_lock_irqsave(&ar->tx_stats_lock, flags); | 
					
						
							|  |  |  | 	ar->tx_stats[queue].len--; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 00:52:51 +01:00
										 |  |  | 	if (ar->tx_stats[queue].len < AR9170_NUM_TX_LIMIT_SOFT) { | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | #ifdef AR9170_QUEUE_STOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, "wake queue %d\n", queue); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		__ar9170_dump_txstats(ar); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_STOP_DEBUG */
 | 
					
						
							|  |  |  | 		ieee80211_wake_queue(ar->hw, queue); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 00:56:55 +01:00
										 |  |  | 	if (info->flags & IEEE80211_TX_CTL_NO_ACK) { | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		ar9170_tx_status(ar, skb, AR9170_TX_STATUS_FAILED); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 		arinfo->timeout = jiffies + | 
					
						
							|  |  |  | 			  msecs_to_jiffies(AR9170_TX_TIMEOUT); | 
					
						
							| 
									
										
										
										
											2009-11-29 00:56:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 		skb_queue_tail(&ar->tx_status[queue], skb); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ar->tx_stats[queue].len && | 
					
						
							|  |  |  | 	    !skb_queue_empty(&ar->tx_pending[queue])) { | 
					
						
							|  |  |  | 		ar9170_tx(ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static struct sk_buff *ar9170_get_queued_skb(struct ar9170 *ar, | 
					
						
							|  |  |  | 					     const u8 *mac, | 
					
						
							|  |  |  | 					     struct sk_buff_head *queue, | 
					
						
							|  |  |  | 					     const u32 rate) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	unsigned long flags; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Unfortunately, the firmware does not tell to which (queued) frame | 
					
						
							|  |  |  | 	 * this transmission status report belongs to. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * So we have to make risky guesses - with the scarce information | 
					
						
							|  |  |  | 	 * the firmware provided (-> destination MAC, and phy_control) - | 
					
						
							|  |  |  | 	 * and hope that we picked the right one... | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	spin_lock_irqsave(&queue->lock, flags); | 
					
						
							|  |  |  | 	skb_queue_walk(queue, skb) { | 
					
						
							|  |  |  | 		struct ar9170_tx_control *txc = (void *) skb->data; | 
					
						
							|  |  |  | 		struct ieee80211_hdr *hdr = (void *) txc->frame_data; | 
					
						
							|  |  |  | 		u32 r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mac && compare_ether_addr(ieee80211_get_DA(hdr), mac)) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							| 
									
										
										
										
											2010-08-11 19:11:19 -07:00
										 |  |  | 				    "skip frame => DA %pM != %pM\n", | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 				    mac, ieee80211_get_DA(hdr)); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ar9170_print_txheader(ar, skb); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		r = (le32_to_cpu(txc->phy_control) & AR9170_TX_PHY_MCS_MASK) >> | 
					
						
							|  |  |  | 		    AR9170_TX_PHY_MCS_SHIFT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ((rate != AR9170_TX_INVALID_RATE) && (r != rate)) { | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 				    "skip frame => rate %d != %d\n", rate, r); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ar9170_print_txheader(ar, skb); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		__skb_unlink(skb, queue); | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&queue->lock, flags); | 
					
						
							|  |  |  | 		return skb; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 	wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 		  "ESS:[%pM] does not have any outstanding frames in queue.\n", | 
					
						
							|  |  |  | 		  mac); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	__ar9170_dump_txqueue(ar, queue); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	spin_unlock_irqrestore(&queue->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  |  * This worker tries to keeps an maintain tx_status queues. | 
					
						
							|  |  |  |  * So we can guarantee that incoming tx_status reports are | 
					
						
							|  |  |  |  * actually for a pending frame. | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void ar9170_tx_janitor(struct work_struct *work) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = container_of(work, struct ar9170, | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 					 tx_janitor.work); | 
					
						
							|  |  |  | 	struct sk_buff_head waste; | 
					
						
							|  |  |  | 	unsigned int i; | 
					
						
							|  |  |  | 	bool resched = false; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 12:15:43 +01:00
										 |  |  | 	if (unlikely(!IS_STARTED(ar))) | 
					
						
							|  |  |  | 		return ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	skb_queue_head_init(&waste); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, "garbage collector scans queue:%d\n", | 
					
						
							|  |  |  | 			    i); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		ar9170_dump_txqueue(ar, &ar->tx_pending[i]); | 
					
						
							|  |  |  | 		ar9170_dump_txqueue(ar, &ar->tx_status[i]); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		ar9170_recycle_expired(ar, &ar->tx_status[i], &waste); | 
					
						
							|  |  |  | 		ar9170_recycle_expired(ar, &ar->tx_pending[i], &waste); | 
					
						
							|  |  |  | 		skb_queue_purge(&waste); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		if (!skb_queue_empty(&ar->tx_status[i]) || | 
					
						
							|  |  |  | 		    !skb_queue_empty(&ar->tx_pending[i])) | 
					
						
							|  |  |  | 			resched = true; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-29 20:08:07 -04:00
										 |  |  | 	if (!resched) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ieee80211_queue_delayed_work(ar->hw, | 
					
						
							|  |  |  | 				     &ar->tx_janitor, | 
					
						
							|  |  |  | 				     msecs_to_jiffies(AR9170_JANITOR_DELAY)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-28 17:04:27 +02:00
										 |  |  | void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ar9170_cmd_response *cmd = (void *) buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((cmd->type & 0xc0) != 0xc0) { | 
					
						
							|  |  |  | 		ar->callback_cmd(ar, len, buf); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* hardware event handlers */ | 
					
						
							|  |  |  | 	switch (cmd->type) { | 
					
						
							|  |  |  | 	case 0xc1: { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * TX status notification: | 
					
						
							|  |  |  | 		 * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1 | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * XX always 81 | 
					
						
							|  |  |  | 		 * YY always 00 | 
					
						
							|  |  |  | 		 * M1-M6 is the MAC address | 
					
						
							|  |  |  | 		 * R1-R4 is the transmit rate | 
					
						
							|  |  |  | 		 * S1-S2 is the transmit status | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		struct sk_buff *skb; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		u32 phy = le32_to_cpu(cmd->tx_status.rate); | 
					
						
							|  |  |  | 		u32 q = (phy & AR9170_TX_PHY_QOS_MASK) >> | 
					
						
							|  |  |  | 			AR9170_TX_PHY_QOS_SHIFT; | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 			    "recv tx_status for %pm, p:%08x, q:%d\n", | 
					
						
							|  |  |  | 			    cmd->tx_status.dst, phy, q); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		skb = ar9170_get_queued_skb(ar, cmd->tx_status.dst, | 
					
						
							|  |  |  | 					    &ar->tx_status[q], | 
					
						
							|  |  |  | 					    AR9170_TX_INVALID_RATE); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		if (unlikely(!skb)) | 
					
						
							|  |  |  | 			return ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		ar9170_tx_status(ar, skb, le16_to_cpu(cmd->tx_status.status)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc0: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * pre-TBTT event | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP) | 
					
						
							| 
									
										
										
										
											2009-07-29 20:08:07 -04:00
										 |  |  | 			ieee80211_queue_work(ar->hw, &ar->beacon_work); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc2: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * (IBSS) beacon send notification | 
					
						
							|  |  |  | 		 * bytes: 04 c2 XX YY B4 B3 B2 B1 | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * XX always 80 | 
					
						
							|  |  |  | 		 * YY always 00 | 
					
						
							|  |  |  | 		 * B1-B4 "should" be the number of send out beacons. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc3: | 
					
						
							|  |  |  | 		/* End of Atim Window */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc4: | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 		/* BlockACK bitmap */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	case 0xc5: | 
					
						
							|  |  |  | 		/* BlockACK events */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc6: | 
					
						
							|  |  |  | 		/* Watchdog Interrupt */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 0xc9: | 
					
						
							|  |  |  | 		/* retransmission issue / SIFS/EIFS collision ?! */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-05 11:47:43 +02:00
										 |  |  | 	/* firmware debug */ | 
					
						
							|  |  |  | 	case 0xca: | 
					
						
							| 
									
										
										
										
											2010-03-31 15:07:48 +01:00
										 |  |  | 		printk(KERN_DEBUG "ar9170 FW: %.*s\n", len - 4, | 
					
						
							|  |  |  | 				(char *)buf + 4); | 
					
						
							| 
									
										
										
										
											2009-06-05 11:47:43 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case 0xcb: | 
					
						
							|  |  |  | 		len -= 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (len) { | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			printk(KERN_DEBUG "ar9170 FW: u8: %#.2x\n", | 
					
						
							|  |  |  | 				*((char *)buf + 4)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			printk(KERN_DEBUG "ar9170 FW: u8: %#.4x\n", | 
					
						
							|  |  |  | 				le16_to_cpup((__le16 *)((char *)buf + 4))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 			printk(KERN_DEBUG "ar9170 FW: u8: %#.8x\n", | 
					
						
							|  |  |  | 				le32_to_cpup((__le32 *)((char *)buf + 4))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 8: | 
					
						
							|  |  |  | 			printk(KERN_DEBUG "ar9170 FW: u8: %#.16lx\n", | 
					
						
							|  |  |  | 				(unsigned long)le64_to_cpup( | 
					
						
							|  |  |  | 						(__le64 *)((char *)buf + 4))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 0xcc: | 
					
						
							|  |  |  | 		print_hex_dump_bytes("ar9170 FW:", DUMP_PREFIX_NONE, | 
					
						
							|  |  |  | 				     (char *)buf + 4, len - 4); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		pr_info("received unhandled event %x\n", cmd->type); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | static void ar9170_rx_reset_rx_mpdu(struct ar9170 *ar) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	memset(&ar->rx_mpdu.plcp, 0, sizeof(struct ar9170_rx_head)); | 
					
						
							|  |  |  | 	ar->rx_mpdu.has_plcp = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | int ar9170_nag_limiter(struct ar9170 *ar) | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	bool print_message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * we expect all sorts of errors in promiscuous mode. | 
					
						
							|  |  |  | 	 * don't bother with it, it's OK! | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (ar->sniffer_enabled) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * only go for frequent errors! The hardware tends to | 
					
						
							|  |  |  | 	 * do some stupid thing once in a while under load, in | 
					
						
							|  |  |  | 	 * noisy environments or just for fun! | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (time_before(jiffies, ar->bad_hw_nagger) && net_ratelimit()) | 
					
						
							|  |  |  | 		print_message = true; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		print_message = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* reset threshold for "once in a while" */ | 
					
						
							|  |  |  | 	ar->bad_hw_nagger = jiffies + HZ / 4; | 
					
						
							|  |  |  | 	return print_message; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_rx_mac_status(struct ar9170 *ar, | 
					
						
							|  |  |  | 				struct ar9170_rx_head *head, | 
					
						
							|  |  |  | 				struct ar9170_rx_macstatus *mac, | 
					
						
							|  |  |  | 				struct ieee80211_rx_status *status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 error, decrypt; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	BUILD_BUG_ON(sizeof(struct ar9170_rx_macstatus) != 4); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	error = mac->error; | 
					
						
							|  |  |  | 	if (error & AR9170_RX_ERROR_MMIC) { | 
					
						
							|  |  |  | 		status->flag |= RX_FLAG_MMIC_ERROR; | 
					
						
							|  |  |  | 		error &= ~AR9170_RX_ERROR_MMIC; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (error & AR9170_RX_ERROR_PLCP) { | 
					
						
							|  |  |  | 		status->flag |= RX_FLAG_FAILED_PLCP_CRC; | 
					
						
							|  |  |  | 		error &= ~AR9170_RX_ERROR_PLCP; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (!(ar->filter_state & FIF_PLCPFAIL)) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (error & AR9170_RX_ERROR_FCS) { | 
					
						
							|  |  |  | 		status->flag |= RX_FLAG_FAILED_FCS_CRC; | 
					
						
							|  |  |  | 		error &= ~AR9170_RX_ERROR_FCS; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (!(ar->filter_state & FIF_FCSFAIL)) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	decrypt = ar9170_get_decrypt_type(mac); | 
					
						
							|  |  |  | 	if (!(decrypt & AR9170_RX_ENC_SOFTWARE) && | 
					
						
							|  |  |  | 	    decrypt != AR9170_ENC_ALG_NONE) | 
					
						
							|  |  |  | 		status->flag |= RX_FLAG_DECRYPTED; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	/* ignore wrong RA errors */ | 
					
						
							|  |  |  | 	error &= ~AR9170_RX_ERROR_WRONG_RA; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (error & AR9170_RX_ERROR_DECRYPT) { | 
					
						
							|  |  |  | 		error &= ~AR9170_RX_ERROR_DECRYPT; | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Rx decryption is done in place, | 
					
						
							|  |  |  | 		 * the original data is lost anyway. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* drop any other error frames */ | 
					
						
							|  |  |  | 	if (unlikely(error)) { | 
					
						
							|  |  |  | 		/* TODO: update netdevice's RX dropped/errors statistics */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 				    "received frame with suspicious error code (%#x).\n", | 
					
						
							|  |  |  | 				    error); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status->band = ar->channel->band; | 
					
						
							|  |  |  | 	status->freq = ar->channel->center_freq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (mac->status & AR9170_RX_STATUS_MODULATION_MASK) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	case AR9170_RX_STATUS_MODULATION_CCK: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (mac->status & AR9170_RX_STATUS_SHORT_PREAMBLE) | 
					
						
							|  |  |  | 			status->flag |= RX_FLAG_SHORTPRE; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		switch (head->plcp[0]) { | 
					
						
							|  |  |  | 		case 0x0a: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 0x14: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 1; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 0x37: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 2; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 0x6e: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 3; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 				wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 					  "invalid plcp cck rate (%x).\n", | 
					
						
							|  |  |  | 					  head->plcp[0]); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-14 00:57:58 +01:00
										 |  |  | 	case AR9170_RX_STATUS_MODULATION_DUPOFDM: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	case AR9170_RX_STATUS_MODULATION_OFDM: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		switch (head->plcp[0] & 0xf) { | 
					
						
							|  |  |  | 		case 0xb: | 
					
						
							|  |  |  | 			status->rate_idx = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		case 0xf: | 
					
						
							|  |  |  | 			status->rate_idx = 1; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		case 0xa: | 
					
						
							|  |  |  | 			status->rate_idx = 2; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		case 0xe: | 
					
						
							|  |  |  | 			status->rate_idx = 3; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 0x9: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 4; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		case 0xd: | 
					
						
							|  |  |  | 			status->rate_idx = 5; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 0x8: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			status->rate_idx = 6; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		case 0xc: | 
					
						
							|  |  |  | 			status->rate_idx = 7; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 				wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 					  "invalid plcp ofdm rate (%x).\n", | 
					
						
							|  |  |  | 					  head->plcp[0]); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (status->band == IEEE80211_BAND_2GHZ) | 
					
						
							|  |  |  | 			status->rate_idx += 4; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	case AR9170_RX_STATUS_MODULATION_HT: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (head->plcp[3] & 0x80) | 
					
						
							|  |  |  | 			status->flag |= RX_FLAG_40MHZ; | 
					
						
							|  |  |  | 		if (head->plcp[6] & 0x80) | 
					
						
							|  |  |  | 			status->flag |= RX_FLAG_SHORT_GI; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		status->rate_idx = clamp(0, 75, head->plcp[6] & 0x7f); | 
					
						
							|  |  |  | 		status->flag |= RX_FLAG_HT; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-14 00:57:58 +01:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_err(ar->hw->wiphy, "invalid modulation\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | static void ar9170_rx_phy_status(struct ar9170 *ar, | 
					
						
							|  |  |  | 				 struct ar9170_rx_phystatus *phy, | 
					
						
							|  |  |  | 				 struct ieee80211_rx_status *status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	BUILD_BUG_ON(sizeof(struct ar9170_rx_phystatus) != 20); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < 3; i++) | 
					
						
							|  |  |  | 		if (phy->rssi[i] != 0x80) | 
					
						
							|  |  |  | 			status->antenna |= BIT(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* post-process RSSI */ | 
					
						
							|  |  |  | 	for (i = 0; i < 7; i++) | 
					
						
							|  |  |  | 		if (phy->rssi[i] & 0x80) | 
					
						
							|  |  |  | 			phy->rssi[i] = ((phy->rssi[i] & 0x7f) + 1) & 0x7f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO: we could do something with phy_errors */ | 
					
						
							|  |  |  | 	status->signal = ar->noise[0] + phy->rssi_combined; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct sk_buff *ar9170_rx_copy_data(u8 *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	int reserved = 0; | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr = (void *) buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ieee80211_is_data_qos(hdr->frame_control)) { | 
					
						
							|  |  |  | 		u8 *qc = ieee80211_get_qos_ctl(hdr); | 
					
						
							|  |  |  | 		reserved += NET_IP_ALIGN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) | 
					
						
							|  |  |  | 			reserved += NET_IP_ALIGN; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (ieee80211_has_a4(hdr->frame_control)) | 
					
						
							|  |  |  | 		reserved += NET_IP_ALIGN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	reserved = 32 + (reserved & NET_IP_ALIGN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb = dev_alloc_skb(len + reserved); | 
					
						
							|  |  |  | 	if (likely(skb)) { | 
					
						
							|  |  |  | 		skb_reserve(skb, reserved); | 
					
						
							|  |  |  | 		memcpy(skb_put(skb, len), buf, len); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	return skb; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * If the frame alignment is right (or the kernel has | 
					
						
							|  |  |  |  * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there | 
					
						
							|  |  |  |  * is only a single MPDU in the USB frame, then we could | 
					
						
							|  |  |  |  * submit to mac80211 the SKB directly. However, since | 
					
						
							|  |  |  |  * there may be multiple packets in one SKB in stream | 
					
						
							|  |  |  |  * mode, and we need to observe the proper ordering, | 
					
						
							|  |  |  |  * this is non-trivial. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170_rx_head *head; | 
					
						
							|  |  |  | 	struct ar9170_rx_macstatus *mac; | 
					
						
							|  |  |  | 	struct ar9170_rx_phystatus *phy = NULL; | 
					
						
							|  |  |  | 	struct ieee80211_rx_status status; | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	int mpdu_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(!IS_STARTED(ar) || len < (sizeof(*mac)))) | 
					
						
							|  |  |  | 		return ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Received MPDU */ | 
					
						
							|  |  |  | 	mpdu_len = len - sizeof(*mac); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mac = (void *)(buf + mpdu_len); | 
					
						
							|  |  |  | 	if (unlikely(mac->error & AR9170_RX_ERROR_FATAL)) { | 
					
						
							|  |  |  | 		/* this frame is too damaged and can't be used - drop it */ | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return ; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	switch (mac->status & AR9170_RX_STATUS_MPDU_MASK) { | 
					
						
							|  |  |  | 	case AR9170_RX_STATUS_MPDU_FIRST: | 
					
						
							|  |  |  | 		/* first mpdu packet has the plcp header */ | 
					
						
							|  |  |  | 		if (likely(mpdu_len >= sizeof(struct ar9170_rx_head))) { | 
					
						
							|  |  |  | 			head = (void *) buf; | 
					
						
							|  |  |  | 			memcpy(&ar->rx_mpdu.plcp, (void *) buf, | 
					
						
							|  |  |  | 			       sizeof(struct ar9170_rx_head)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			mpdu_len -= sizeof(struct ar9170_rx_head); | 
					
						
							|  |  |  | 			buf += sizeof(struct ar9170_rx_head); | 
					
						
							|  |  |  | 			ar->rx_mpdu.has_plcp = true; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 				wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 					  "plcp info is clipped.\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case AR9170_RX_STATUS_MPDU_LAST: | 
					
						
							|  |  |  | 		/* last mpdu has a extra tail with phy status information */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (likely(mpdu_len >= sizeof(struct ar9170_rx_phystatus))) { | 
					
						
							|  |  |  | 			mpdu_len -= sizeof(struct ar9170_rx_phystatus); | 
					
						
							|  |  |  | 			phy = (void *)(buf + mpdu_len); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (ar9170_nag_limiter(ar)) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 				wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 					  "frame tail is clipped.\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case AR9170_RX_STATUS_MPDU_MIDDLE: | 
					
						
							|  |  |  | 		/* middle mpdus are just data */ | 
					
						
							|  |  |  | 		if (unlikely(!ar->rx_mpdu.has_plcp)) { | 
					
						
							|  |  |  | 			if (!ar9170_nag_limiter(ar)) | 
					
						
							|  |  |  | 				return ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 				  "rx stream did not start with a first_mpdu frame tag.\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		head = &ar->rx_mpdu.plcp; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case AR9170_RX_STATUS_MPDU_SINGLE: | 
					
						
							|  |  |  | 		/* single mpdu - has plcp (head) and phy status (tail) */ | 
					
						
							|  |  |  | 		head = (void *) buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mpdu_len -= sizeof(struct ar9170_rx_head); | 
					
						
							|  |  |  | 		mpdu_len -= sizeof(struct ar9170_rx_phystatus); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		buf += sizeof(struct ar9170_rx_head); | 
					
						
							|  |  |  | 		phy = (void *)(buf + mpdu_len); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		BUG_ON(1); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (unlikely(mpdu_len < FCS_LEN)) | 
					
						
							|  |  |  | 		return ; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	memset(&status, 0, sizeof(status)); | 
					
						
							|  |  |  | 	if (unlikely(ar9170_rx_mac_status(ar, head, mac, &status))) | 
					
						
							|  |  |  | 		return ; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (phy) | 
					
						
							|  |  |  | 		ar9170_rx_phy_status(ar, phy, &status); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	skb = ar9170_rx_copy_data(buf, mpdu_len); | 
					
						
							| 
									
										
										
										
											2009-06-17 13:13:00 +02:00
										 |  |  | 	if (likely(skb)) { | 
					
						
							|  |  |  | 		memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); | 
					
						
							|  |  |  | 		ieee80211_rx_irqsafe(ar->hw, skb); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	unsigned int i, tlen, resplen, wlen = 0, clen = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	u8 *tbuf, *respbuf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tbuf = skb->data; | 
					
						
							|  |  |  | 	tlen = skb->len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (tlen >= 4) { | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		clen = tbuf[1] << 8 | tbuf[0]; | 
					
						
							|  |  |  | 		wlen = ALIGN(clen, 4); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		/* check if this is stream has a valid tag.*/ | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		if (tbuf[2] != 0 || tbuf[3] != 0x4e) { | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * TODO: handle the highly unlikely event that the | 
					
						
							|  |  |  | 			 * corrupted stream has the TAG at the right position. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* check if the frame can be repaired. */ | 
					
						
							|  |  |  | 			if (!ar->rx_failover_missing) { | 
					
						
							|  |  |  | 				/* this is no "short read". */ | 
					
						
							|  |  |  | 				if (ar9170_nag_limiter(ar)) { | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 					wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 						  "missing tag!\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 					goto err_telluser; | 
					
						
							|  |  |  | 				} else | 
					
						
							|  |  |  | 					goto err_silent; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (ar->rx_failover_missing > tlen) { | 
					
						
							|  |  |  | 				if (ar9170_nag_limiter(ar)) { | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 					wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 						  "possible multi stream corruption!\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 					goto err_telluser; | 
					
						
							|  |  |  | 				} else | 
					
						
							|  |  |  | 					goto err_silent; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen); | 
					
						
							|  |  |  | 			ar->rx_failover_missing -= tlen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (ar->rx_failover_missing <= 0) { | 
					
						
							|  |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * nested ar9170_rx call! | 
					
						
							|  |  |  | 				 * termination is guranteed, even when the | 
					
						
							|  |  |  | 				 * combined frame also have a element with | 
					
						
							|  |  |  | 				 * a bad tag. | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				ar->rx_failover_missing = 0; | 
					
						
							|  |  |  | 				ar9170_rx(ar, ar->rx_failover); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				skb_reset_tail_pointer(ar->rx_failover); | 
					
						
							|  |  |  | 				skb_trim(ar->rx_failover, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* check if stream is clipped */ | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		if (wlen > tlen - 4) { | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			if (ar->rx_failover_missing) { | 
					
						
							|  |  |  | 				/* TODO: handle double stream corruption. */ | 
					
						
							|  |  |  | 				if (ar9170_nag_limiter(ar)) { | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 					wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 						  "double rx stream corruption!\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 					goto err_telluser; | 
					
						
							|  |  |  | 				} else | 
					
						
							|  |  |  | 					goto err_silent; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * save incomplete data set. | 
					
						
							|  |  |  | 			 * the firmware will resend the missing bits when | 
					
						
							|  |  |  | 			 * the rx - descriptor comes round again. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen); | 
					
						
							|  |  |  | 			ar->rx_failover_missing = clen - tlen; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		resplen = clen; | 
					
						
							|  |  |  | 		respbuf = tbuf + 4; | 
					
						
							|  |  |  | 		tbuf += wlen + 4; | 
					
						
							|  |  |  | 		tlen -= wlen + 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* weird thing, but this is the same in the original driver */ | 
					
						
							|  |  |  | 		while (resplen > 2 && i < 12 && | 
					
						
							|  |  |  | 		       respbuf[0] == 0xff && respbuf[1] == 0xff) { | 
					
						
							|  |  |  | 			i += 2; | 
					
						
							|  |  |  | 			resplen -= 2; | 
					
						
							|  |  |  | 			respbuf += 2; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (resplen < 4) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* found the 6 * 0xffff marker? */ | 
					
						
							|  |  |  | 		if (i == 12) | 
					
						
							|  |  |  | 			ar9170_handle_command_response(ar, respbuf, resplen); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 			ar9170_handle_mpdu(ar, respbuf, clen); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (tlen) { | 
					
						
							|  |  |  | 		if (net_ratelimit()) | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 				  "%d bytes of unprocessed data left in rx stream!\n", | 
					
						
							|  |  |  | 				  tlen); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		goto err_telluser; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_telluser: | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 	wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 		  "damaged RX stream data [want:%d, data:%d, rx:%d, pending:%d ]\n", | 
					
						
							|  |  |  | 		  clen, wlen, tlen, ar->rx_failover_missing); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ar->rx_failover_missing) | 
					
						
							|  |  |  | 		print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET, | 
					
						
							|  |  |  | 				     ar->rx_failover->data, | 
					
						
							|  |  |  | 				     ar->rx_failover->len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET, | 
					
						
							|  |  |  | 			     skb->data, skb->len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 	wiphy_err(ar->hw->wiphy, | 
					
						
							|  |  |  | 		  "If you see this message frequently, please check your hardware and cables.\n"); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | err_silent: | 
					
						
							|  |  |  | 	if (ar->rx_failover_missing) { | 
					
						
							|  |  |  | 		skb_reset_tail_pointer(ar->rx_failover); | 
					
						
							|  |  |  | 		skb_trim(ar->rx_failover, 0); | 
					
						
							|  |  |  | 		ar->rx_failover_missing = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop)		\
 | 
					
						
							|  |  |  | do {									\ | 
					
						
							|  |  |  | 	queue.aifs = ai_fs;						\ | 
					
						
							|  |  |  | 	queue.cw_min = cwmin;						\ | 
					
						
							|  |  |  | 	queue.cw_max = cwmax;						\ | 
					
						
							|  |  |  | 	queue.txop = _txop;						\ | 
					
						
							|  |  |  | } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_op_start(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	int err, i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* reinitialize queues statistics */ | 
					
						
							|  |  |  | 	memset(&ar->tx_stats, 0, sizeof(ar->tx_stats)); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) | 
					
						
							|  |  |  | 		ar->tx_stats[i].limit = AR9170_TXQ_DEPTH; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* reset QoS defaults */ | 
					
						
							|  |  |  | 	AR9170_FILL_QUEUE(ar->edcf[0], 3, 15, 1023,  0); /* BEST EFFORT*/ | 
					
						
							|  |  |  | 	AR9170_FILL_QUEUE(ar->edcf[1], 7, 15, 1023,  0); /* BACKGROUND */ | 
					
						
							|  |  |  | 	AR9170_FILL_QUEUE(ar->edcf[2], 2, 7,    15, 94); /* VIDEO */ | 
					
						
							|  |  |  | 	AR9170_FILL_QUEUE(ar->edcf[3], 2, 3,     7, 47); /* VOICE */ | 
					
						
							|  |  |  | 	AR9170_FILL_QUEUE(ar->edcf[4], 2, 3,     7,  0); /* SPECIAL */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 	/* set sane AMPDU defaults */ | 
					
						
							|  |  |  | 	ar->global_ampdu_density = 6; | 
					
						
							|  |  |  | 	ar->global_ampdu_factor = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	ar->bad_hw_nagger = jiffies; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	err = ar->open(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ar9170_init_mac(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ar9170_set_qos(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ar9170_init_phy(ar, IEEE80211_BAND_2GHZ); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ar9170_init_rf(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* start DMA */ | 
					
						
							|  |  |  | 	err = ar9170_write_reg(ar, 0x1c3d30, 0x100); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ar->state = AR9170_STARTED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ar9170_op_stop(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	unsigned int i; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_STARTED(ar)) | 
					
						
							|  |  |  | 		ar->state = AR9170_IDLE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	cancel_delayed_work_sync(&ar->tx_janitor); | 
					
						
							| 
									
										
										
										
											2009-07-24 11:55:44 +04:00
										 |  |  | #ifdef CONFIG_AR9170_LEDS
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 	cancel_delayed_work_sync(&ar->led_work); | 
					
						
							| 
									
										
										
										
											2009-07-24 11:55:44 +04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	cancel_work_sync(&ar->beacon_work); | 
					
						
							| 
									
										
										
										
											2009-07-27 12:51:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-23 20:31:21 +02:00
										 |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_ACCEPTING_CMD(ar)) { | 
					
						
							|  |  |  | 		ar9170_set_leds_state(ar, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* stop DMA */ | 
					
						
							|  |  |  | 		ar9170_write_reg(ar, 0x1c3d30, 0); | 
					
						
							|  |  |  | 		ar->stop(ar); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) { | 
					
						
							|  |  |  | 		skb_queue_purge(&ar->tx_pending[i]); | 
					
						
							|  |  |  | 		skb_queue_purge(&ar->tx_status[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static int ar9170_tx_prepare(struct ar9170 *ar, struct sk_buff *skb) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr; | 
					
						
							|  |  |  | 	struct ar9170_tx_control *txc; | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info; | 
					
						
							|  |  |  | 	struct ieee80211_tx_rate *txrate; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	struct ar9170_tx_info *arinfo; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	unsigned int queue = skb_get_queue_mapping(skb); | 
					
						
							|  |  |  | 	u16 keytype = 0; | 
					
						
							|  |  |  | 	u16 len, icv = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	BUILD_BUG_ON(sizeof(*arinfo) > sizeof(info->rate_driver_data)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hdr = (void *)skb->data; | 
					
						
							|  |  |  | 	info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	len = skb->len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	txc = (void *)skb_push(skb, sizeof(*txc)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (info->control.hw_key) { | 
					
						
							|  |  |  | 		icv = info->control.hw_key->icv_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 		switch (info->control.hw_key->cipher) { | 
					
						
							|  |  |  | 		case WLAN_CIPHER_SUITE_WEP40: | 
					
						
							|  |  |  | 		case WLAN_CIPHER_SUITE_WEP104: | 
					
						
							|  |  |  | 		case WLAN_CIPHER_SUITE_TKIP: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			keytype = AR9170_TX_MAC_ENCR_RC4; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 		case WLAN_CIPHER_SUITE_CCMP: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			keytype = AR9170_TX_MAC_ENCR_AES; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			WARN_ON(1); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			goto err_out; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Length */ | 
					
						
							|  |  |  | 	txc->length = cpu_to_le16(len + icv + 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	txc->mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION | | 
					
						
							|  |  |  | 				       AR9170_TX_MAC_BACKOFF); | 
					
						
							|  |  |  | 	txc->mac_control |= cpu_to_le16(ar9170_qos_hwmap[queue] << | 
					
						
							|  |  |  | 					AR9170_TX_MAC_QOS_SHIFT); | 
					
						
							|  |  |  | 	txc->mac_control |= cpu_to_le16(keytype); | 
					
						
							|  |  |  | 	txc->phy_control = cpu_to_le32(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (info->flags & IEEE80211_TX_CTL_NO_ACK) | 
					
						
							|  |  |  | 		txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_NO_ACK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	txrate = &info->control.rates[0]; | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) | 
					
						
							|  |  |  | 		txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS); | 
					
						
							|  |  |  | 	else if (txrate->flags & IEEE80211_TX_RC_USE_RTS_CTS) | 
					
						
							|  |  |  | 		txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	arinfo = (void *)info->rate_driver_data; | 
					
						
							|  |  |  | 	arinfo->timeout = jiffies + msecs_to_jiffies(AR9170_QUEUE_TIMEOUT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && | 
					
						
							|  |  |  | 	     (is_valid_ether_addr(ieee80211_get_DA(hdr)))) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * WARNING: | 
					
						
							|  |  |  | 		 * Putting the QoS queue bits into an unexplored territory is | 
					
						
							|  |  |  | 		 * certainly not elegant. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * In my defense: This idea provides a reasonable way to | 
					
						
							|  |  |  | 		 * smuggle valuable information to the tx_status callback. | 
					
						
							|  |  |  | 		 * Also, the idea behind this bit-abuse came straight from | 
					
						
							|  |  |  | 		 * the original driver code. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txc->phy_control |= | 
					
						
							|  |  |  | 			cpu_to_le32(queue << AR9170_TX_PHY_QOS_SHIFT); | 
					
						
							| 
									
										
										
										
											2009-11-29 00:56:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 		txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_out: | 
					
						
							|  |  |  | 	skb_pull(skb, sizeof(*txc)); | 
					
						
							|  |  |  | 	return -EINVAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ar9170_tx_prepare_phy(struct ar9170 *ar, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170_tx_control *txc; | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info; | 
					
						
							|  |  |  | 	struct ieee80211_rate *rate = NULL; | 
					
						
							|  |  |  | 	struct ieee80211_tx_rate *txrate; | 
					
						
							|  |  |  | 	u32 power, chains; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	txc = (void *) skb->data; | 
					
						
							|  |  |  | 	info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	txrate = &info->control.rates[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD) | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ); | 
					
						
							|  |  |  | 	/* this works because 40 MHz is 2 and dup is 3 */ | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_DUP_DATA) | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_SHORT_GI) | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (txrate->flags & IEEE80211_TX_RC_MCS) { | 
					
						
							|  |  |  | 		u32 r = txrate->idx; | 
					
						
							|  |  |  | 		u8 *txpower; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		/* heavy clip control */ | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32((r & 0x7) << 7); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		r <<= AR9170_TX_PHY_MCS_SHIFT; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		BUG_ON(r & ~AR9170_TX_PHY_MCS_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		txc->phy_control |= cpu_to_le32(r & AR9170_TX_PHY_MCS_MASK); | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_MOD_HT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) { | 
					
						
							|  |  |  | 			if (info->band == IEEE80211_BAND_5GHZ) | 
					
						
							|  |  |  | 				txpower = ar->power_5G_ht40; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				txpower = ar->power_2G_ht40; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (info->band == IEEE80211_BAND_5GHZ) | 
					
						
							|  |  |  | 				txpower = ar->power_5G_ht20; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				txpower = ar->power_2G_ht20; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		power = txpower[(txrate->idx) & 7]; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		u8 *txpower; | 
					
						
							|  |  |  | 		u32 mod; | 
					
						
							|  |  |  | 		u32 phyrate; | 
					
						
							|  |  |  | 		u8 idx = txrate->idx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (info->band != IEEE80211_BAND_2GHZ) { | 
					
						
							|  |  |  | 			idx += 4; | 
					
						
							|  |  |  | 			txpower = ar->power_5G_leg; | 
					
						
							|  |  |  | 			mod = AR9170_TX_PHY_MOD_OFDM; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (idx < 4) { | 
					
						
							|  |  |  | 				txpower = ar->power_2G_cck; | 
					
						
							|  |  |  | 				mod = AR9170_TX_PHY_MOD_CCK; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				mod = AR9170_TX_PHY_MOD_OFDM; | 
					
						
							|  |  |  | 				txpower = ar->power_2G_ofdm; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		rate = &__ar9170_ratetable[idx]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		phyrate = rate->hw_value & 0xF; | 
					
						
							|  |  |  | 		power = txpower[(rate->hw_value & 0x30) >> 4]; | 
					
						
							|  |  |  | 		phyrate <<= AR9170_TX_PHY_MCS_SHIFT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(mod); | 
					
						
							|  |  |  | 		txc->phy_control |= cpu_to_le32(phyrate); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	power <<= AR9170_TX_PHY_TX_PWR_SHIFT; | 
					
						
							|  |  |  | 	power &= AR9170_TX_PHY_TX_PWR_MASK; | 
					
						
							|  |  |  | 	txc->phy_control |= cpu_to_le32(power); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set TX chains */ | 
					
						
							|  |  |  | 	if (ar->eeprom.tx_mask == 1) { | 
					
						
							|  |  |  | 		chains = AR9170_TX_PHY_TXCHAIN_1; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		chains = AR9170_TX_PHY_TXCHAIN_2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* >= 36M legacy OFDM - use only one chain */ | 
					
						
							|  |  |  | 		if (rate && rate->bitrate >= 360) | 
					
						
							|  |  |  | 			chains = AR9170_TX_PHY_TXCHAIN_1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	txc->phy_control |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_SHIFT); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | static void ar9170_tx(struct ar9170 *ar) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info; | 
					
						
							|  |  |  | 	struct ar9170_tx_info *arinfo; | 
					
						
							|  |  |  | 	unsigned int i, frames, frames_failed, remaining_space; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	bool schedule_garbagecollector = false; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	BUILD_BUG_ON(sizeof(*arinfo) > sizeof(info->rate_driver_data)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	if (unlikely(!IS_STARTED(ar))) | 
					
						
							|  |  |  | 		return ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	remaining_space = AR9170_TX_MAX_PENDING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) { | 
					
						
							|  |  |  | 		spin_lock_irqsave(&ar->tx_stats_lock, flags); | 
					
						
							| 
									
										
										
										
											2009-11-29 00:52:51 +01:00
										 |  |  | 		frames = min(ar->tx_stats[i].limit - ar->tx_stats[i].len, | 
					
						
							|  |  |  | 			     skb_queue_len(&ar->tx_pending[i])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (remaining_space < frames) { | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 				    "tx quota reached queue:%d, " | 
					
						
							|  |  |  | 				    "remaining slots:%d, needed:%d\n", | 
					
						
							|  |  |  | 				    i, remaining_space, frames); | 
					
						
							| 
									
										
										
										
											2009-11-29 00:52:51 +01:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 			frames = remaining_space; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ar->tx_stats[i].len += frames; | 
					
						
							|  |  |  | 		ar->tx_stats[i].count += frames; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		if (ar->tx_stats[i].len >= ar->tx_stats[i].limit) { | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, "queue %d full\n", i); | 
					
						
							|  |  |  | 			wiphy_debug(ar->hw->wiphy, "stuck frames: ===>\n"); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ar9170_dump_txqueue(ar, &ar->tx_pending[i]); | 
					
						
							|  |  |  | 			ar9170_dump_txqueue(ar, &ar->tx_status[i]); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_STOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, "stop queue %d\n", i); | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 			__ar9170_dump_txstats(ar); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_STOP_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ieee80211_stop_queue(ar->hw, i); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!frames) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		frames_failed = 0; | 
					
						
							|  |  |  | 		while (frames) { | 
					
						
							|  |  |  | 			skb = skb_dequeue(&ar->tx_pending[i]); | 
					
						
							|  |  |  | 			if (unlikely(!skb)) { | 
					
						
							|  |  |  | 				frames_failed += frames; | 
					
						
							|  |  |  | 				frames = 0; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 			arinfo = (void *) info->rate_driver_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* TODO: cancel stuck frames */ | 
					
						
							|  |  |  | 			arinfo->timeout = jiffies + | 
					
						
							|  |  |  | 					  msecs_to_jiffies(AR9170_TX_TIMEOUT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, "send frame q:%d =>\n", i); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ar9170_print_txheader(ar, skb); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			err = ar->tx(ar, skb); | 
					
						
							|  |  |  | 			if (unlikely(err)) { | 
					
						
							|  |  |  | 				frames_failed++; | 
					
						
							|  |  |  | 				dev_kfree_skb_any(skb); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				remaining_space--; | 
					
						
							|  |  |  | 				schedule_garbagecollector = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			frames--; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 			    "ar9170_tx report for queue %d\n", i); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 		wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 			    "unprocessed pending frames left:\n"); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 		ar9170_dump_txqueue(ar, &ar->tx_pending[i]); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (unlikely(frames_failed)) { | 
					
						
							|  |  |  | #ifdef AR9170_QUEUE_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, | 
					
						
							|  |  |  | 				    "frames failed %d =>\n", frames_failed); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | #endif /* AR9170_QUEUE_DEBUG */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			spin_lock_irqsave(&ar->tx_stats_lock, flags); | 
					
						
							|  |  |  | 			ar->tx_stats[i].len -= frames_failed; | 
					
						
							|  |  |  | 			ar->tx_stats[i].count -= frames_failed; | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | #ifdef AR9170_QUEUE_STOP_DEBUG
 | 
					
						
							| 
									
										
										
										
											2010-07-26 14:39:58 -07:00
										 |  |  | 			wiphy_debug(ar->hw->wiphy, "wake queue %d\n", i); | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 			__ar9170_dump_txstats(ar); | 
					
						
							|  |  |  | #endif /* AR9170_QUEUE_STOP_DEBUG */
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 			ieee80211_wake_queue(ar->hw, i); | 
					
						
							|  |  |  | 			spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-29 20:08:07 -04:00
										 |  |  | 	if (!schedule_garbagecollector) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ieee80211_queue_delayed_work(ar->hw, | 
					
						
							|  |  |  | 				     &ar->tx_janitor, | 
					
						
							|  |  |  | 				     msecs_to_jiffies(AR9170_JANITOR_DELAY)); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info; | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 	unsigned int queue; | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(!IS_STARTED(ar))) | 
					
						
							|  |  |  | 		goto err_free; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(ar9170_tx_prepare(ar, skb))) | 
					
						
							|  |  |  | 		goto err_free; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 	queue = skb_get_queue_mapping(skb); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	info = IEEE80211_SKB_CB(skb); | 
					
						
							| 
									
										
										
										
											2010-05-01 18:18:18 +02:00
										 |  |  | 	ar9170_tx_prepare_phy(ar, skb); | 
					
						
							|  |  |  | 	skb_queue_tail(&ar->tx_pending[queue], skb); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	ar9170_tx(ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	return NETDEV_TX_OK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_free: | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	dev_kfree_skb_any(skb); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	return NETDEV_TX_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_op_add_interface(struct ieee80211_hw *hw, | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:45 +01:00
										 |  |  | 				   struct ieee80211_vif *vif) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							| 
									
										
										
										
											2009-09-10 10:10:54 -07:00
										 |  |  | 	struct ath_common *common = &ar->common; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ar->vif) { | 
					
						
							|  |  |  | 		err = -EBUSY; | 
					
						
							|  |  |  | 		goto unlock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:45 +01:00
										 |  |  | 	ar->vif = vif; | 
					
						
							|  |  |  | 	memcpy(common->macaddr, vif->addr, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (modparam_nohwcrypt || (ar->vif->type != NL80211_IFTYPE_STATION)) { | 
					
						
							|  |  |  | 		ar->rx_software_decryption = true; | 
					
						
							|  |  |  | 		ar->disable_offload = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ar->cur_filter = 0; | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 	err = ar9170_update_frame_filter(ar, AR9170_MAC_REG_FTF_DEFAULTS); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto unlock; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = ar9170_set_operating_mode(ar); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unlock: | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ar9170_op_remove_interface(struct ieee80211_hw *hw, | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:45 +01:00
										 |  |  | 				       struct ieee80211_vif *vif) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 	ar->vif = NULL; | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 	ar9170_update_frame_filter(ar, 0); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	ar9170_set_beacon_timers(ar); | 
					
						
							|  |  |  | 	dev_kfree_skb(ar->beacon); | 
					
						
							|  |  |  | 	ar->beacon = NULL; | 
					
						
							|  |  |  | 	ar->sniffer_enabled = false; | 
					
						
							|  |  |  | 	ar->rx_software_decryption = false; | 
					
						
							|  |  |  | 	ar9170_set_operating_mode(ar); | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { | 
					
						
							|  |  |  | 		/* TODO */ | 
					
						
							|  |  |  | 		err = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & IEEE80211_CONF_CHANGE_PS) { | 
					
						
							|  |  |  | 		/* TODO */ | 
					
						
							|  |  |  | 		err = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & IEEE80211_CONF_CHANGE_POWER) { | 
					
						
							|  |  |  | 		/* TODO */ | 
					
						
							|  |  |  | 		err = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * is it long_frame_max_tx_count or short_frame_max_tx_count? | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ar9170_set_hwretry_limit(ar, | 
					
						
							|  |  |  | 			ar->hw->conf.long_frame_max_tx_count); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* adjust slot time for 5 GHz */ | 
					
						
							|  |  |  | 		err = ar9170_set_slot_time(ar); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ar9170_set_dyn_sifs_ack(ar); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		err = ar9170_set_channel(ar, hw->conf.channel, | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 				AR9170_RFI_NONE, | 
					
						
							|  |  |  | 				nl80211_to_ar9170(hw->conf.channel_type)); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-01 21:22:57 +00:00
										 |  |  | static u64 ar9170_op_prepare_multicast(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				       struct netdev_hw_addr_list *mc_list) | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	u64 mchash; | 
					
						
							| 
									
										
										
										
											2010-04-01 21:22:57 +00:00
										 |  |  | 	struct netdev_hw_addr *ha; | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* always get broadcast frames */ | 
					
						
							|  |  |  | 	mchash = 1ULL << (0xff >> 2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-01 21:22:57 +00:00
										 |  |  | 	netdev_hw_addr_list_for_each(ha, mc_list) | 
					
						
							|  |  |  | 		mchash |= 1ULL << (ha->addr[5] >> 2); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return mchash; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static void ar9170_op_configure_filter(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				       unsigned int changed_flags, | 
					
						
							|  |  |  | 				       unsigned int *new_flags, | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | 				       u64 multicast) | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 	if (unlikely(!IS_ACCEPTING_CMD(ar))) | 
					
						
							|  |  |  | 		return ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	/* mask supported flags */ | 
					
						
							|  |  |  | 	*new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC | | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		      FIF_PROMISC_IN_BSS | FIF_FCSFAIL | FIF_PLCPFAIL; | 
					
						
							|  |  |  | 	ar->filter_state = *new_flags; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * We can support more by setting the sniffer bit and | 
					
						
							|  |  |  | 	 * then checking the error flags, later. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | 	if (changed_flags & FIF_ALLMULTI && *new_flags & FIF_ALLMULTI) | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 		multicast = ~0ULL; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 	if (multicast != ar->cur_mc_hash) | 
					
						
							|  |  |  | 		ar9170_update_multicast(ar, multicast); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (changed_flags & FIF_CONTROL) { | 
					
						
							|  |  |  | 		u32 filter = AR9170_MAC_REG_FTF_PSPOLL | | 
					
						
							|  |  |  | 			     AR9170_MAC_REG_FTF_RTS | | 
					
						
							|  |  |  | 			     AR9170_MAC_REG_FTF_CTS | | 
					
						
							|  |  |  | 			     AR9170_MAC_REG_FTF_ACK | | 
					
						
							|  |  |  | 			     AR9170_MAC_REG_FTF_CFE | | 
					
						
							|  |  |  | 			     AR9170_MAC_REG_FTF_CFE_ACK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (*new_flags & FIF_CONTROL) | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 			filter |= ar->cur_filter; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 			filter &= (~ar->cur_filter); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 		ar9170_update_frame_filter(ar, filter); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed_flags & FIF_PROMISC_IN_BSS) { | 
					
						
							|  |  |  | 		ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0; | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 		ar9170_set_operating_mode(ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-19 12:43:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				       struct ieee80211_vif *vif, | 
					
						
							|  |  |  | 				       struct ieee80211_bss_conf *bss_conf, | 
					
						
							|  |  |  | 				       u32 changed) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							| 
									
										
										
										
											2009-09-10 10:10:54 -07:00
										 |  |  | 	struct ath_common *common = &ar->common; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-23 16:13:26 +02:00
										 |  |  | 	if (changed & BSS_CHANGED_BSSID) { | 
					
						
							| 
									
										
										
										
											2009-09-10 10:10:54 -07:00
										 |  |  | 		memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); | 
					
						
							| 
									
										
										
										
											2009-04-23 16:13:26 +02:00
										 |  |  | 		err = ar9170_set_operating_mode(ar); | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							| 
									
										
										
										
											2009-04-23 16:13:26 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-21 23:25:07 +02:00
										 |  |  | 	if (changed & BSS_CHANGED_BEACON_ENABLED) | 
					
						
							|  |  |  | 		ar->enable_beacon = bss_conf->enable_beacon; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & BSS_CHANGED_BEACON) { | 
					
						
							| 
									
										
										
										
											2009-04-23 16:13:26 +02:00
										 |  |  | 		err = ar9170_update_beacon(ar); | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							| 
									
										
										
										
											2009-08-21 23:25:07 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-23 16:13:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-21 23:25:07 +02:00
										 |  |  | 	if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON | | 
					
						
							|  |  |  | 		       BSS_CHANGED_BEACON_INT)) { | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 		err = ar9170_set_beacon_timers(ar); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & BSS_CHANGED_ASSOC) { | 
					
						
							|  |  |  | #ifndef CONFIG_AR9170_LEDS
 | 
					
						
							|  |  |  | 		/* enable assoc LED. */ | 
					
						
							|  |  |  | 		err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0); | 
					
						
							|  |  |  | #endif /* CONFIG_AR9170_LEDS */
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & BSS_CHANGED_HT) { | 
					
						
							|  |  |  | 		/* TODO */ | 
					
						
							|  |  |  | 		err = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & BSS_CHANGED_ERP_SLOT) { | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 		err = ar9170_set_slot_time(ar); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (changed & BSS_CHANGED_BASIC_RATES) { | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | 		err = ar9170_set_basic_rates(ar); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-01 21:42:01 +02:00
										 |  |  | out: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u64 ar9170_op_get_tsf(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	u64 tsf; | 
					
						
							| 
									
										
										
										
											2009-09-15 23:27:53 +02:00
										 |  |  | #define NR 3
 | 
					
						
							|  |  |  | 	static const u32 addr[NR] = { AR9170_MAC_REG_TSF_H, | 
					
						
							|  |  |  | 				    AR9170_MAC_REG_TSF_L, | 
					
						
							|  |  |  | 				    AR9170_MAC_REG_TSF_H }; | 
					
						
							|  |  |  | 	u32 val[NR]; | 
					
						
							|  |  |  | 	int loops = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							| 
									
										
										
										
											2009-09-15 23:27:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (loops++ < 10) { | 
					
						
							|  |  |  | 		err = ar9170_read_mreg(ar, NR, addr, val); | 
					
						
							|  |  |  | 		if (err || val[0] == val[2]) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (WARN_ON(err)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-09-15 23:27:53 +02:00
										 |  |  | 	tsf = val[0]; | 
					
						
							|  |  |  | 	tsf = (tsf << 32) | val[1]; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	return tsf; | 
					
						
							| 
									
										
										
										
											2009-09-15 23:27:53 +02:00
										 |  |  | #undef NR
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | 
					
						
							|  |  |  | 			  struct ieee80211_vif *vif, struct ieee80211_sta *sta, | 
					
						
							|  |  |  | 			  struct ieee80211_key_conf *key) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	int err = 0, i; | 
					
						
							|  |  |  | 	u8 ktype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((!ar->vif) || (ar->disable_offload)) | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 	switch (key->cipher) { | 
					
						
							|  |  |  | 	case WLAN_CIPHER_SUITE_WEP40: | 
					
						
							|  |  |  | 		ktype = AR9170_ENC_ALG_WEP64; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case WLAN_CIPHER_SUITE_WEP104: | 
					
						
							|  |  |  | 		ktype = AR9170_ENC_ALG_WEP128; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 	case WLAN_CIPHER_SUITE_TKIP: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		ktype = AR9170_ENC_ALG_TKIP; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 	case WLAN_CIPHER_SUITE_CCMP: | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		ktype = AR9170_ENC_ALG_AESCCMP; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 	if (cmd == SET_KEY) { | 
					
						
							|  |  |  | 		if (unlikely(!IS_STARTED(ar))) { | 
					
						
							|  |  |  | 			err = -EOPNOTSUPP; | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* group keys need all-zeroes address */ | 
					
						
							|  |  |  | 		if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | 
					
						
							|  |  |  | 			sta = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { | 
					
						
							|  |  |  | 			for (i = 0; i < 64; i++) | 
					
						
							|  |  |  | 				if (!(ar->usedkeys & BIT(i))) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			if (i == 64) { | 
					
						
							|  |  |  | 				ar->rx_software_decryption = true; | 
					
						
							|  |  |  | 				ar9170_set_operating_mode(ar); | 
					
						
							|  |  |  | 				err = -ENOSPC; | 
					
						
							|  |  |  | 				goto out; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			i = 64 + key->keyidx; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		key->hw_key_idx = i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, ktype, 0, | 
					
						
							|  |  |  | 					key->key, min_t(u8, 16, key->keylen)); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 		if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 			err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, | 
					
						
							|  |  |  | 						ktype, 1, key->key + 16, 16); | 
					
						
							|  |  |  | 			if (err) | 
					
						
							|  |  |  | 				goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * hardware is not capable generating the MMIC | 
					
						
							|  |  |  | 			 * for fragmented frames! | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (i < 64) | 
					
						
							|  |  |  | 			ar->usedkeys |= BIT(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (unlikely(!IS_STARTED(ar))) { | 
					
						
							|  |  |  | 			/* The device is gone... together with the key ;-) */ | 
					
						
							|  |  |  | 			err = 0; | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ar9170_disable_key(ar, key->hw_key_idx); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (key->hw_key_idx < 64) { | 
					
						
							|  |  |  | 			ar->usedkeys &= ~BIT(key->hw_key_idx); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			err = ar9170_upload_key(ar, key->hw_key_idx, NULL, | 
					
						
							|  |  |  | 						AR9170_ENC_ALG_NONE, 0, | 
					
						
							|  |  |  | 						NULL, 0); | 
					
						
							|  |  |  | 			if (err) | 
					
						
							|  |  |  | 				goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-10 09:46:38 +02:00
										 |  |  | 			if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 				err = ar9170_upload_key(ar, key->hw_key_idx, | 
					
						
							|  |  |  | 							NULL, | 
					
						
							|  |  |  | 							AR9170_ENC_ALG_NONE, 1, | 
					
						
							|  |  |  | 							NULL, 0); | 
					
						
							|  |  |  | 				if (err) | 
					
						
							|  |  |  | 					goto out; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ar9170_regwrite_begin(ar); | 
					
						
							|  |  |  | 	ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L, ar->usedkeys); | 
					
						
							|  |  |  | 	ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H, ar->usedkeys >> 32); | 
					
						
							|  |  |  | 	ar9170_regwrite_finish(); | 
					
						
							|  |  |  | 	err = ar9170_regwrite_result(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_get_stats(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 			    struct ieee80211_low_level_stats *stats) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							|  |  |  | 	err = ar9170_read_reg(ar, AR9170_MAC_REG_TX_RETRY, &val); | 
					
						
							|  |  |  | 	ar->stats.dot11ACKFailureCount += val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(stats, &ar->stats, sizeof(*stats)); | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-28 14:47:49 -04:00
										 |  |  | static int ar9170_get_survey(struct ieee80211_hw *hw, int idx, | 
					
						
							|  |  |  | 				struct survey_info *survey) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	struct ieee80211_conf *conf = &hw->conf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (idx != 0) | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO: update noise value, e.g. call ar9170_set_channel */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	survey->channel = conf->channel; | 
					
						
							|  |  |  | 	survey->filled = SURVEY_INFO_NOISE_DBM; | 
					
						
							|  |  |  | 	survey->noise = ar->noise[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue, | 
					
						
							|  |  |  | 			  const struct ieee80211_tx_queue_params *param) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(&ar->mutex); | 
					
						
							| 
									
										
										
										
											2009-08-09 14:24:09 +02:00
										 |  |  | 	if (queue < __AR9170_NUM_TXQ) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		memcpy(&ar->edcf[ar9170_qos_hwmap[queue]], | 
					
						
							|  |  |  | 		       param, sizeof(*param)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ret = ar9170_set_qos(ar); | 
					
						
							| 
									
										
										
										
											2009-08-09 14:24:09 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 		ret = -EINVAL; | 
					
						
							| 
									
										
										
										
											2009-08-09 14:24:09 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutex_unlock(&ar->mutex); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | static int ar9170_ampdu_action(struct ieee80211_hw *hw, | 
					
						
							| 
									
										
										
										
											2009-11-16 12:00:38 +01:00
										 |  |  | 			       struct ieee80211_vif *vif, | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 			       enum ieee80211_ampdu_mlme_action action, | 
					
						
							|  |  |  | 			       struct ieee80211_sta *sta, u16 tid, u16 *ssn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (action) { | 
					
						
							|  |  |  | 	case IEEE80211_AMPDU_RX_START: | 
					
						
							|  |  |  | 	case IEEE80211_AMPDU_RX_STOP: | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 		/* Handled by firmware */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		return -EOPNOTSUPP; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | static const struct ieee80211_ops ar9170_ops = { | 
					
						
							|  |  |  | 	.start			= ar9170_op_start, | 
					
						
							|  |  |  | 	.stop			= ar9170_op_stop, | 
					
						
							|  |  |  | 	.tx			= ar9170_op_tx, | 
					
						
							|  |  |  | 	.add_interface		= ar9170_op_add_interface, | 
					
						
							|  |  |  | 	.remove_interface	= ar9170_op_remove_interface, | 
					
						
							|  |  |  | 	.config			= ar9170_op_config, | 
					
						
							| 
									
										
										
										
											2009-08-17 16:16:53 +02:00
										 |  |  | 	.prepare_multicast	= ar9170_op_prepare_multicast, | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	.configure_filter	= ar9170_op_configure_filter, | 
					
						
							|  |  |  | 	.conf_tx		= ar9170_conf_tx, | 
					
						
							|  |  |  | 	.bss_info_changed	= ar9170_op_bss_info_changed, | 
					
						
							|  |  |  | 	.get_tsf		= ar9170_op_get_tsf, | 
					
						
							|  |  |  | 	.set_key		= ar9170_set_key, | 
					
						
							|  |  |  | 	.get_stats		= ar9170_get_stats, | 
					
						
							| 
									
										
										
										
											2010-07-28 14:47:49 -04:00
										 |  |  | 	.get_survey		= ar9170_get_survey, | 
					
						
							| 
									
										
										
										
											2009-04-20 18:27:04 +02:00
										 |  |  | 	.ampdu_action		= ar9170_ampdu_action, | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *ar9170_alloc(size_t priv_size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw; | 
					
						
							|  |  |  | 	struct ar9170 *ar; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	struct sk_buff *skb; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * this buffer is used for rx stream reconstruction. | 
					
						
							|  |  |  | 	 * Under heavy load this device (or the transport layer?) | 
					
						
							| 
									
										
										
											
												tree-wide: Assorted spelling fixes
In particular, several occurances of funny versions of 'success',
'unknown', 'therefore', 'acknowledge', 'argument', 'achieve', 'address',
'beginning', 'desirable', 'separate' and 'necessary' are fixed.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Joe Perches <joe@perches.com>
Cc: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
											
										 
											2010-02-03 08:01:28 +08:00
										 |  |  | 	 * tends to split the streams into separate rx descriptors. | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-23 21:51:14 +01:00
										 |  |  | 	skb = __dev_alloc_skb(AR9170_RX_STREAM_MAX_SIZE, GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	if (!skb) | 
					
						
							|  |  |  | 		goto err_nomem; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	hw = ieee80211_alloc_hw(priv_size, &ar9170_ops); | 
					
						
							|  |  |  | 	if (!hw) | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 		goto err_nomem; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ar = hw->priv; | 
					
						
							|  |  |  | 	ar->hw = hw; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	ar->rx_failover = skb; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutex_init(&ar->mutex); | 
					
						
							|  |  |  | 	spin_lock_init(&ar->cmdlock); | 
					
						
							|  |  |  | 	spin_lock_init(&ar->tx_stats_lock); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	for (i = 0; i < __AR9170_NUM_TXQ; i++) { | 
					
						
							|  |  |  | 		skb_queue_head_init(&ar->tx_status[i]); | 
					
						
							|  |  |  | 		skb_queue_head_init(&ar->tx_pending[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 	ar9170_rx_reset_rx_mpdu(ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	INIT_WORK(&ar->beacon_work, ar9170_new_beacon); | 
					
						
							| 
									
										
										
										
											2009-06-06 05:07:23 +02:00
										 |  |  | 	INIT_DELAYED_WORK(&ar->tx_janitor, ar9170_tx_janitor); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* all hw supports 2.4 GHz, so set channel to 1 by default */ | 
					
						
							|  |  |  | 	ar->channel = &ar9170_2ghz_chantable[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* first part of wiphy init */ | 
					
						
							|  |  |  | 	ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | 
					
						
							|  |  |  | 					 BIT(NL80211_IFTYPE_WDS) | | 
					
						
							|  |  |  | 					 BIT(NL80211_IFTYPE_ADHOC); | 
					
						
							|  |  |  | 	ar->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS | | 
					
						
							|  |  |  | 			 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | | 
					
						
							| 
									
										
										
										
											2010-04-30 15:37:00 -04:00
										 |  |  | 			 IEEE80211_HW_SIGNAL_DBM; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 12:15:43 +01:00
										 |  |  | 	ar->hw->queues = __AR9170_NUM_TXQ; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	ar->hw->extra_tx_headroom = 8; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ar->hw->max_rates = 1; | 
					
						
							|  |  |  | 	ar->hw->max_rate_tries = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < ARRAY_SIZE(ar->noise); i++) | 
					
						
							|  |  |  | 		ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ar; | 
					
						
							| 
									
										
										
										
											2009-04-19 01:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | err_nomem: | 
					
						
							|  |  |  | 	kfree_skb(skb); | 
					
						
							|  |  |  | 	return ERR_PTR(-ENOMEM); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ar9170_read_eeprom(struct ar9170 *ar) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #define RW	8	/* number of words to read at once */
 | 
					
						
							|  |  |  | #define RB	(sizeof(u32) * RW)
 | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	struct ath_regulatory *regulatory = &ar->common.regulatory; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	u8 *eeprom = (void *)&ar->eeprom; | 
					
						
							|  |  |  | 	u8 *addr = ar->eeprom.mac_address; | 
					
						
							|  |  |  | 	__le32 offsets[RW]; | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 	unsigned int rx_streams, tx_streams, tx_params = 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	int i, j, err, bands = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BUILD_BUG_ON(sizeof(ar->eeprom) & 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BUILD_BUG_ON(RB > AR9170_MAX_CMD_LEN - 4); | 
					
						
							|  |  |  | #ifndef __CHECKER__
 | 
					
						
							|  |  |  | 	/* don't want to handle trailing remains */ | 
					
						
							|  |  |  | 	BUILD_BUG_ON(sizeof(ar->eeprom) % RB); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < sizeof(ar->eeprom)/RB; i++) { | 
					
						
							|  |  |  | 		for (j = 0; j < RW; j++) | 
					
						
							|  |  |  | 			offsets[j] = cpu_to_le32(AR9170_EEPROM_START + | 
					
						
							|  |  |  | 						 RB * i + 4 * j); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		err = ar->exec_cmd(ar, AR9170_CMD_RREG, | 
					
						
							|  |  |  | 				   RB, (u8 *) &offsets, | 
					
						
							|  |  |  | 				   RB, eeprom + RB * i); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef RW
 | 
					
						
							|  |  |  | #undef RB
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ar->eeprom.length == cpu_to_le16(0xFFFF)) | 
					
						
							|  |  |  | 		return -ENODATA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ar->eeprom.operating_flags & AR9170_OPFLAG_2GHZ) { | 
					
						
							|  |  |  | 		ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar9170_band_2GHz; | 
					
						
							|  |  |  | 		bands++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ar->eeprom.operating_flags & AR9170_OPFLAG_5GHZ) { | 
					
						
							|  |  |  | 		ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar9170_band_5GHz; | 
					
						
							|  |  |  | 		bands++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-11 17:24:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rx_streams = hweight8(ar->eeprom.rx_mask); | 
					
						
							|  |  |  | 	tx_streams = hweight8(ar->eeprom.tx_mask); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rx_streams != tx_streams) | 
					
						
							|  |  |  | 		tx_params = IEEE80211_HT_MCS_TX_RX_DIFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (tx_streams >= 1 && tx_streams <= IEEE80211_HT_MCS_TX_MAX_STREAMS) | 
					
						
							|  |  |  | 		tx_params = (tx_streams - 1) << | 
					
						
							|  |  |  | 			    IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ar9170_band_2GHz.ht_cap.mcs.tx_params |= tx_params; | 
					
						
							|  |  |  | 	ar9170_band_5GHz.ht_cap.mcs.tx_params |= tx_params; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * I measured this, a bandswitch takes roughly | 
					
						
							|  |  |  | 	 * 135 ms and a frequency switch about 80. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * FIXME: measure these values again once EEPROM settings | 
					
						
							|  |  |  | 	 *	  are used, that will influence them! | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (bands == 2) | 
					
						
							|  |  |  | 		ar->hw->channel_change_time = 135 * 1000; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ar->hw->channel_change_time = 80 * 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	regulatory->current_rd = le16_to_cpu(ar->eeprom.reg_domain[0]); | 
					
						
							|  |  |  | 	regulatory->current_rd_ext = le16_to_cpu(ar->eeprom.reg_domain[1]); | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	/* second part of wiphy init */ | 
					
						
							|  |  |  | 	SET_IEEE80211_PERM_ADDR(ar->hw, addr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return bands ? 0 : -EINVAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | static int ar9170_reg_notifier(struct wiphy *wiphy, | 
					
						
							|  |  |  | 			struct regulatory_request *request) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | 
					
						
							|  |  |  | 	struct ar9170 *ar = hw->priv; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	return ath_reg_notifier_apply(wiphy, request, &ar->common.regulatory); | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | int ar9170_register(struct ar9170 *ar, struct device *pdev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	struct ath_regulatory *regulatory = &ar->common.regulatory; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* try to read EEPROM, init MAC addr */ | 
					
						
							|  |  |  | 	err = ar9170_read_eeprom(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	err = ath_regd_init(regulatory, ar->hw->wiphy, | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | 			    ar9170_reg_notifier); | 
					
						
							| 
									
										
										
										
											2009-04-13 21:41:46 -04:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_out; | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	err = ieee80211_register_hw(ar->hw); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 18:07:23 -07:00
										 |  |  | 	if (!ath_is_world_regd(regulatory)) | 
					
						
							|  |  |  | 		regulatory_hint(ar->hw->wiphy, regulatory->alpha2); | 
					
						
							| 
									
										
										
										
											2009-03-30 22:30:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	err = ar9170_init_leds(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_unreg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_AR9170_LEDS
 | 
					
						
							|  |  |  | 	err = ar9170_register_leds(ar); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto err_unreg; | 
					
						
							|  |  |  | #endif /* CONFIG_AR9170_LEDS */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev_info(pdev, "Atheros AR9170 is registered as '%s'\n", | 
					
						
							|  |  |  | 		 wiphy_name(ar->hw->wiphy)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:30 +01:00
										 |  |  | 	ar->registered = true; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | err_unreg: | 
					
						
							|  |  |  | 	ieee80211_unregister_hw(ar->hw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_out: | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ar9170_unregister(struct ar9170 *ar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:30 +01:00
										 |  |  | 	if (ar->registered) { | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #ifdef CONFIG_AR9170_LEDS
 | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:30 +01:00
										 |  |  | 		ar9170_unregister_leds(ar); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | #endif /* CONFIG_AR9170_LEDS */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ieee80211_unregister_hw(ar->hw); | 
					
						
							| 
									
										
										
										
											2009-12-23 13:15:30 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	kfree_skb(ar->rx_failover); | 
					
						
							| 
									
										
										
										
											2009-03-21 23:05:13 +01:00
										 |  |  | 	mutex_destroy(&ar->mutex); | 
					
						
							|  |  |  | } |