• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/net/wireless/ath/ath9k/
1/*
2 * Copyright (c) 2010 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef HTC_H
18#define HTC_H
19
20#include <linux/module.h>
21#include <linux/usb.h>
22#include <linux/firmware.h>
23#include <linux/skbuff.h>
24#include <linux/netdevice.h>
25#include <linux/leds.h>
26#include <linux/slab.h>
27#include <net/mac80211.h>
28
29#include "common.h"
30#include "htc_hst.h"
31#include "hif_usb.h"
32#include "wmi.h"
33
34#define ATH_STA_SHORT_CALINTERVAL 1000    /* 1 second */
35#define ATH_ANI_POLLINTERVAL      100     /* 100 ms */
36#define ATH_LONG_CALINTERVAL      30000   /* 30 seconds */
37#define ATH_RESTART_CALINTERVAL   1200000 /* 20 minutes */
38
39#define ATH_DEFAULT_BMISS_LIMIT 10
40#define IEEE80211_MS_TO_TU(x)   (((x) * 1000) / 1024)
41#define TSF_TO_TU(_h, _l) \
42	((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
43
44extern struct ieee80211_ops ath9k_htc_ops;
45extern int htc_modparam_nohwcrypt;
46
47enum htc_phymode {
48	HTC_MODE_AUTO		= 0,
49	HTC_MODE_11A		= 1,
50	HTC_MODE_11B		= 2,
51	HTC_MODE_11G		= 3,
52	HTC_MODE_FH		= 4,
53	HTC_MODE_TURBO_A	= 5,
54	HTC_MODE_TURBO_G	= 6,
55	HTC_MODE_11NA		= 7,
56	HTC_MODE_11NG		= 8
57};
58
59enum htc_opmode {
60	HTC_M_STA	= 1,
61	HTC_M_IBSS	= 0,
62	HTC_M_AHDEMO	= 3,
63	HTC_M_HOSTAP	= 6,
64	HTC_M_MONITOR	= 8,
65	HTC_M_WDS	= 2
66};
67
68#define ATH9K_HTC_HDRSPACE sizeof(struct htc_frame_hdr)
69#define ATH9K_HTC_AMPDU	1
70#define ATH9K_HTC_NORMAL 2
71
72#define ATH9K_HTC_TX_CTSONLY      0x1
73#define ATH9K_HTC_TX_RTSCTS       0x2
74#define ATH9K_HTC_TX_USE_MIN_RATE 0x100
75
76struct tx_frame_hdr {
77	u8 data_type;
78	u8 node_idx;
79	u8 vif_idx;
80	u8 tidno;
81	u32 flags; /* ATH9K_HTC_TX_* */
82	u8 key_type;
83	u8 keyix;
84	u8 reserved[26];
85} __packed;
86
87struct tx_mgmt_hdr {
88	u8 node_idx;
89	u8 vif_idx;
90	u8 tidno;
91	u8 flags;
92	u8 key_type;
93	u8 keyix;
94	u16 reserved;
95} __packed;
96
97struct tx_beacon_header {
98	u8 len_changed;
99	u8 vif_index;
100	u16 rev;
101} __packed;
102
103struct ath9k_htc_target_hw {
104	u32 flags;
105	u32 flags_ext;
106	u32 ampdu_limit;
107	u8 ampdu_subframes;
108	u8 tx_chainmask;
109	u8 tx_chainmask_legacy;
110	u8 rtscts_ratecode;
111	u8 protmode;
112} __packed;
113
114struct ath9k_htc_cap_target {
115	u32 flags;
116	u32 flags_ext;
117	u32 ampdu_limit;
118	u8 ampdu_subframes;
119	u8 tx_chainmask;
120	u8 tx_chainmask_legacy;
121	u8 rtscts_ratecode;
122	u8 protmode;
123} __packed;
124
125struct ath9k_htc_target_vif {
126	u8 index;
127	u8 des_bssid[ETH_ALEN];
128	__be32 opmode;
129	u8 myaddr[ETH_ALEN];
130	u8 bssid[ETH_ALEN];
131	u32 flags;
132	u32 flags_ext;
133	u16 ps_sta;
134	__be16 rtsthreshold;
135	u8 ath_cap;
136	u8 node;
137	s8 mcast_rate;
138} __packed;
139
140#define ATH_HTC_STA_AUTH  0x0001
141#define ATH_HTC_STA_QOS   0x0002
142#define ATH_HTC_STA_ERP   0x0004
143#define ATH_HTC_STA_HT    0x0008
144
145struct ath9k_htc_target_sta {
146	u16 associd;
147	u16 txpower;
148	u32 ucastkey;
149	u8 macaddr[ETH_ALEN];
150	u8 bssid[ETH_ALEN];
151	u8 sta_index;
152	u8 vif_index;
153	u8 vif_sta;
154	__be16 flags; /* ATH_HTC_STA_* */
155	u16 htcap;
156	u8 valid;
157	u16 capinfo;
158	struct ath9k_htc_target_hw *hw;
159	struct ath9k_htc_target_vif *vif;
160	u16 txseqmgmt;
161	u8 is_vif_sta;
162	u16 maxampdu;
163	u16 iv16;
164	u32 iv32;
165} __packed;
166
167struct ath9k_htc_target_aggr {
168	u8 sta_index;
169	u8 tidno;
170	u8 aggr_enable;
171	u8 padding;
172} __packed;
173
174#define ATH_HTC_RATE_MAX 30
175
176#define WLAN_RC_DS_FLAG  0x01
177#define WLAN_RC_40_FLAG  0x02
178#define WLAN_RC_SGI_FLAG 0x04
179#define WLAN_RC_HT_FLAG  0x08
180
181struct ath9k_htc_rateset {
182	u8 rs_nrates;
183	u8 rs_rates[ATH_HTC_RATE_MAX];
184};
185
186struct ath9k_htc_rate {
187	struct ath9k_htc_rateset legacy_rates;
188	struct ath9k_htc_rateset ht_rates;
189} __packed;
190
191struct ath9k_htc_target_rate {
192	u8 sta_index;
193	u8 isnew;
194	__be32 capflags;
195	struct ath9k_htc_rate rates;
196};
197
198struct ath9k_htc_target_stats {
199	__be32 tx_shortretry;
200	__be32 tx_longretry;
201	__be32 tx_xretries;
202	__be32 ht_txunaggr_xretry;
203	__be32 ht_tx_xretries;
204} __packed;
205
206struct ath9k_htc_vif {
207	u8 index;
208};
209
210#define ATH9K_HTC_MAX_STA 8
211#define ATH9K_HTC_MAX_TID 8
212
213enum tid_aggr_state {
214	AGGR_STOP = 0,
215	AGGR_PROGRESS,
216	AGGR_START,
217	AGGR_OPERATIONAL
218};
219
220struct ath9k_htc_sta {
221	u8 index;
222	enum tid_aggr_state tid_state[ATH9K_HTC_MAX_TID];
223};
224
225#define ATH9K_HTC_RXBUF 256
226#define HTC_RX_FRAME_HEADER_SIZE 40
227
228struct ath9k_htc_rxbuf {
229	bool in_process;
230	struct sk_buff *skb;
231	struct ath_htc_rx_status rxstatus;
232	struct list_head list;
233};
234
235struct ath9k_htc_rx {
236	int last_rssi;
237	struct list_head rxbuf;
238	spinlock_t rxbuflock;
239};
240
241struct ath9k_htc_tx_ctl {
242	u8 type; /* ATH9K_HTC_* */
243};
244
245#ifdef CONFIG_ATH9K_HTC_DEBUGFS
246
247#define TX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.tx_stats.c++)
248#define RX_STAT_INC(c) (hif_dev->htc_handle->drv_priv->debug.rx_stats.c++)
249
250#define TX_QSTAT_INC(q) (priv->debug.tx_stats.queue_stats[q]++)
251
252struct ath_tx_stats {
253	u32 buf_queued;
254	u32 buf_completed;
255	u32 skb_queued;
256	u32 skb_completed;
257	u32 skb_dropped;
258	u32 queue_stats[WME_NUM_AC];
259};
260
261struct ath_rx_stats {
262	u32 skb_allocated;
263	u32 skb_completed;
264	u32 skb_dropped;
265};
266
267struct ath9k_debug {
268	struct dentry *debugfs_phy;
269	struct dentry *debugfs_tgt_stats;
270	struct dentry *debugfs_xmit;
271	struct dentry *debugfs_recv;
272	struct ath_tx_stats tx_stats;
273	struct ath_rx_stats rx_stats;
274	u32 txrate;
275};
276
277#else
278
279#define TX_STAT_INC(c) do { } while (0)
280#define RX_STAT_INC(c) do { } while (0)
281
282#define TX_QSTAT_INC(c) do { } while (0)
283
284#endif /* CONFIG_ATH9K_HTC_DEBUGFS */
285
286#define ATH_LED_PIN_DEF             1
287#define ATH_LED_PIN_9287            8
288#define ATH_LED_PIN_9271            15
289#define ATH_LED_PIN_7010            12
290#define ATH_LED_ON_DURATION_IDLE    350	/* in msecs */
291#define ATH_LED_OFF_DURATION_IDLE   250	/* in msecs */
292
293enum ath_led_type {
294	ATH_LED_RADIO,
295	ATH_LED_ASSOC,
296	ATH_LED_TX,
297	ATH_LED_RX
298};
299
300struct ath_led {
301	struct ath9k_htc_priv *priv;
302	struct led_classdev led_cdev;
303	enum ath_led_type led_type;
304	struct delayed_work brightness_work;
305	char name[32];
306	bool registered;
307	int brightness;
308};
309
310struct htc_beacon_config {
311	u16 beacon_interval;
312	u16 listen_interval;
313	u16 dtim_period;
314	u16 bmiss_timeout;
315	u8 dtim_count;
316};
317
318#define OP_INVALID        BIT(0)
319#define OP_SCANNING       BIT(1)
320#define OP_FULL_RESET     BIT(2)
321#define OP_LED_ASSOCIATED BIT(3)
322#define OP_LED_ON         BIT(4)
323#define OP_PREAMBLE_SHORT BIT(5)
324#define OP_PROTECT_ENABLE BIT(6)
325#define OP_ASSOCIATED     BIT(7)
326#define OP_ENABLE_BEACON  BIT(8)
327#define OP_LED_DEINIT     BIT(9)
328#define OP_UNPLUGGED      BIT(10)
329
330struct ath9k_htc_priv {
331	struct device *dev;
332	struct ieee80211_hw *hw;
333	struct ath_hw *ah;
334	struct htc_target *htc;
335	struct wmi *wmi;
336
337	enum htc_endpoint_id wmi_cmd_ep;
338	enum htc_endpoint_id beacon_ep;
339	enum htc_endpoint_id cab_ep;
340	enum htc_endpoint_id uapsd_ep;
341	enum htc_endpoint_id mgmt_ep;
342	enum htc_endpoint_id data_be_ep;
343	enum htc_endpoint_id data_bk_ep;
344	enum htc_endpoint_id data_vi_ep;
345	enum htc_endpoint_id data_vo_ep;
346
347	u16 op_flags;
348	u16 curtxpow;
349	u16 txpowlimit;
350	u16 nvifs;
351	u16 nstations;
352	u16 seq_no;
353	u32 bmiss_cnt;
354
355	struct ath9k_hw_cal_data caldata[38];
356
357	spinlock_t beacon_lock;
358
359	bool tx_queues_stop;
360	spinlock_t tx_lock;
361
362	struct ieee80211_vif *vif;
363	struct htc_beacon_config cur_beacon_conf;
364	unsigned int rxfilter;
365	struct tasklet_struct wmi_tasklet;
366	struct tasklet_struct rx_tasklet;
367	struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
368	struct ath9k_htc_rx rx;
369	struct tasklet_struct tx_tasklet;
370	struct sk_buff_head tx_queue;
371	struct delayed_work ath9k_ani_work;
372	struct work_struct ps_work;
373
374	struct mutex htc_pm_lock;
375	unsigned long ps_usecount;
376	bool ps_enabled;
377	bool ps_idle;
378
379	struct ath_led radio_led;
380	struct ath_led assoc_led;
381	struct ath_led tx_led;
382	struct ath_led rx_led;
383	struct delayed_work ath9k_led_blink_work;
384	int led_on_duration;
385	int led_off_duration;
386	int led_on_cnt;
387	int led_off_cnt;
388
389	int beaconq;
390	int cabq;
391	int hwq_map[WME_NUM_AC];
392
393#ifdef CONFIG_ATH9K_HTC_DEBUGFS
394	struct ath9k_debug debug;
395#endif
396	struct mutex mutex;
397};
398
399static inline void ath_read_cachesize(struct ath_common *common, int *csz)
400{
401	common->bus_ops->read_cachesize(common, csz);
402}
403
404void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv);
405void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv,
406			     struct ieee80211_vif *vif);
407void ath9k_htc_swba(struct ath9k_htc_priv *priv, u8 beacon_pending);
408
409void ath9k_htc_rxep(void *priv, struct sk_buff *skb,
410		    enum htc_endpoint_id ep_id);
411void ath9k_htc_txep(void *priv, struct sk_buff *skb, enum htc_endpoint_id ep_id,
412		    bool txok);
413void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb,
414			enum htc_endpoint_id ep_id, bool txok);
415
416void ath9k_htc_station_work(struct work_struct *work);
417void ath9k_htc_aggr_work(struct work_struct *work);
418void ath9k_ani_work(struct work_struct *work);;
419
420int ath9k_tx_init(struct ath9k_htc_priv *priv);
421void ath9k_tx_tasklet(unsigned long data);
422int ath9k_htc_tx_start(struct ath9k_htc_priv *priv, struct sk_buff *skb);
423void ath9k_tx_cleanup(struct ath9k_htc_priv *priv);
424bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype);
425int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv);
426int get_hw_qnum(u16 queue, int *hwq_map);
427int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
428		       struct ath9k_tx_queue_info *qinfo);
429
430int ath9k_rx_init(struct ath9k_htc_priv *priv);
431void ath9k_rx_cleanup(struct ath9k_htc_priv *priv);
432void ath9k_host_rx_init(struct ath9k_htc_priv *priv);
433void ath9k_rx_tasklet(unsigned long data);
434u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv);
435
436void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv);
437void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv);
438void ath9k_ps_work(struct work_struct *work);
439
440void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv);
441void ath9k_init_leds(struct ath9k_htc_priv *priv);
442void ath9k_deinit_leds(struct ath9k_htc_priv *priv);
443
444int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
445			   u16 devid);
446void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug);
447#ifdef CONFIG_PM
448int ath9k_htc_resume(struct htc_target *htc_handle);
449#endif
450#ifdef CONFIG_ATH9K_HTC_DEBUGFS
451int ath9k_htc_debug_create_root(void);
452void ath9k_htc_debug_remove_root(void);
453int ath9k_htc_init_debug(struct ath_hw *ah);
454void ath9k_htc_exit_debug(struct ath_hw *ah);
455#else
456static inline int ath9k_htc_debug_create_root(void) { return 0; };
457static inline void ath9k_htc_debug_remove_root(void) {};
458static inline int ath9k_htc_init_debug(struct ath_hw *ah) { return 0; };
459static inline void ath9k_htc_exit_debug(struct ath_hw *ah) {};
460#endif /* CONFIG_ATH9K_HTC_DEBUGFS */
461
462#endif /* HTC_H */
463