blob: bb97981fb2481d1b46763d15cb49aae1c382fc68 [file] [log] [blame]
Christian Lampartere9348cd2009-03-21 23:05:13 +01001/*
2 * Atheros AR9170 driver
3 *
4 * Driver specific definitions
5 *
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, see
20 * http://www.gnu.org/licenses/.
21 *
22 * This file incorporates work covered by the following copyright and
23 * permission notice:
24 * Copyright (c) 2007-2008 Atheros Communications, Inc.
25 *
26 * Permission to use, copy, modify, and/or distribute this software for any
27 * purpose with or without fee is hereby granted, provided that the above
28 * copyright notice and this permission notice appear in all copies.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 */
38#ifndef __AR9170_H
39#define __AR9170_H
40
41#include <linux/completion.h>
42#include <linux/spinlock.h>
Johannes Bergd3236552009-04-20 14:31:42 +020043#include <net/cfg80211.h>
Christian Lampartere9348cd2009-03-21 23:05:13 +010044#include <net/mac80211.h>
45#ifdef CONFIG_AR9170_LEDS
46#include <linux/leds.h>
47#endif /* CONFIG_AR9170_LEDS */
48#include "eeprom.h"
49#include "hw.h"
50
Luis R. Rodriguez203c4802009-03-30 22:30:33 -040051#include "../regd.h"
Christian Lamparter1878f772009-03-30 22:30:32 -040052
Christian Lampartere9348cd2009-03-21 23:05:13 +010053#define PAYLOAD_MAX (AR9170_MAX_CMD_LEN/4 - 1)
54
55enum ar9170_bw {
56 AR9170_BW_20,
57 AR9170_BW_40_BELOW,
58 AR9170_BW_40_ABOVE,
59
60 __AR9170_NUM_BW,
61};
62
Johannes Berg9e52b062009-04-20 18:27:04 +020063static inline enum ar9170_bw nl80211_to_ar9170(enum nl80211_channel_type type)
64{
65 switch (type) {
66 case NL80211_CHAN_NO_HT:
67 case NL80211_CHAN_HT20:
68 return AR9170_BW_20;
69 case NL80211_CHAN_HT40MINUS:
70 return AR9170_BW_40_BELOW;
71 case NL80211_CHAN_HT40PLUS:
72 return AR9170_BW_40_ABOVE;
73 default:
74 BUG();
75 }
76}
77
Christian Lampartere9348cd2009-03-21 23:05:13 +010078enum ar9170_rf_init_mode {
79 AR9170_RFI_NONE,
80 AR9170_RFI_WARM,
81 AR9170_RFI_COLD,
82};
83
84#define AR9170_MAX_RX_BUFFER_SIZE 8192
85
86#ifdef CONFIG_AR9170_LEDS
87struct ar9170;
88
89struct ar9170_led {
90 struct ar9170 *ar;
91 struct led_classdev l;
92 char name[32];
93 unsigned int toggled;
Christian Lamparter2431fe92009-05-25 21:51:19 +020094 bool last_state;
Christian Lampartere9348cd2009-03-21 23:05:13 +010095 bool registered;
96};
97
98#endif /* CONFIG_AR9170_LEDS */
99
100enum ar9170_device_state {
101 AR9170_UNKNOWN_STATE,
102 AR9170_STOPPED,
103 AR9170_IDLE,
104 AR9170_STARTED,
Christian Lampartere9348cd2009-03-21 23:05:13 +0100105};
106
Christian Lampartercca847992009-04-19 01:28:12 +0200107struct ar9170_rxstream_mpdu_merge {
108 struct ar9170_rx_head plcp;
109 bool has_plcp;
110};
111
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200112#define AR9170_QUEUE_TIMEOUT 64
113#define AR9170_TX_TIMEOUT 8
114#define AR9170_JANITOR_DELAY 128
115#define AR9170_TX_INVALID_RATE 0xffffffff
116
Christian Lampartere9348cd2009-03-21 23:05:13 +0100117struct ar9170 {
118 struct ieee80211_hw *hw;
119 struct mutex mutex;
120 enum ar9170_device_state state;
Christian Lampartercca847992009-04-19 01:28:12 +0200121 unsigned long bad_hw_nagger;
Christian Lampartere9348cd2009-03-21 23:05:13 +0100122
123 int (*open)(struct ar9170 *);
124 void (*stop)(struct ar9170 *);
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200125 int (*tx)(struct ar9170 *, struct sk_buff *);
Christian Lampartere9348cd2009-03-21 23:05:13 +0100126 int (*exec_cmd)(struct ar9170 *, enum ar9170_cmd, u32 ,
127 void *, u32 , void *);
128 void (*callback_cmd)(struct ar9170 *, u32 , void *);
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200129 int (*flush)(struct ar9170 *);
Christian Lampartere9348cd2009-03-21 23:05:13 +0100130
131 /* interface mode settings */
132 struct ieee80211_vif *vif;
133 u8 mac_addr[ETH_ALEN];
134 u8 bssid[ETH_ALEN];
135
136 /* beaconing */
137 struct sk_buff *beacon;
138 struct work_struct beacon_work;
139
140 /* cryptographic engine */
141 u64 usedkeys;
142 bool rx_software_decryption;
143 bool disable_offload;
144
145 /* filter settings */
146 struct work_struct filter_config_work;
147 u64 cur_mc_hash, want_mc_hash;
148 u32 cur_filter, want_filter;
Christian Lamparter864cc022009-05-23 20:28:21 +0200149 unsigned long filter_changed;
Christian Lampartercca847992009-04-19 01:28:12 +0200150 unsigned int filter_state;
Christian Lampartere9348cd2009-03-21 23:05:13 +0100151 bool sniffer_enabled;
152
153 /* PHY */
154 struct ieee80211_channel *channel;
155 int noise[4];
156
157 /* power calibration data */
158 u8 power_5G_leg[4];
159 u8 power_2G_cck[4];
160 u8 power_2G_ofdm[4];
161 u8 power_5G_ht20[8];
162 u8 power_5G_ht40[8];
163 u8 power_2G_ht20[8];
164 u8 power_2G_ht40[8];
165
166#ifdef CONFIG_AR9170_LEDS
167 struct delayed_work led_work;
168 struct ar9170_led leds[AR9170_NUM_LEDS];
169#endif /* CONFIG_AR9170_LEDS */
170
171 /* qos queue settings */
172 spinlock_t tx_stats_lock;
173 struct ieee80211_tx_queue_stats tx_stats[5];
174 struct ieee80211_tx_queue_params edcf[5];
175
176 spinlock_t cmdlock;
177 __le32 cmdbuf[PAYLOAD_MAX + 1];
178
179 /* MAC statistics */
180 struct ieee80211_low_level_stats stats;
181
182 /* EEPROM */
183 struct ar9170_eeprom eeprom;
Christian Lamparter1878f772009-03-30 22:30:32 -0400184 struct ath_regulatory regulatory;
Christian Lampartere9348cd2009-03-21 23:05:13 +0100185
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200186 /* tx queues - as seen by hw - */
187 struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
188 struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
189 struct delayed_work tx_janitor;
Christian Lampartercca847992009-04-19 01:28:12 +0200190
191 /* rxstream mpdu merge */
192 struct ar9170_rxstream_mpdu_merge rx_mpdu;
193 struct sk_buff *rx_failover;
194 int rx_failover_missing;
Christian Lampartere9348cd2009-03-21 23:05:13 +0100195};
196
197struct ar9170_sta_info {
Christian Lampartere9348cd2009-03-21 23:05:13 +0100198};
199
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200200#define AR9170_TX_FLAG_WAIT_FOR_ACK BIT(0)
201#define AR9170_TX_FLAG_NO_ACK BIT(1)
202#define AR9170_TX_FLAG_BLOCK_ACK BIT(2)
203
204struct ar9170_tx_info {
205 unsigned long timeout;
206 unsigned int flags;
207};
208
209#define IS_STARTED(a) (((struct ar9170 *)a)->state >= AR9170_STARTED)
210#define IS_ACCEPTING_CMD(a) (((struct ar9170 *)a)->state >= AR9170_IDLE)
Christian Lampartere9348cd2009-03-21 23:05:13 +0100211
Christian Lamparter864cc022009-05-23 20:28:21 +0200212#define AR9170_FILTER_CHANGED_MODE BIT(0)
Christian Lampartere9348cd2009-03-21 23:05:13 +0100213#define AR9170_FILTER_CHANGED_MULTICAST BIT(1)
214#define AR9170_FILTER_CHANGED_FRAMEFILTER BIT(2)
215
216/* exported interface */
217void *ar9170_alloc(size_t priv_size);
218int ar9170_register(struct ar9170 *ar, struct device *pdev);
219void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb);
220void ar9170_unregister(struct ar9170 *ar);
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200221void ar9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
Christian Lamparter66d00812009-05-28 17:04:27 +0200222void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
Christian Lamparter9b9c5aa2009-06-06 05:07:23 +0200223int ar9170_nag_limiter(struct ar9170 *ar);
Christian Lampartere9348cd2009-03-21 23:05:13 +0100224
225/* MAC */
226int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
227int ar9170_init_mac(struct ar9170 *ar);
228int ar9170_set_qos(struct ar9170 *ar);
229int ar9170_update_multicast(struct ar9170 *ar);
230int ar9170_update_frame_filter(struct ar9170 *ar);
231int ar9170_set_operating_mode(struct ar9170 *ar);
232int ar9170_set_beacon_timers(struct ar9170 *ar);
Christian Lamparter29ceff52009-06-01 21:42:01 +0200233int ar9170_set_dyn_sifs_ack(struct ar9170 *ar);
234int ar9170_set_slot_time(struct ar9170 *ar);
235int ar9170_set_basic_rates(struct ar9170 *ar);
Christian Lampartere9348cd2009-03-21 23:05:13 +0100236int ar9170_set_hwretry_limit(struct ar9170 *ar, u32 max_retry);
237int ar9170_update_beacon(struct ar9170 *ar);
238void ar9170_new_beacon(struct work_struct *work);
239int ar9170_upload_key(struct ar9170 *ar, u8 id, const u8 *mac, u8 ktype,
240 u8 keyidx, u8 *keydata, int keylen);
241int ar9170_disable_key(struct ar9170 *ar, u8 id);
242
243/* LEDs */
244#ifdef CONFIG_AR9170_LEDS
245int ar9170_register_leds(struct ar9170 *ar);
246void ar9170_unregister_leds(struct ar9170 *ar);
247#endif /* CONFIG_AR9170_LEDS */
248int ar9170_init_leds(struct ar9170 *ar);
249int ar9170_set_leds_state(struct ar9170 *ar, u32 led_state);
250
251/* PHY / RF */
252int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band);
253int ar9170_init_rf(struct ar9170 *ar);
254int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
255 enum ar9170_rf_init_mode rfi, enum ar9170_bw bw);
256
257#endif /* __AR9170_H */