diff options
Diffstat (limited to 'drivers/net/wireless/ar9170')
-rw-r--r-- | drivers/net/wireless/ar9170/Kconfig | 17 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/Makefile | 3 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/ar9170.h | 209 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/cmd.c | 129 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/cmd.h | 91 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/eeprom.h | 179 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/hw.h | 417 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/led.c | 171 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/mac.c | 452 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/main.c | 1671 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/phy.c | 1240 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/usb.c | 748 | ||||
-rw-r--r-- | drivers/net/wireless/ar9170/usb.h | 74 |
13 files changed, 5401 insertions, 0 deletions
diff --git a/drivers/net/wireless/ar9170/Kconfig b/drivers/net/wireless/ar9170/Kconfig new file mode 100644 index 000000000000..de4281fda129 --- /dev/null +++ b/drivers/net/wireless/ar9170/Kconfig | |||
@@ -0,0 +1,17 @@ | |||
1 | config AR9170_USB | ||
2 | tristate "Atheros AR9170 802.11n USB support" | ||
3 | depends on USB && MAC80211 && WLAN_80211 && EXPERIMENTAL | ||
4 | select FW_LOADER | ||
5 | help | ||
6 | This is a driver for the Atheros "otus" 802.11n USB devices. | ||
7 | |||
8 | These devices require additional firmware (2 files). | ||
9 | For now, these files can be downloaded from here: | ||
10 | http://wireless.kernel.org/en/users/Drivers/ar9170 | ||
11 | |||
12 | If you choose to build a module, it'll be called ar9170usb. | ||
13 | |||
14 | config AR9170_LEDS | ||
15 | bool | ||
16 | depends on AR9170_USB && MAC80211_LEDS && (LEDS_CLASS = y || LEDS_CLASS = AR9170_USB) | ||
17 | default y | ||
diff --git a/drivers/net/wireless/ar9170/Makefile b/drivers/net/wireless/ar9170/Makefile new file mode 100644 index 000000000000..8d91c7ee3215 --- /dev/null +++ b/drivers/net/wireless/ar9170/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | ar9170usb-objs := usb.o main.o cmd.o mac.o phy.o led.o | ||
2 | |||
3 | obj-$(CONFIG_AR9170_USB) += ar9170usb.o | ||
diff --git a/drivers/net/wireless/ar9170/ar9170.h b/drivers/net/wireless/ar9170/ar9170.h new file mode 100644 index 000000000000..f4fb2e94aea0 --- /dev/null +++ b/drivers/net/wireless/ar9170/ar9170.h | |||
@@ -0,0 +1,209 @@ | |||
1 | /* | ||
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> | ||
43 | #include <net/wireless.h> | ||
44 | #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 | |||
51 | #define PAYLOAD_MAX (AR9170_MAX_CMD_LEN/4 - 1) | ||
52 | |||
53 | enum ar9170_bw { | ||
54 | AR9170_BW_20, | ||
55 | AR9170_BW_40_BELOW, | ||
56 | AR9170_BW_40_ABOVE, | ||
57 | |||
58 | __AR9170_NUM_BW, | ||
59 | }; | ||
60 | |||
61 | enum ar9170_rf_init_mode { | ||
62 | AR9170_RFI_NONE, | ||
63 | AR9170_RFI_WARM, | ||
64 | AR9170_RFI_COLD, | ||
65 | }; | ||
66 | |||
67 | #define AR9170_MAX_RX_BUFFER_SIZE 8192 | ||
68 | |||
69 | #ifdef CONFIG_AR9170_LEDS | ||
70 | struct ar9170; | ||
71 | |||
72 | struct ar9170_led { | ||
73 | struct ar9170 *ar; | ||
74 | struct led_classdev l; | ||
75 | char name[32]; | ||
76 | unsigned int toggled; | ||
77 | bool registered; | ||
78 | }; | ||
79 | |||
80 | #endif /* CONFIG_AR9170_LEDS */ | ||
81 | |||
82 | enum ar9170_device_state { | ||
83 | AR9170_UNKNOWN_STATE, | ||
84 | AR9170_STOPPED, | ||
85 | AR9170_IDLE, | ||
86 | AR9170_STARTED, | ||
87 | AR9170_ASSOCIATED, | ||
88 | }; | ||
89 | |||
90 | struct ar9170 { | ||
91 | struct ieee80211_hw *hw; | ||
92 | struct mutex mutex; | ||
93 | enum ar9170_device_state state; | ||
94 | |||
95 | int (*open)(struct ar9170 *); | ||
96 | void (*stop)(struct ar9170 *); | ||
97 | int (*tx)(struct ar9170 *, struct sk_buff *, bool, unsigned int); | ||
98 | int (*exec_cmd)(struct ar9170 *, enum ar9170_cmd, u32 , | ||
99 | void *, u32 , void *); | ||
100 | void (*callback_cmd)(struct ar9170 *, u32 , void *); | ||
101 | |||
102 | /* interface mode settings */ | ||
103 | struct ieee80211_vif *vif; | ||
104 | u8 mac_addr[ETH_ALEN]; | ||
105 | u8 bssid[ETH_ALEN]; | ||
106 | |||
107 | /* beaconing */ | ||
108 | struct sk_buff *beacon; | ||
109 | struct work_struct beacon_work; | ||
110 | |||
111 | /* cryptographic engine */ | ||
112 | u64 usedkeys; | ||
113 | bool rx_software_decryption; | ||
114 | bool disable_offload; | ||
115 | |||
116 | /* filter settings */ | ||
117 | struct work_struct filter_config_work; | ||
118 | u64 cur_mc_hash, want_mc_hash; | ||
119 | u32 cur_filter, want_filter; | ||
120 | unsigned int filter_changed; | ||
121 | bool sniffer_enabled; | ||
122 | |||
123 | /* PHY */ | ||
124 | struct ieee80211_channel *channel; | ||
125 | int noise[4]; | ||
126 | |||
127 | /* power calibration data */ | ||
128 | u8 power_5G_leg[4]; | ||
129 | u8 power_2G_cck[4]; | ||
130 | u8 power_2G_ofdm[4]; | ||
131 | u8 power_5G_ht20[8]; | ||
132 | u8 power_5G_ht40[8]; | ||
133 | u8 power_2G_ht20[8]; | ||
134 | u8 power_2G_ht40[8]; | ||
135 | |||
136 | #ifdef CONFIG_AR9170_LEDS | ||
137 | struct delayed_work led_work; | ||
138 | struct ar9170_led leds[AR9170_NUM_LEDS]; | ||
139 | #endif /* CONFIG_AR9170_LEDS */ | ||
140 | |||
141 | /* qos queue settings */ | ||
142 | spinlock_t tx_stats_lock; | ||
143 | struct ieee80211_tx_queue_stats tx_stats[5]; | ||
144 | struct ieee80211_tx_queue_params edcf[5]; | ||
145 | |||
146 | spinlock_t cmdlock; | ||
147 | __le32 cmdbuf[PAYLOAD_MAX + 1]; | ||
148 | |||
149 | /* MAC statistics */ | ||
150 | struct ieee80211_low_level_stats stats; | ||
151 | |||
152 | /* EEPROM */ | ||
153 | struct ar9170_eeprom eeprom; | ||
154 | |||
155 | /* global tx status for unregistered Stations. */ | ||
156 | struct sk_buff_head global_tx_status; | ||
157 | struct sk_buff_head global_tx_status_waste; | ||
158 | struct delayed_work tx_status_janitor; | ||
159 | }; | ||
160 | |||
161 | struct ar9170_sta_info { | ||
162 | struct sk_buff_head tx_status[__AR9170_NUM_TXQ]; | ||
163 | }; | ||
164 | |||
165 | #define IS_STARTED(a) (a->state >= AR9170_STARTED) | ||
166 | #define IS_ACCEPTING_CMD(a) (a->state >= AR9170_IDLE) | ||
167 | |||
168 | #define AR9170_FILTER_CHANGED_PROMISC BIT(0) | ||
169 | #define AR9170_FILTER_CHANGED_MULTICAST BIT(1) | ||
170 | #define AR9170_FILTER_CHANGED_FRAMEFILTER BIT(2) | ||
171 | |||
172 | /* exported interface */ | ||
173 | void *ar9170_alloc(size_t priv_size); | ||
174 | int ar9170_register(struct ar9170 *ar, struct device *pdev); | ||
175 | void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb); | ||
176 | void ar9170_unregister(struct ar9170 *ar); | ||
177 | void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb, | ||
178 | bool update_statistics, u16 tx_status); | ||
179 | |||
180 | /* MAC */ | ||
181 | int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb); | ||
182 | int ar9170_init_mac(struct ar9170 *ar); | ||
183 | int ar9170_set_qos(struct ar9170 *ar); | ||
184 | int ar9170_update_multicast(struct ar9170 *ar); | ||
185 | int ar9170_update_frame_filter(struct ar9170 *ar); | ||
186 | int ar9170_set_operating_mode(struct ar9170 *ar); | ||
187 | int ar9170_set_beacon_timers(struct ar9170 *ar); | ||
188 | int ar9170_set_hwretry_limit(struct ar9170 *ar, u32 max_retry); | ||
189 | int ar9170_update_beacon(struct ar9170 *ar); | ||
190 | void ar9170_new_beacon(struct work_struct *work); | ||
191 | int ar9170_upload_key(struct ar9170 *ar, u8 id, const u8 *mac, u8 ktype, | ||
192 | u8 keyidx, u8 *keydata, int keylen); | ||
193 | int ar9170_disable_key(struct ar9170 *ar, u8 id); | ||
194 | |||
195 | /* LEDs */ | ||
196 | #ifdef CONFIG_AR9170_LEDS | ||
197 | int ar9170_register_leds(struct ar9170 *ar); | ||
198 | void ar9170_unregister_leds(struct ar9170 *ar); | ||
199 | #endif /* CONFIG_AR9170_LEDS */ | ||
200 | int ar9170_init_leds(struct ar9170 *ar); | ||
201 | int ar9170_set_leds_state(struct ar9170 *ar, u32 led_state); | ||
202 | |||
203 | /* PHY / RF */ | ||
204 | int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band); | ||
205 | int ar9170_init_rf(struct ar9170 *ar); | ||
206 | int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel, | ||
207 | enum ar9170_rf_init_mode rfi, enum ar9170_bw bw); | ||
208 | |||
209 | #endif /* __AR9170_H */ | ||
diff --git a/drivers/net/wireless/ar9170/cmd.c b/drivers/net/wireless/ar9170/cmd.c new file mode 100644 index 000000000000..f57a6200167b --- /dev/null +++ b/drivers/net/wireless/ar9170/cmd.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * Basic HW register/memory/command access functions | ||
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 | |||
39 | #include "ar9170.h" | ||
40 | #include "cmd.h" | ||
41 | |||
42 | int ar9170_write_mem(struct ar9170 *ar, const __le32 *data, size_t len) | ||
43 | { | ||
44 | int err; | ||
45 | |||
46 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
47 | return 0; | ||
48 | |||
49 | err = ar->exec_cmd(ar, AR9170_CMD_WMEM, len, (u8 *) data, 0, NULL); | ||
50 | if (err) | ||
51 | printk(KERN_DEBUG "%s: writing memory failed\n", | ||
52 | wiphy_name(ar->hw->wiphy)); | ||
53 | return err; | ||
54 | } | ||
55 | |||
56 | int ar9170_write_reg(struct ar9170 *ar, const u32 reg, const u32 val) | ||
57 | { | ||
58 | __le32 buf[2] = { | ||
59 | cpu_to_le32(reg), | ||
60 | cpu_to_le32(val), | ||
61 | }; | ||
62 | int err; | ||
63 | |||
64 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
65 | return 0; | ||
66 | |||
67 | err = ar->exec_cmd(ar, AR9170_CMD_WREG, sizeof(buf), | ||
68 | (u8 *) buf, 0, NULL); | ||
69 | if (err) | ||
70 | printk(KERN_DEBUG "%s: writing reg %#x (val %#x) failed\n", | ||
71 | wiphy_name(ar->hw->wiphy), reg, val); | ||
72 | return err; | ||
73 | } | ||
74 | |||
75 | static int ar9170_read_mreg(struct ar9170 *ar, int nregs, | ||
76 | const u32 *regs, u32 *out) | ||
77 | { | ||
78 | int i, err; | ||
79 | __le32 *offs, *res; | ||
80 | |||
81 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
82 | return 0; | ||
83 | |||
84 | /* abuse "out" for the register offsets, must be same length */ | ||
85 | offs = (__le32 *)out; | ||
86 | for (i = 0; i < nregs; i++) | ||
87 | offs[i] = cpu_to_le32(regs[i]); | ||
88 | |||
89 | /* also use the same buffer for the input */ | ||
90 | res = (__le32 *)out; | ||
91 | |||
92 | err = ar->exec_cmd(ar, AR9170_CMD_RREG, | ||
93 | 4 * nregs, (u8 *)offs, | ||
94 | 4 * nregs, (u8 *)res); | ||
95 | if (err) | ||
96 | return err; | ||
97 | |||
98 | /* convert result to cpu endian */ | ||
99 | for (i = 0; i < nregs; i++) | ||
100 | out[i] = le32_to_cpu(res[i]); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | int ar9170_read_reg(struct ar9170 *ar, u32 reg, u32 *val) | ||
106 | { | ||
107 | return ar9170_read_mreg(ar, 1, ®, val); | ||
108 | } | ||
109 | |||
110 | int ar9170_echo_test(struct ar9170 *ar, u32 v) | ||
111 | { | ||
112 | __le32 echobuf = cpu_to_le32(v); | ||
113 | __le32 echores; | ||
114 | int err; | ||
115 | |||
116 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
117 | return -ENODEV; | ||
118 | |||
119 | err = ar->exec_cmd(ar, AR9170_CMD_ECHO, | ||
120 | 4, (u8 *)&echobuf, | ||
121 | 4, (u8 *)&echores); | ||
122 | if (err) | ||
123 | return err; | ||
124 | |||
125 | if (echobuf != echores) | ||
126 | return -EINVAL; | ||
127 | |||
128 | return 0; | ||
129 | } | ||
diff --git a/drivers/net/wireless/ar9170/cmd.h b/drivers/net/wireless/ar9170/cmd.h new file mode 100644 index 000000000000..a4f0e50e52b4 --- /dev/null +++ b/drivers/net/wireless/ar9170/cmd.h | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * Basic HW register/memory/command access functions | ||
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 __CMD_H | ||
39 | #define __CMD_H | ||
40 | |||
41 | #include "ar9170.h" | ||
42 | |||
43 | /* basic HW access */ | ||
44 | int ar9170_write_mem(struct ar9170 *ar, const __le32 *data, size_t len); | ||
45 | int ar9170_write_reg(struct ar9170 *ar, const u32 reg, const u32 val); | ||
46 | int ar9170_read_reg(struct ar9170 *ar, u32 reg, u32 *val); | ||
47 | int ar9170_echo_test(struct ar9170 *ar, u32 v); | ||
48 | |||
49 | /* | ||
50 | * Macros to facilitate writing multiple registers in a single | ||
51 | * write-combining USB command. Note that when the first group | ||
52 | * fails the whole thing will fail without any others attempted, | ||
53 | * but you won't know which write in the group failed. | ||
54 | */ | ||
55 | #define ar9170_regwrite_begin(ar) \ | ||
56 | do { \ | ||
57 | int __nreg = 0, __err = 0; \ | ||
58 | struct ar9170 *__ar = ar; | ||
59 | |||
60 | #define ar9170_regwrite(r, v) do { \ | ||
61 | __ar->cmdbuf[2 * __nreg + 1] = cpu_to_le32(r); \ | ||
62 | __ar->cmdbuf[2 * __nreg + 2] = cpu_to_le32(v); \ | ||
63 | __nreg++; \ | ||
64 | if ((__nreg >= PAYLOAD_MAX/2)) { \ | ||
65 | if (IS_ACCEPTING_CMD(__ar)) \ | ||
66 | __err = ar->exec_cmd(__ar, AR9170_CMD_WREG, \ | ||
67 | 8 * __nreg, \ | ||
68 | (u8 *) &__ar->cmdbuf[1], \ | ||
69 | 0, NULL); \ | ||
70 | __nreg = 0; \ | ||
71 | if (__err) \ | ||
72 | goto __regwrite_out; \ | ||
73 | } \ | ||
74 | } while (0) | ||
75 | |||
76 | #define ar9170_regwrite_finish() \ | ||
77 | __regwrite_out : \ | ||
78 | if (__nreg) { \ | ||
79 | if (IS_ACCEPTING_CMD(__ar)) \ | ||
80 | __err = ar->exec_cmd(__ar, AR9170_CMD_WREG, \ | ||
81 | 8 * __nreg, \ | ||
82 | (u8 *) &__ar->cmdbuf[1], \ | ||
83 | 0, NULL); \ | ||
84 | __nreg = 0; \ | ||
85 | } | ||
86 | |||
87 | #define ar9170_regwrite_result() \ | ||
88 | __err; \ | ||
89 | } while (0); | ||
90 | |||
91 | #endif /* __CMD_H */ | ||
diff --git a/drivers/net/wireless/ar9170/eeprom.h b/drivers/net/wireless/ar9170/eeprom.h new file mode 100644 index 000000000000..d2c8cc83f1dd --- /dev/null +++ b/drivers/net/wireless/ar9170/eeprom.h | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * EEPROM layout | ||
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_EEPROM_H | ||
39 | #define __AR9170_EEPROM_H | ||
40 | |||
41 | #define AR5416_MAX_CHAINS 2 | ||
42 | #define AR5416_MODAL_SPURS 5 | ||
43 | |||
44 | struct ar9170_eeprom_modal { | ||
45 | __le32 antCtrlChain[AR5416_MAX_CHAINS]; | ||
46 | __le32 antCtrlCommon; | ||
47 | s8 antennaGainCh[AR5416_MAX_CHAINS]; | ||
48 | u8 switchSettling; | ||
49 | u8 txRxAttenCh[AR5416_MAX_CHAINS]; | ||
50 | u8 rxTxMarginCh[AR5416_MAX_CHAINS]; | ||
51 | s8 adcDesiredSize; | ||
52 | s8 pgaDesiredSize; | ||
53 | u8 xlnaGainCh[AR5416_MAX_CHAINS]; | ||
54 | u8 txEndToXpaOff; | ||
55 | u8 txEndToRxOn; | ||
56 | u8 txFrameToXpaOn; | ||
57 | u8 thresh62; | ||
58 | s8 noiseFloorThreshCh[AR5416_MAX_CHAINS]; | ||
59 | u8 xpdGain; | ||
60 | u8 xpd; | ||
61 | s8 iqCalICh[AR5416_MAX_CHAINS]; | ||
62 | s8 iqCalQCh[AR5416_MAX_CHAINS]; | ||
63 | u8 pdGainOverlap; | ||
64 | u8 ob; | ||
65 | u8 db; | ||
66 | u8 xpaBiasLvl; | ||
67 | u8 pwrDecreaseFor2Chain; | ||
68 | u8 pwrDecreaseFor3Chain; | ||
69 | u8 txFrameToDataStart; | ||
70 | u8 txFrameToPaOn; | ||
71 | u8 ht40PowerIncForPdadc; | ||
72 | u8 bswAtten[AR5416_MAX_CHAINS]; | ||
73 | u8 bswMargin[AR5416_MAX_CHAINS]; | ||
74 | u8 swSettleHt40; | ||
75 | u8 reserved[22]; | ||
76 | struct spur_channel { | ||
77 | __le16 spurChan; | ||
78 | u8 spurRangeLow; | ||
79 | u8 spurRangeHigh; | ||
80 | } __packed spur_channels[AR5416_MODAL_SPURS]; | ||
81 | } __packed; | ||
82 | |||
83 | #define AR5416_NUM_PD_GAINS 4 | ||
84 | #define AR5416_PD_GAIN_ICEPTS 5 | ||
85 | |||
86 | struct ar9170_calibration_data_per_freq { | ||
87 | u8 pwr_pdg[AR5416_NUM_PD_GAINS][AR5416_PD_GAIN_ICEPTS]; | ||
88 | u8 vpd_pdg[AR5416_NUM_PD_GAINS][AR5416_PD_GAIN_ICEPTS]; | ||
89 | } __packed; | ||
90 | |||
91 | #define AR5416_NUM_5G_CAL_PIERS 8 | ||
92 | #define AR5416_NUM_2G_CAL_PIERS 4 | ||
93 | |||
94 | #define AR5416_NUM_5G_TARGET_PWRS 8 | ||
95 | #define AR5416_NUM_2G_CCK_TARGET_PWRS 3 | ||
96 | #define AR5416_NUM_2G_OFDM_TARGET_PWRS 4 | ||
97 | #define AR5416_MAX_NUM_TGT_PWRS 8 | ||
98 | |||
99 | struct ar9170_calibration_target_power_legacy { | ||
100 | u8 freq; | ||
101 | u8 power[4]; | ||
102 | } __packed; | ||
103 | |||
104 | struct ar9170_calibration_target_power_ht { | ||
105 | u8 freq; | ||
106 | u8 power[8]; | ||
107 | } __packed; | ||
108 | |||
109 | #define AR5416_NUM_CTLS 24 | ||
110 | |||
111 | struct ar9170_calctl_edges { | ||
112 | u8 channel; | ||
113 | #define AR9170_CALCTL_EDGE_FLAGS 0xC0 | ||
114 | u8 power_flags; | ||
115 | } __packed; | ||
116 | |||
117 | #define AR5416_NUM_BAND_EDGES 8 | ||
118 | |||
119 | struct ar9170_calctl_data { | ||
120 | struct ar9170_calctl_edges | ||
121 | control_edges[AR5416_MAX_CHAINS][AR5416_NUM_BAND_EDGES]; | ||
122 | } __packed; | ||
123 | |||
124 | |||
125 | struct ar9170_eeprom { | ||
126 | __le16 length; | ||
127 | __le16 checksum; | ||
128 | __le16 version; | ||
129 | u8 operating_flags; | ||
130 | #define AR9170_OPFLAG_5GHZ 1 | ||
131 | #define AR9170_OPFLAG_2GHZ 2 | ||
132 | u8 misc; | ||
133 | __le16 reg_domain[2]; | ||
134 | u8 mac_address[6]; | ||
135 | u8 rx_mask; | ||
136 | u8 tx_mask; | ||
137 | __le16 rf_silent; | ||
138 | __le16 bluetooth_options; | ||
139 | __le16 device_capabilities; | ||
140 | __le32 build_number; | ||
141 | u8 deviceType; | ||
142 | u8 reserved[33]; | ||
143 | |||
144 | u8 customer_data[64]; | ||
145 | |||
146 | struct ar9170_eeprom_modal | ||
147 | modal_header[2]; | ||
148 | |||
149 | u8 cal_freq_pier_5G[AR5416_NUM_5G_CAL_PIERS]; | ||
150 | u8 cal_freq_pier_2G[AR5416_NUM_2G_CAL_PIERS]; | ||
151 | |||
152 | struct ar9170_calibration_data_per_freq | ||
153 | cal_pier_data_5G[AR5416_MAX_CHAINS][AR5416_NUM_5G_CAL_PIERS], | ||
154 | cal_pier_data_2G[AR5416_MAX_CHAINS][AR5416_NUM_2G_CAL_PIERS]; | ||
155 | |||
156 | /* power calibration data */ | ||
157 | struct ar9170_calibration_target_power_legacy | ||
158 | cal_tgt_pwr_5G[AR5416_NUM_5G_TARGET_PWRS]; | ||
159 | struct ar9170_calibration_target_power_ht | ||
160 | cal_tgt_pwr_5G_ht20[AR5416_NUM_5G_TARGET_PWRS], | ||
161 | cal_tgt_pwr_5G_ht40[AR5416_NUM_5G_TARGET_PWRS]; | ||
162 | |||
163 | struct ar9170_calibration_target_power_legacy | ||
164 | cal_tgt_pwr_2G_cck[AR5416_NUM_2G_CCK_TARGET_PWRS], | ||
165 | cal_tgt_pwr_2G_ofdm[AR5416_NUM_2G_OFDM_TARGET_PWRS]; | ||
166 | struct ar9170_calibration_target_power_ht | ||
167 | cal_tgt_pwr_2G_ht20[AR5416_NUM_2G_OFDM_TARGET_PWRS], | ||
168 | cal_tgt_pwr_2G_ht40[AR5416_NUM_2G_OFDM_TARGET_PWRS]; | ||
169 | |||
170 | /* conformance testing limits */ | ||
171 | u8 ctl_index[AR5416_NUM_CTLS]; | ||
172 | struct ar9170_calctl_data | ||
173 | ctl_data[AR5416_NUM_CTLS]; | ||
174 | |||
175 | u8 pad; | ||
176 | __le16 subsystem_id; | ||
177 | } __packed; | ||
178 | |||
179 | #endif /* __AR9170_EEPROM_H */ | ||
diff --git a/drivers/net/wireless/ar9170/hw.h b/drivers/net/wireless/ar9170/hw.h new file mode 100644 index 000000000000..13091bd9d815 --- /dev/null +++ b/drivers/net/wireless/ar9170/hw.h | |||
@@ -0,0 +1,417 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * Hardware-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_HW_H | ||
39 | #define __AR9170_HW_H | ||
40 | |||
41 | #define AR9170_MAX_CMD_LEN 64 | ||
42 | |||
43 | enum ar9170_cmd { | ||
44 | AR9170_CMD_RREG = 0x00, | ||
45 | AR9170_CMD_WREG = 0x01, | ||
46 | AR9170_CMD_RMEM = 0x02, | ||
47 | AR9170_CMD_WMEM = 0x03, | ||
48 | AR9170_CMD_BITAND = 0x04, | ||
49 | AR9170_CMD_BITOR = 0x05, | ||
50 | AR9170_CMD_EKEY = 0x28, | ||
51 | AR9170_CMD_DKEY = 0x29, | ||
52 | AR9170_CMD_FREQUENCY = 0x30, | ||
53 | AR9170_CMD_RF_INIT = 0x31, | ||
54 | AR9170_CMD_SYNTH = 0x32, | ||
55 | AR9170_CMD_FREQ_START = 0x33, | ||
56 | AR9170_CMD_ECHO = 0x80, | ||
57 | AR9170_CMD_TALLY = 0x81, | ||
58 | AR9170_CMD_TALLY_APD = 0x82, | ||
59 | AR9170_CMD_CONFIG = 0x83, | ||
60 | AR9170_CMD_RESET = 0x90, | ||
61 | AR9170_CMD_DKRESET = 0x91, | ||
62 | AR9170_CMD_DKTX_STATUS = 0x92, | ||
63 | AR9170_CMD_FDC = 0xA0, | ||
64 | AR9170_CMD_WREEPROM = 0xB0, | ||
65 | AR9170_CMD_WFLASH = 0xB0, | ||
66 | AR9170_CMD_FLASH_ERASE = 0xB1, | ||
67 | AR9170_CMD_FLASH_PROG = 0xB2, | ||
68 | AR9170_CMD_FLASH_CHKSUM = 0xB3, | ||
69 | AR9170_CMD_FLASH_READ = 0xB4, | ||
70 | AR9170_CMD_FW_DL_INIT = 0xB5, | ||
71 | AR9170_CMD_MEM_WREEPROM = 0xBB, | ||
72 | }; | ||
73 | |||
74 | /* endpoints */ | ||
75 | #define AR9170_EP_TX 1 | ||
76 | #define AR9170_EP_RX 2 | ||
77 | #define AR9170_EP_IRQ 3 | ||
78 | #define AR9170_EP_CMD 4 | ||
79 | |||
80 | #define AR9170_EEPROM_START 0x1600 | ||
81 | |||
82 | #define AR9170_GPIO_REG_BASE 0x1d0100 | ||
83 | #define AR9170_GPIO_REG_PORT_TYPE AR9170_GPIO_REG_BASE | ||
84 | #define AR9170_GPIO_REG_DATA (AR9170_GPIO_REG_BASE + 4) | ||
85 | #define AR9170_NUM_LEDS 2 | ||
86 | |||
87 | |||
88 | #define AR9170_USB_REG_BASE 0x1e1000 | ||
89 | #define AR9170_USB_REG_DMA_CTL (AR9170_USB_REG_BASE + 0x108) | ||
90 | #define AR9170_DMA_CTL_ENABLE_TO_DEVICE 0x1 | ||
91 | #define AR9170_DMA_CTL_ENABLE_FROM_DEVICE 0x2 | ||
92 | #define AR9170_DMA_CTL_HIGH_SPEED 0x4 | ||
93 | #define AR9170_DMA_CTL_PACKET_MODE 0x8 | ||
94 | |||
95 | #define AR9170_USB_REG_MAX_AGG_UPLOAD (AR9170_USB_REG_BASE + 0x110) | ||
96 | #define AR9170_USB_REG_UPLOAD_TIME_CTL (AR9170_USB_REG_BASE + 0x114) | ||
97 | |||
98 | |||
99 | |||
100 | #define AR9170_MAC_REG_BASE 0x1c3000 | ||
101 | |||
102 | #define AR9170_MAC_REG_TSF_L (AR9170_MAC_REG_BASE + 0x514) | ||
103 | #define AR9170_MAC_REG_TSF_H (AR9170_MAC_REG_BASE + 0x518) | ||
104 | |||
105 | #define AR9170_MAC_REG_ATIM_WINDOW (AR9170_MAC_REG_BASE + 0x51C) | ||
106 | #define AR9170_MAC_REG_BCN_PERIOD (AR9170_MAC_REG_BASE + 0x520) | ||
107 | #define AR9170_MAC_REG_PRETBTT (AR9170_MAC_REG_BASE + 0x524) | ||
108 | |||
109 | #define AR9170_MAC_REG_MAC_ADDR_L (AR9170_MAC_REG_BASE + 0x610) | ||
110 | #define AR9170_MAC_REG_MAC_ADDR_H (AR9170_MAC_REG_BASE + 0x614) | ||
111 | #define AR9170_MAC_REG_BSSID_L (AR9170_MAC_REG_BASE + 0x618) | ||
112 | #define AR9170_MAC_REG_BSSID_H (AR9170_MAC_REG_BASE + 0x61c) | ||
113 | |||
114 | #define AR9170_MAC_REG_GROUP_HASH_TBL_L (AR9170_MAC_REG_BASE + 0x624) | ||
115 | #define AR9170_MAC_REG_GROUP_HASH_TBL_H (AR9170_MAC_REG_BASE + 0x628) | ||
116 | |||
117 | #define AR9170_MAC_REG_RX_TIMEOUT (AR9170_MAC_REG_BASE + 0x62C) | ||
118 | |||
119 | #define AR9170_MAC_REG_BASIC_RATE (AR9170_MAC_REG_BASE + 0x630) | ||
120 | #define AR9170_MAC_REG_MANDATORY_RATE (AR9170_MAC_REG_BASE + 0x634) | ||
121 | #define AR9170_MAC_REG_RTS_CTS_RATE (AR9170_MAC_REG_BASE + 0x638) | ||
122 | #define AR9170_MAC_REG_BACKOFF_PROTECT (AR9170_MAC_REG_BASE + 0x63c) | ||
123 | #define AR9170_MAC_REG_RX_THRESHOLD (AR9170_MAC_REG_BASE + 0x640) | ||
124 | #define AR9170_MAC_REG_RX_PE_DELAY (AR9170_MAC_REG_BASE + 0x64C) | ||
125 | |||
126 | #define AR9170_MAC_REG_DYNAMIC_SIFS_ACK (AR9170_MAC_REG_BASE + 0x658) | ||
127 | #define AR9170_MAC_REG_SNIFFER (AR9170_MAC_REG_BASE + 0x674) | ||
128 | #define AR9170_MAC_REG_SNIFFER_ENABLE_PROMISC BIT(0) | ||
129 | #define AR9170_MAC_REG_SNIFFER_DEFAULTS 0x02000000 | ||
130 | #define AR9170_MAC_REG_ENCRYPTION (AR9170_MAC_REG_BASE + 0x678) | ||
131 | #define AR9170_MAC_REG_ENCRYPTION_RX_SOFTWARE BIT(3) | ||
132 | #define AR9170_MAC_REG_ENCRYPTION_DEFAULTS 0x70 | ||
133 | |||
134 | #define AR9170_MAC_REG_MISC_680 (AR9170_MAC_REG_BASE + 0x680) | ||
135 | #define AR9170_MAC_REG_TX_UNDERRUN (AR9170_MAC_REG_BASE + 0x688) | ||
136 | |||
137 | #define AR9170_MAC_REG_FRAMETYPE_FILTER (AR9170_MAC_REG_BASE + 0x68c) | ||
138 | #define AR9170_MAC_REG_FTF_ASSOC_REQ BIT(0) | ||
139 | #define AR9170_MAC_REG_FTF_ASSOC_RESP BIT(1) | ||
140 | #define AR9170_MAC_REG_FTF_REASSOC_REQ BIT(2) | ||
141 | #define AR9170_MAC_REG_FTF_REASSOC_RESP BIT(3) | ||
142 | #define AR9170_MAC_REG_FTF_PRB_REQ BIT(4) | ||
143 | #define AR9170_MAC_REG_FTF_PRB_RESP BIT(5) | ||
144 | #define AR9170_MAC_REG_FTF_BIT6 BIT(6) | ||
145 | #define AR9170_MAC_REG_FTF_BIT7 BIT(7) | ||
146 | #define AR9170_MAC_REG_FTF_BEACON BIT(8) | ||
147 | #define AR9170_MAC_REG_FTF_ATIM BIT(9) | ||
148 | #define AR9170_MAC_REG_FTF_DEASSOC BIT(10) | ||
149 | #define AR9170_MAC_REG_FTF_AUTH BIT(11) | ||
150 | #define AR9170_MAC_REG_FTF_DEAUTH BIT(12) | ||
151 | #define AR9170_MAC_REG_FTF_BIT13 BIT(13) | ||
152 | #define AR9170_MAC_REG_FTF_BIT14 BIT(14) | ||
153 | #define AR9170_MAC_REG_FTF_BIT15 BIT(15) | ||
154 | #define AR9170_MAC_REG_FTF_BAR BIT(24) | ||
155 | #define AR9170_MAC_REG_FTF_BIT25 BIT(25) | ||
156 | #define AR9170_MAC_REG_FTF_PSPOLL BIT(26) | ||
157 | #define AR9170_MAC_REG_FTF_RTS BIT(27) | ||
158 | #define AR9170_MAC_REG_FTF_CTS BIT(28) | ||
159 | #define AR9170_MAC_REG_FTF_ACK BIT(29) | ||
160 | #define AR9170_MAC_REG_FTF_CFE BIT(30) | ||
161 | #define AR9170_MAC_REG_FTF_CFE_ACK BIT(31) | ||
162 | #define AR9170_MAC_REG_FTF_DEFAULTS 0x0500ffff | ||
163 | #define AR9170_MAC_REG_FTF_MONITOR 0xfd00ffff | ||
164 | |||
165 | #define AR9170_MAC_REG_RX_TOTAL (AR9170_MAC_REG_BASE + 0x6A0) | ||
166 | #define AR9170_MAC_REG_RX_CRC32 (AR9170_MAC_REG_BASE + 0x6A4) | ||
167 | #define AR9170_MAC_REG_RX_CRC16 (AR9170_MAC_REG_BASE + 0x6A8) | ||
168 | #define AR9170_MAC_REG_RX_ERR_DECRYPTION_UNI (AR9170_MAC_REG_BASE + 0x6AC) | ||
169 | #define AR9170_MAC_REG_RX_OVERRUN (AR9170_MAC_REG_BASE + 0x6B0) | ||
170 | #define AR9170_MAC_REG_RX_ERR_DECRYPTION_MUL (AR9170_MAC_REG_BASE + 0x6BC) | ||
171 | #define AR9170_MAC_REG_TX_RETRY (AR9170_MAC_REG_BASE + 0x6CC) | ||
172 | #define AR9170_MAC_REG_TX_TOTAL (AR9170_MAC_REG_BASE + 0x6F4) | ||
173 | |||
174 | |||
175 | #define AR9170_MAC_REG_ACK_EXTENSION (AR9170_MAC_REG_BASE + 0x690) | ||
176 | #define AR9170_MAC_REG_EIFS_AND_SIFS (AR9170_MAC_REG_BASE + 0x698) | ||
177 | |||
178 | #define AR9170_MAC_REG_SLOT_TIME (AR9170_MAC_REG_BASE + 0x6F0) | ||
179 | |||
180 | #define AR9170_MAC_REG_POWERMANAGEMENT (AR9170_MAC_REG_BASE + 0x700) | ||
181 | #define AR9170_MAC_REG_POWERMGT_IBSS 0xe0 | ||
182 | #define AR9170_MAC_REG_POWERMGT_AP 0xa1 | ||
183 | #define AR9170_MAC_REG_POWERMGT_STA 0x2 | ||
184 | #define AR9170_MAC_REG_POWERMGT_AP_WDS 0x3 | ||
185 | #define AR9170_MAC_REG_POWERMGT_DEFAULTS (0xf << 24) | ||
186 | |||
187 | #define AR9170_MAC_REG_ROLL_CALL_TBL_L (AR9170_MAC_REG_BASE + 0x704) | ||
188 | #define AR9170_MAC_REG_ROLL_CALL_TBL_H (AR9170_MAC_REG_BASE + 0x708) | ||
189 | |||
190 | #define AR9170_MAC_REG_AC0_CW (AR9170_MAC_REG_BASE + 0xB00) | ||
191 | #define AR9170_MAC_REG_AC1_CW (AR9170_MAC_REG_BASE + 0xB04) | ||
192 | #define AR9170_MAC_REG_AC2_CW (AR9170_MAC_REG_BASE + 0xB08) | ||
193 | #define AR9170_MAC_REG_AC3_CW (AR9170_MAC_REG_BASE + 0xB0C) | ||
194 | #define AR9170_MAC_REG_AC4_CW (AR9170_MAC_REG_BASE + 0xB10) | ||
195 | #define AR9170_MAC_REG_AC1_AC0_AIFS (AR9170_MAC_REG_BASE + 0xB14) | ||
196 | #define AR9170_MAC_REG_AC3_AC2_AIFS (AR9170_MAC_REG_BASE + 0xB18) | ||
197 | |||
198 | #define AR9170_MAC_REG_RETRY_MAX (AR9170_MAC_REG_BASE + 0xB28) | ||
199 | |||
200 | #define AR9170_MAC_REG_FCS_SELECT (AR9170_MAC_REG_BASE + 0xBB0) | ||
201 | #define AR9170_MAC_FCS_SWFCS 0x1 | ||
202 | #define AR9170_MAC_FCS_FIFO_PROT 0x4 | ||
203 | |||
204 | |||
205 | #define AR9170_MAC_REG_TXOP_NOT_ENOUGH_IND (AR9170_MAC_REG_BASE + 0xB30) | ||
206 | |||
207 | #define AR9170_MAC_REG_AC1_AC0_TXOP (AR9170_MAC_REG_BASE + 0xB44) | ||
208 | #define AR9170_MAC_REG_AC3_AC2_TXOP (AR9170_MAC_REG_BASE + 0xB48) | ||
209 | |||
210 | #define AR9170_MAC_REG_ACK_TABLE (AR9170_MAC_REG_BASE + 0xC00) | ||
211 | #define AR9170_MAC_REG_AMPDU_RX_THRESH (AR9170_MAC_REG_BASE + 0xC50) | ||
212 | |||
213 | #define AR9170_MAC_REG_TXRX_MPI (AR9170_MAC_REG_BASE + 0xD7C) | ||
214 | #define AR9170_MAC_TXRX_MPI_TX_MPI_MASK 0x0000000f | ||
215 | #define AR9170_MAC_TXRX_MPI_TX_TO_MASK 0x0000fff0 | ||
216 | #define AR9170_MAC_TXRX_MPI_RX_MPI_MASK 0x000f0000 | ||
217 | #define AR9170_MAC_TXRX_MPI_RX_TO_MASK 0xfff00000 | ||
218 | |||
219 | #define AR9170_MAC_REG_BCN_ADDR (AR9170_MAC_REG_BASE + 0xD84) | ||
220 | #define AR9170_MAC_REG_BCN_LENGTH (AR9170_MAC_REG_BASE + 0xD88) | ||
221 | #define AR9170_MAC_REG_BCN_PLCP (AR9170_MAC_REG_BASE + 0xD90) | ||
222 | #define AR9170_MAC_REG_BCN_CTRL (AR9170_MAC_REG_BASE + 0xD94) | ||
223 | #define AR9170_MAC_REG_BCN_HT1 (AR9170_MAC_REG_BASE + 0xDA0) | ||
224 | #define AR9170_MAC_REG_BCN_HT2 (AR9170_MAC_REG_BASE + 0xDA4) | ||
225 | |||
226 | |||
227 | #define AR9170_PWR_REG_BASE 0x1D4000 | ||
228 | |||
229 | #define AR9170_PWR_REG_CLOCK_SEL (AR9170_PWR_REG_BASE + 0x008) | ||
230 | #define AR9170_PWR_CLK_AHB_40MHZ 0 | ||
231 | #define AR9170_PWR_CLK_AHB_20_22MHZ 1 | ||
232 | #define AR9170_PWR_CLK_AHB_40_44MHZ 2 | ||
233 | #define AR9170_PWR_CLK_AHB_80_88MHZ 3 | ||
234 | #define AR9170_PWR_CLK_DAC_160_INV_DLY 0x70 | ||
235 | |||
236 | |||
237 | /* put beacon here in memory */ | ||
238 | #define AR9170_BEACON_BUFFER_ADDRESS 0x117900 | ||
239 | |||
240 | |||
241 | struct ar9170_tx_control { | ||
242 | __le16 length; | ||
243 | __le16 mac_control; | ||
244 | __le32 phy_control; | ||
245 | u8 frame_data[0]; | ||
246 | } __packed; | ||
247 | |||
248 | /* these are either-or */ | ||
249 | #define AR9170_TX_MAC_PROT_RTS 0x0001 | ||
250 | #define AR9170_TX_MAC_PROT_CTS 0x0002 | ||
251 | |||
252 | #define AR9170_TX_MAC_NO_ACK 0x0004 | ||
253 | /* if unset, MAC will only do SIFS space before frame */ | ||
254 | #define AR9170_TX_MAC_BACKOFF 0x0008 | ||
255 | #define AR9170_TX_MAC_BURST 0x0010 | ||
256 | #define AR9170_TX_MAC_AGGR 0x0020 | ||
257 | |||
258 | /* encryption is a two-bit field */ | ||
259 | #define AR9170_TX_MAC_ENCR_NONE 0x0000 | ||
260 | #define AR9170_TX_MAC_ENCR_RC4 0x0040 | ||
261 | #define AR9170_TX_MAC_ENCR_CENC 0x0080 | ||
262 | #define AR9170_TX_MAC_ENCR_AES 0x00c0 | ||
263 | |||
264 | #define AR9170_TX_MAC_MMIC 0x0100 | ||
265 | #define AR9170_TX_MAC_HW_DURATION 0x0200 | ||
266 | #define AR9170_TX_MAC_QOS_SHIFT 10 | ||
267 | #define AR9170_TX_MAC_QOS_MASK (3 << AR9170_TX_MAC_QOS_SHIFT) | ||
268 | #define AR9170_TX_MAC_AGGR_QOS_BIT1 0x0400 | ||
269 | #define AR9170_TX_MAC_AGGR_QOS_BIT2 0x0800 | ||
270 | #define AR9170_TX_MAC_DISABLE_TXOP 0x1000 | ||
271 | #define AR9170_TX_MAC_TXOP_RIFS 0x2000 | ||
272 | #define AR9170_TX_MAC_IMM_AMPDU 0x4000 | ||
273 | #define AR9170_TX_MAC_RATE_PROBE 0x8000 | ||
274 | |||
275 | /* either-or */ | ||
276 | #define AR9170_TX_PHY_MOD_CCK 0x00000000 | ||
277 | #define AR9170_TX_PHY_MOD_OFDM 0x00000001 | ||
278 | #define AR9170_TX_PHY_MOD_HT 0x00000002 | ||
279 | |||
280 | /* depends on modulation */ | ||
281 | #define AR9170_TX_PHY_SHORT_PREAMBLE 0x00000004 | ||
282 | #define AR9170_TX_PHY_GREENFIELD 0x00000004 | ||
283 | |||
284 | #define AR9170_TX_PHY_BW_SHIFT 3 | ||
285 | #define AR9170_TX_PHY_BW_MASK (3 << AR9170_TX_PHY_BW_SHIFT) | ||
286 | #define AR9170_TX_PHY_BW_20MHZ 0 | ||
287 | #define AR9170_TX_PHY_BW_40MHZ 2 | ||
288 | #define AR9170_TX_PHY_BW_40MHZ_DUP 3 | ||
289 | |||
290 | #define AR9170_TX_PHY_TX_HEAVY_CLIP_SHIFT 6 | ||
291 | #define AR9170_TX_PHY_TX_HEAVY_CLIP_MASK (7 << AR9170_TX_PHY_TX_HEAVY_CLIP_SHIFT) | ||
292 | |||
293 | #define AR9170_TX_PHY_TX_PWR_SHIFT 9 | ||
294 | #define AR9170_TX_PHY_TX_PWR_MASK (0x3f << AR9170_TX_PHY_TX_PWR_SHIFT) | ||
295 | |||
296 | /* not part of the hw-spec */ | ||
297 | #define AR9170_TX_PHY_QOS_SHIFT 25 | ||
298 | #define AR9170_TX_PHY_QOS_MASK (3 << AR9170_TX_PHY_QOS_SHIFT) | ||
299 | |||
300 | #define AR9170_TX_PHY_TXCHAIN_SHIFT 15 | ||
301 | #define AR9170_TX_PHY_TXCHAIN_MASK (7 << AR9170_TX_PHY_TXCHAIN_SHIFT) | ||
302 | #define AR9170_TX_PHY_TXCHAIN_1 1 | ||
303 | /* use for cck, ofdm 6/9/12/18/24 and HT if capable */ | ||
304 | #define AR9170_TX_PHY_TXCHAIN_2 5 | ||
305 | |||
306 | #define AR9170_TX_PHY_MCS_SHIFT 18 | ||
307 | #define AR9170_TX_PHY_MCS_MASK (0x7f << AR9170_TX_PHY_MCS_SHIFT) | ||
308 | |||
309 | #define AR9170_TX_PHY_SHORT_GI 0x80000000 | ||
310 | |||
311 | struct ar9170_rx_head { | ||
312 | u8 plcp[12]; | ||
313 | }; | ||
314 | |||
315 | struct ar9170_rx_tail { | ||
316 | union { | ||
317 | struct { | ||
318 | u8 rssi_ant0, rssi_ant1, rssi_ant2, | ||
319 | rssi_ant0x, rssi_ant1x, rssi_ant2x, | ||
320 | rssi_combined; | ||
321 | }; | ||
322 | u8 rssi[7]; | ||
323 | }; | ||
324 | |||
325 | u8 evm_stream0[6], evm_stream1[6]; | ||
326 | u8 phy_err; | ||
327 | u8 SAidx, DAidx; | ||
328 | u8 error; | ||
329 | u8 status; | ||
330 | }; | ||
331 | |||
332 | #define AR9170_ENC_ALG_NONE 0x0 | ||
333 | #define AR9170_ENC_ALG_WEP64 0x1 | ||
334 | #define AR9170_ENC_ALG_TKIP 0x2 | ||
335 | #define AR9170_ENC_ALG_AESCCMP 0x4 | ||
336 | #define AR9170_ENC_ALG_WEP128 0x5 | ||
337 | #define AR9170_ENC_ALG_WEP256 0x6 | ||
338 | #define AR9170_ENC_ALG_CENC 0x7 | ||
339 | |||
340 | #define AR9170_RX_ENC_SOFTWARE 0x8 | ||
341 | |||
342 | static inline u8 ar9170_get_decrypt_type(struct ar9170_rx_tail *t) | ||
343 | { | ||
344 | return (t->SAidx & 0xc0) >> 4 | | ||
345 | (t->DAidx & 0xc0) >> 6; | ||
346 | } | ||
347 | |||
348 | #define AR9170_RX_STATUS_MODULATION_MASK 0x03 | ||
349 | #define AR9170_RX_STATUS_MODULATION_CCK 0x00 | ||
350 | #define AR9170_RX_STATUS_MODULATION_OFDM 0x01 | ||
351 | #define AR9170_RX_STATUS_MODULATION_HT 0x02 | ||
352 | #define AR9170_RX_STATUS_MODULATION_DUPOFDM 0x03 | ||
353 | |||
354 | /* depends on modulation */ | ||
355 | #define AR9170_RX_STATUS_SHORT_PREAMBLE 0x08 | ||
356 | #define AR9170_RX_STATUS_GREENFIELD 0x08 | ||
357 | |||
358 | #define AR9170_RX_STATUS_MPDU_MASK 0x30 | ||
359 | #define AR9170_RX_STATUS_MPDU_SINGLE 0x00 | ||
360 | #define AR9170_RX_STATUS_MPDU_FIRST 0x10 | ||
361 | #define AR9170_RX_STATUS_MPDU_MIDDLE 0x20 | ||
362 | #define AR9170_RX_STATUS_MPDU_LAST 0x30 | ||
363 | |||
364 | |||
365 | #define AR9170_RX_ERROR_RXTO 0x01 | ||
366 | #define AR9170_RX_ERROR_OVERRUN 0x02 | ||
367 | #define AR9170_RX_ERROR_DECRYPT 0x04 | ||
368 | #define AR9170_RX_ERROR_FCS 0x08 | ||
369 | #define AR9170_RX_ERROR_WRONG_RA 0x10 | ||
370 | #define AR9170_RX_ERROR_PLCP 0x20 | ||
371 | #define AR9170_RX_ERROR_MMIC 0x40 | ||
372 | |||
373 | struct ar9170_cmd_tx_status { | ||
374 | __le16 unkn; | ||
375 | u8 dst[ETH_ALEN]; | ||
376 | __le32 rate; | ||
377 | __le16 status; | ||
378 | } __packed; | ||
379 | |||
380 | #define AR9170_TX_STATUS_COMPLETE 0x00 | ||
381 | #define AR9170_TX_STATUS_RETRY 0x01 | ||
382 | #define AR9170_TX_STATUS_FAILED 0x02 | ||
383 | |||
384 | struct ar9170_cmd_ba_failed_count { | ||
385 | __le16 failed; | ||
386 | __le16 rate; | ||
387 | } __packed; | ||
388 | |||
389 | struct ar9170_cmd_response { | ||
390 | u8 flag; | ||
391 | u8 type; | ||
392 | |||
393 | union { | ||
394 | struct ar9170_cmd_tx_status tx_status; | ||
395 | struct ar9170_cmd_ba_failed_count ba_fail_cnt; | ||
396 | u8 data[0]; | ||
397 | }; | ||
398 | } __packed; | ||
399 | |||
400 | /* QoS */ | ||
401 | |||
402 | /* mac80211 queue to HW/FW map */ | ||
403 | static const u8 ar9170_qos_hwmap[4] = { 3, 2, 0, 1 }; | ||
404 | |||
405 | /* HW/FW queue to mac80211 map */ | ||
406 | static const u8 ar9170_qos_mac80211map[4] = { 2, 3, 1, 0 }; | ||
407 | |||
408 | enum ar9170_txq { | ||
409 | AR9170_TXQ_BE, | ||
410 | AR9170_TXQ_BK, | ||
411 | AR9170_TXQ_VI, | ||
412 | AR9170_TXQ_VO, | ||
413 | |||
414 | __AR9170_NUM_TXQ, | ||
415 | }; | ||
416 | |||
417 | #endif /* __AR9170_HW_H */ | ||
diff --git a/drivers/net/wireless/ar9170/led.c b/drivers/net/wireless/ar9170/led.c new file mode 100644 index 000000000000..341cead7f606 --- /dev/null +++ b/drivers/net/wireless/ar9170/led.c | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * LED handling | ||
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 | |||
39 | #include "ar9170.h" | ||
40 | #include "cmd.h" | ||
41 | |||
42 | int ar9170_set_leds_state(struct ar9170 *ar, u32 led_state) | ||
43 | { | ||
44 | return ar9170_write_reg(ar, AR9170_GPIO_REG_DATA, led_state); | ||
45 | } | ||
46 | |||
47 | int ar9170_init_leds(struct ar9170 *ar) | ||
48 | { | ||
49 | int err; | ||
50 | |||
51 | /* disable LEDs */ | ||
52 | /* GPIO [0/1 mode: output, 2/3: input] */ | ||
53 | err = ar9170_write_reg(ar, AR9170_GPIO_REG_PORT_TYPE, 3); | ||
54 | if (err) | ||
55 | goto out; | ||
56 | |||
57 | /* GPIO 0/1 value: off */ | ||
58 | err = ar9170_set_leds_state(ar, 0); | ||
59 | |||
60 | out: | ||
61 | return err; | ||
62 | } | ||
63 | |||
64 | #ifdef CONFIG_AR9170_LEDS | ||
65 | static void ar9170_update_leds(struct work_struct *work) | ||
66 | { | ||
67 | struct ar9170 *ar = container_of(work, struct ar9170, led_work.work); | ||
68 | int i, tmp, blink_delay = 1000; | ||
69 | u32 led_val = 0; | ||
70 | bool rerun = false; | ||
71 | |||
72 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
73 | return ; | ||
74 | |||
75 | mutex_lock(&ar->mutex); | ||
76 | for (i = 0; i < AR9170_NUM_LEDS; i++) | ||
77 | if (ar->leds[i].toggled) { | ||
78 | led_val |= 1 << i; | ||
79 | |||
80 | tmp = 70 + 200 / (ar->leds[i].toggled); | ||
81 | if (tmp < blink_delay) | ||
82 | blink_delay = tmp; | ||
83 | |||
84 | if (ar->leds[i].toggled > 1) | ||
85 | ar->leds[i].toggled = 0; | ||
86 | |||
87 | rerun = true; | ||
88 | } | ||
89 | |||
90 | ar9170_set_leds_state(ar, led_val); | ||
91 | mutex_unlock(&ar->mutex); | ||
92 | |||
93 | if (rerun) | ||
94 | queue_delayed_work(ar->hw->workqueue, &ar->led_work, | ||
95 | msecs_to_jiffies(blink_delay)); | ||
96 | } | ||
97 | |||
98 | static void ar9170_led_brightness_set(struct led_classdev *led, | ||
99 | enum led_brightness brightness) | ||
100 | { | ||
101 | struct ar9170_led *arl = container_of(led, struct ar9170_led, l); | ||
102 | struct ar9170 *ar = arl->ar; | ||
103 | |||
104 | arl->toggled++; | ||
105 | |||
106 | if (likely(IS_ACCEPTING_CMD(ar) && brightness)) | ||
107 | queue_delayed_work(ar->hw->workqueue, &ar->led_work, HZ/10); | ||
108 | } | ||
109 | |||
110 | static int ar9170_register_led(struct ar9170 *ar, int i, char *name, | ||
111 | char *trigger) | ||
112 | { | ||
113 | int err; | ||
114 | |||
115 | snprintf(ar->leds[i].name, sizeof(ar->leds[i].name), | ||
116 | "ar9170-%s::%s", wiphy_name(ar->hw->wiphy), name); | ||
117 | |||
118 | ar->leds[i].ar = ar; | ||
119 | ar->leds[i].l.name = ar->leds[i].name; | ||
120 | ar->leds[i].l.brightness_set = ar9170_led_brightness_set; | ||
121 | ar->leds[i].l.brightness = 0; | ||
122 | ar->leds[i].l.default_trigger = trigger; | ||
123 | |||
124 | err = led_classdev_register(wiphy_dev(ar->hw->wiphy), | ||
125 | &ar->leds[i].l); | ||
126 | if (err) | ||
127 | printk(KERN_ERR "%s: failed to register %s LED (%d).\n", | ||
128 | wiphy_name(ar->hw->wiphy), ar->leds[i].name, err); | ||
129 | else | ||
130 | ar->leds[i].registered = true; | ||
131 | |||
132 | return err; | ||
133 | } | ||
134 | |||
135 | void ar9170_unregister_leds(struct ar9170 *ar) | ||
136 | { | ||
137 | int i; | ||
138 | |||
139 | cancel_delayed_work_sync(&ar->led_work); | ||
140 | |||
141 | for (i = 0; i < AR9170_NUM_LEDS; i++) | ||
142 | if (ar->leds[i].registered) { | ||
143 | led_classdev_unregister(&ar->leds[i].l); | ||
144 | ar->leds[i].registered = false; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | int ar9170_register_leds(struct ar9170 *ar) | ||
149 | { | ||
150 | int err; | ||
151 | |||
152 | INIT_DELAYED_WORK(&ar->led_work, ar9170_update_leds); | ||
153 | |||
154 | err = ar9170_register_led(ar, 0, "tx", | ||
155 | ieee80211_get_tx_led_name(ar->hw)); | ||
156 | if (err) | ||
157 | goto fail; | ||
158 | |||
159 | err = ar9170_register_led(ar, 1, "assoc", | ||
160 | ieee80211_get_assoc_led_name(ar->hw)); | ||
161 | if (err) | ||
162 | goto fail; | ||
163 | |||
164 | return 0; | ||
165 | |||
166 | fail: | ||
167 | ar9170_unregister_leds(ar); | ||
168 | return err; | ||
169 | } | ||
170 | |||
171 | #endif /* CONFIG_AR9170_LEDS */ | ||
diff --git a/drivers/net/wireless/ar9170/mac.c b/drivers/net/wireless/ar9170/mac.c new file mode 100644 index 000000000000..c8fa3073169f --- /dev/null +++ b/drivers/net/wireless/ar9170/mac.c | |||
@@ -0,0 +1,452 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * MAC programming | ||
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 | #include "ar9170.h" | ||
39 | #include "cmd.h" | ||
40 | |||
41 | int ar9170_set_qos(struct ar9170 *ar) | ||
42 | { | ||
43 | ar9170_regwrite_begin(ar); | ||
44 | |||
45 | ar9170_regwrite(AR9170_MAC_REG_AC0_CW, ar->edcf[0].cw_min | | ||
46 | (ar->edcf[0].cw_max << 16)); | ||
47 | ar9170_regwrite(AR9170_MAC_REG_AC1_CW, ar->edcf[1].cw_min | | ||
48 | (ar->edcf[1].cw_max << 16)); | ||
49 | ar9170_regwrite(AR9170_MAC_REG_AC2_CW, ar->edcf[2].cw_min | | ||
50 | (ar->edcf[2].cw_max << 16)); | ||
51 | ar9170_regwrite(AR9170_MAC_REG_AC3_CW, ar->edcf[3].cw_min | | ||
52 | (ar->edcf[3].cw_max << 16)); | ||
53 | ar9170_regwrite(AR9170_MAC_REG_AC4_CW, ar->edcf[4].cw_min | | ||
54 | (ar->edcf[4].cw_max << 16)); | ||
55 | |||
56 | ar9170_regwrite(AR9170_MAC_REG_AC1_AC0_AIFS, | ||
57 | ((ar->edcf[0].aifs * 9 + 10)) | | ||
58 | ((ar->edcf[1].aifs * 9 + 10) << 12) | | ||
59 | ((ar->edcf[2].aifs * 9 + 10) << 24)); | ||
60 | ar9170_regwrite(AR9170_MAC_REG_AC3_AC2_AIFS, | ||
61 | ((ar->edcf[2].aifs * 9 + 10) >> 8) | | ||
62 | ((ar->edcf[3].aifs * 9 + 10) << 4) | | ||
63 | ((ar->edcf[4].aifs * 9 + 10) << 16)); | ||
64 | |||
65 | ar9170_regwrite(AR9170_MAC_REG_AC1_AC0_TXOP, | ||
66 | ar->edcf[0].txop | ar->edcf[1].txop << 16); | ||
67 | ar9170_regwrite(AR9170_MAC_REG_AC3_AC2_TXOP, | ||
68 | ar->edcf[1].txop | ar->edcf[3].txop << 16); | ||
69 | |||
70 | ar9170_regwrite_finish(); | ||
71 | |||
72 | return ar9170_regwrite_result(); | ||
73 | } | ||
74 | |||
75 | int ar9170_init_mac(struct ar9170 *ar) | ||
76 | { | ||
77 | ar9170_regwrite_begin(ar); | ||
78 | |||
79 | ar9170_regwrite(AR9170_MAC_REG_ACK_EXTENSION, 0x40); | ||
80 | |||
81 | ar9170_regwrite(AR9170_MAC_REG_RETRY_MAX, 0); | ||
82 | |||
83 | /* enable MMIC */ | ||
84 | ar9170_regwrite(AR9170_MAC_REG_SNIFFER, | ||
85 | AR9170_MAC_REG_SNIFFER_DEFAULTS); | ||
86 | |||
87 | ar9170_regwrite(AR9170_MAC_REG_RX_THRESHOLD, 0xc1f80); | ||
88 | |||
89 | ar9170_regwrite(AR9170_MAC_REG_RX_PE_DELAY, 0x70); | ||
90 | ar9170_regwrite(AR9170_MAC_REG_EIFS_AND_SIFS, 0xa144000); | ||
91 | ar9170_regwrite(AR9170_MAC_REG_SLOT_TIME, 9 << 10); | ||
92 | |||
93 | /* CF-END mode */ | ||
94 | ar9170_regwrite(0x1c3b2c, 0x19000000); | ||
95 | |||
96 | /* NAV protects ACK only (in TXOP) */ | ||
97 | ar9170_regwrite(0x1c3b38, 0x201); | ||
98 | |||
99 | /* Set Beacon PHY CTRL's TPC to 0x7, TA1=1 */ | ||
100 | /* OTUS set AM to 0x1 */ | ||
101 | ar9170_regwrite(AR9170_MAC_REG_BCN_HT1, 0x8000170); | ||
102 | |||
103 | ar9170_regwrite(AR9170_MAC_REG_BACKOFF_PROTECT, 0x105); | ||
104 | |||
105 | /* AGG test code*/ | ||
106 | /* Aggregation MAX number and timeout */ | ||
107 | ar9170_regwrite(0x1c3b9c, 0x10000a); | ||
108 | |||
109 | ar9170_regwrite(AR9170_MAC_REG_FRAMETYPE_FILTER, | ||
110 | AR9170_MAC_REG_FTF_DEFAULTS); | ||
111 | |||
112 | /* Enable deaggregator, response in sniffer mode */ | ||
113 | ar9170_regwrite(0x1c3c40, 0x1 | 1<<30); | ||
114 | |||
115 | /* rate sets */ | ||
116 | ar9170_regwrite(AR9170_MAC_REG_BASIC_RATE, 0x150f); | ||
117 | ar9170_regwrite(AR9170_MAC_REG_MANDATORY_RATE, 0x150f); | ||
118 | ar9170_regwrite(AR9170_MAC_REG_RTS_CTS_RATE, 0x10b01bb); | ||
119 | |||
120 | /* MIMO response control */ | ||
121 | ar9170_regwrite(0x1c3694, 0x4003C1E);/* bit 26~28 otus-AM */ | ||
122 | |||
123 | /* switch MAC to OTUS interface */ | ||
124 | ar9170_regwrite(0x1c3600, 0x3); | ||
125 | |||
126 | ar9170_regwrite(AR9170_MAC_REG_AMPDU_RX_THRESH, 0xffff); | ||
127 | |||
128 | /* set PHY register read timeout (??) */ | ||
129 | ar9170_regwrite(AR9170_MAC_REG_MISC_680, 0xf00008); | ||
130 | |||
131 | /* Disable Rx TimeOut, workaround for BB. */ | ||
132 | ar9170_regwrite(AR9170_MAC_REG_RX_TIMEOUT, 0x0); | ||
133 | |||
134 | /* Set CPU clock frequency to 88/80MHz */ | ||
135 | ar9170_regwrite(AR9170_PWR_REG_CLOCK_SEL, | ||
136 | AR9170_PWR_CLK_AHB_80_88MHZ | | ||
137 | AR9170_PWR_CLK_DAC_160_INV_DLY); | ||
138 | |||
139 | /* Set WLAN DMA interrupt mode: generate int per packet */ | ||
140 | ar9170_regwrite(AR9170_MAC_REG_TXRX_MPI, 0x110011); | ||
141 | |||
142 | ar9170_regwrite(AR9170_MAC_REG_FCS_SELECT, | ||
143 | AR9170_MAC_FCS_FIFO_PROT); | ||
144 | |||
145 | /* Disables the CF_END frame, undocumented register */ | ||
146 | ar9170_regwrite(AR9170_MAC_REG_TXOP_NOT_ENOUGH_IND, | ||
147 | 0x141E0F48); | ||
148 | |||
149 | ar9170_regwrite_finish(); | ||
150 | |||
151 | return ar9170_regwrite_result(); | ||
152 | } | ||
153 | |||
154 | static int ar9170_set_mac_reg(struct ar9170 *ar, const u32 reg, const u8 *mac) | ||
155 | { | ||
156 | static const u8 zero[ETH_ALEN] = { 0 }; | ||
157 | |||
158 | if (!mac) | ||
159 | mac = zero; | ||
160 | |||
161 | ar9170_regwrite_begin(ar); | ||
162 | |||
163 | ar9170_regwrite(reg, | ||
164 | (mac[3] << 24) | (mac[2] << 16) | | ||
165 | (mac[1] << 8) | mac[0]); | ||
166 | |||
167 | ar9170_regwrite(reg + 4, (mac[5] << 8) | mac[4]); | ||
168 | |||
169 | ar9170_regwrite_finish(); | ||
170 | |||
171 | return ar9170_regwrite_result(); | ||
172 | } | ||
173 | |||
174 | int ar9170_update_multicast(struct ar9170 *ar) | ||
175 | { | ||
176 | int err; | ||
177 | |||
178 | ar9170_regwrite_begin(ar); | ||
179 | ar9170_regwrite(AR9170_MAC_REG_GROUP_HASH_TBL_H, | ||
180 | ar->want_mc_hash >> 32); | ||
181 | ar9170_regwrite(AR9170_MAC_REG_GROUP_HASH_TBL_L, | ||
182 | ar->want_mc_hash); | ||
183 | |||
184 | ar9170_regwrite_finish(); | ||
185 | err = ar9170_regwrite_result(); | ||
186 | |||
187 | if (err) | ||
188 | return err; | ||
189 | |||
190 | ar->cur_mc_hash = ar->want_mc_hash; | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | int ar9170_update_frame_filter(struct ar9170 *ar) | ||
196 | { | ||
197 | int err; | ||
198 | |||
199 | err = ar9170_write_reg(ar, AR9170_MAC_REG_FRAMETYPE_FILTER, | ||
200 | ar->want_filter); | ||
201 | |||
202 | if (err) | ||
203 | return err; | ||
204 | |||
205 | ar->cur_filter = ar->want_filter; | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int ar9170_set_promiscouous(struct ar9170 *ar) | ||
211 | { | ||
212 | u32 encr_mode, sniffer; | ||
213 | int err; | ||
214 | |||
215 | err = ar9170_read_reg(ar, AR9170_MAC_REG_SNIFFER, &sniffer); | ||
216 | if (err) | ||
217 | return err; | ||
218 | |||
219 | err = ar9170_read_reg(ar, AR9170_MAC_REG_ENCRYPTION, &encr_mode); | ||
220 | if (err) | ||
221 | return err; | ||
222 | |||
223 | if (ar->sniffer_enabled) { | ||
224 | sniffer |= AR9170_MAC_REG_SNIFFER_ENABLE_PROMISC; | ||
225 | |||
226 | /* | ||
227 | * Rx decryption works in place. | ||
228 | * | ||
229 | * If we don't disable it, the hardware will render all | ||
230 | * encrypted frames which are encrypted with an unknown | ||
231 | * key useless. | ||
232 | */ | ||
233 | |||
234 | encr_mode |= AR9170_MAC_REG_ENCRYPTION_RX_SOFTWARE; | ||
235 | ar->sniffer_enabled = true; | ||
236 | } else { | ||
237 | sniffer &= ~AR9170_MAC_REG_SNIFFER_ENABLE_PROMISC; | ||
238 | |||
239 | if (ar->rx_software_decryption) | ||
240 | encr_mode |= AR9170_MAC_REG_ENCRYPTION_RX_SOFTWARE; | ||
241 | else | ||
242 | encr_mode &= ~AR9170_MAC_REG_ENCRYPTION_RX_SOFTWARE; | ||
243 | } | ||
244 | |||
245 | ar9170_regwrite_begin(ar); | ||
246 | ar9170_regwrite(AR9170_MAC_REG_ENCRYPTION, encr_mode); | ||
247 | ar9170_regwrite(AR9170_MAC_REG_SNIFFER, sniffer); | ||
248 | ar9170_regwrite_finish(); | ||
249 | |||
250 | return ar9170_regwrite_result(); | ||
251 | } | ||
252 | |||
253 | int ar9170_set_operating_mode(struct ar9170 *ar) | ||
254 | { | ||
255 | u32 pm_mode = AR9170_MAC_REG_POWERMGT_DEFAULTS; | ||
256 | u8 *mac_addr, *bssid; | ||
257 | int err; | ||
258 | |||
259 | if (ar->vif) { | ||
260 | mac_addr = ar->mac_addr; | ||
261 | bssid = ar->bssid; | ||
262 | |||
263 | switch (ar->vif->type) { | ||
264 | case NL80211_IFTYPE_MESH_POINT: | ||
265 | case NL80211_IFTYPE_ADHOC: | ||
266 | pm_mode |= AR9170_MAC_REG_POWERMGT_IBSS; | ||
267 | break; | ||
268 | /* case NL80211_IFTYPE_AP: | ||
269 | pm_mode |= AR9170_MAC_REG_POWERMGT_AP; | ||
270 | break;*/ | ||
271 | case NL80211_IFTYPE_WDS: | ||
272 | pm_mode |= AR9170_MAC_REG_POWERMGT_AP_WDS; | ||
273 | break; | ||
274 | case NL80211_IFTYPE_MONITOR: | ||
275 | ar->sniffer_enabled = true; | ||
276 | ar->rx_software_decryption = true; | ||
277 | break; | ||
278 | default: | ||
279 | pm_mode |= AR9170_MAC_REG_POWERMGT_STA; | ||
280 | break; | ||
281 | } | ||
282 | } else { | ||
283 | mac_addr = NULL; | ||
284 | bssid = NULL; | ||
285 | } | ||
286 | |||
287 | err = ar9170_set_mac_reg(ar, AR9170_MAC_REG_MAC_ADDR_L, mac_addr); | ||
288 | if (err) | ||
289 | return err; | ||
290 | |||
291 | err = ar9170_set_mac_reg(ar, AR9170_MAC_REG_BSSID_L, bssid); | ||
292 | if (err) | ||
293 | return err; | ||
294 | |||
295 | err = ar9170_set_promiscouous(ar); | ||
296 | if (err) | ||
297 | return err; | ||
298 | |||
299 | ar9170_regwrite_begin(ar); | ||
300 | |||
301 | ar9170_regwrite(AR9170_MAC_REG_POWERMANAGEMENT, pm_mode); | ||
302 | ar9170_regwrite_finish(); | ||
303 | |||
304 | return ar9170_regwrite_result(); | ||
305 | } | ||
306 | |||
307 | int ar9170_set_hwretry_limit(struct ar9170 *ar, unsigned int max_retry) | ||
308 | { | ||
309 | u32 tmp = min_t(u32, 0x33333, max_retry * 0x11111); | ||
310 | |||
311 | return ar9170_write_reg(ar, AR9170_MAC_REG_RETRY_MAX, tmp); | ||
312 | } | ||
313 | |||
314 | int ar9170_set_beacon_timers(struct ar9170 *ar) | ||
315 | { | ||
316 | u32 v = 0; | ||
317 | u32 pretbtt = 0; | ||
318 | |||
319 | v |= ar->hw->conf.beacon_int; | ||
320 | |||
321 | if (ar->vif) { | ||
322 | switch (ar->vif->type) { | ||
323 | case NL80211_IFTYPE_MESH_POINT: | ||
324 | case NL80211_IFTYPE_ADHOC: | ||
325 | v |= BIT(25); | ||
326 | break; | ||
327 | case NL80211_IFTYPE_AP: | ||
328 | v |= BIT(24); | ||
329 | pretbtt = (ar->hw->conf.beacon_int - 6) << 16; | ||
330 | break; | ||
331 | default: | ||
332 | break; | ||
333 | } | ||
334 | |||
335 | v |= ar->vif->bss_conf.dtim_period << 16; | ||
336 | } | ||
337 | |||
338 | ar9170_regwrite_begin(ar); | ||
339 | |||
340 | ar9170_regwrite(AR9170_MAC_REG_PRETBTT, pretbtt); | ||
341 | ar9170_regwrite(AR9170_MAC_REG_BCN_PERIOD, v); | ||
342 | ar9170_regwrite_finish(); | ||
343 | return ar9170_regwrite_result(); | ||
344 | } | ||
345 | |||
346 | int ar9170_update_beacon(struct ar9170 *ar) | ||
347 | { | ||
348 | struct sk_buff *skb; | ||
349 | __le32 *data, *old = NULL; | ||
350 | u32 word; | ||
351 | int i; | ||
352 | |||
353 | skb = ieee80211_beacon_get(ar->hw, ar->vif); | ||
354 | if (!skb) | ||
355 | return -ENOMEM; | ||
356 | |||
357 | data = (__le32 *)skb->data; | ||
358 | if (ar->beacon) | ||
359 | old = (__le32 *)ar->beacon->data; | ||
360 | |||
361 | ar9170_regwrite_begin(ar); | ||
362 | for (i = 0; i < DIV_ROUND_UP(skb->len, 4); i++) { | ||
363 | /* | ||
364 | * XXX: This accesses beyond skb data for up | ||
365 | * to the last 3 bytes!! | ||
366 | */ | ||
367 | |||
368 | if (old && (data[i] == old[i])) | ||
369 | continue; | ||
370 | |||
371 | word = le32_to_cpu(data[i]); | ||
372 | ar9170_regwrite(AR9170_BEACON_BUFFER_ADDRESS + 4 * i, word); | ||
373 | } | ||
374 | |||
375 | /* XXX: use skb->cb info */ | ||
376 | if (ar->hw->conf.channel->band == IEEE80211_BAND_2GHZ) | ||
377 | ar9170_regwrite(AR9170_MAC_REG_BCN_PLCP, | ||
378 | ((skb->len + 4) << (3+16)) + 0x0400); | ||
379 | else | ||
380 | ar9170_regwrite(AR9170_MAC_REG_BCN_PLCP, | ||
381 | ((skb->len + 4) << (3+16)) + 0x0400); | ||
382 | |||
383 | ar9170_regwrite(AR9170_MAC_REG_BCN_LENGTH, skb->len + 4); | ||
384 | ar9170_regwrite(AR9170_MAC_REG_BCN_ADDR, AR9170_BEACON_BUFFER_ADDRESS); | ||
385 | ar9170_regwrite(AR9170_MAC_REG_BCN_CTRL, 1); | ||
386 | |||
387 | ar9170_regwrite_finish(); | ||
388 | |||
389 | dev_kfree_skb(ar->beacon); | ||
390 | ar->beacon = skb; | ||
391 | |||
392 | return ar9170_regwrite_result(); | ||
393 | } | ||
394 | |||
395 | void ar9170_new_beacon(struct work_struct *work) | ||
396 | { | ||
397 | struct ar9170 *ar = container_of(work, struct ar9170, | ||
398 | beacon_work); | ||
399 | struct sk_buff *skb; | ||
400 | |||
401 | if (unlikely(!IS_STARTED(ar))) | ||
402 | return ; | ||
403 | |||
404 | mutex_lock(&ar->mutex); | ||
405 | |||
406 | if (!ar->vif) | ||
407 | goto out; | ||
408 | |||
409 | ar9170_update_beacon(ar); | ||
410 | |||
411 | rcu_read_lock(); | ||
412 | while ((skb = ieee80211_get_buffered_bc(ar->hw, ar->vif))) | ||
413 | ar9170_op_tx(ar->hw, skb); | ||
414 | |||
415 | rcu_read_unlock(); | ||
416 | |||
417 | out: | ||
418 | mutex_unlock(&ar->mutex); | ||
419 | } | ||
420 | |||
421 | int ar9170_upload_key(struct ar9170 *ar, u8 id, const u8 *mac, u8 ktype, | ||
422 | u8 keyidx, u8 *keydata, int keylen) | ||
423 | { | ||
424 | __le32 vals[7]; | ||
425 | static const u8 bcast[ETH_ALEN] = | ||
426 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | ||
427 | u8 dummy; | ||
428 | |||
429 | mac = mac ? : bcast; | ||
430 | |||
431 | vals[0] = cpu_to_le32((keyidx << 16) + id); | ||
432 | vals[1] = cpu_to_le32(mac[1] << 24 | mac[0] << 16 | ktype); | ||
433 | vals[2] = cpu_to_le32(mac[5] << 24 | mac[4] << 16 | | ||
434 | mac[3] << 8 | mac[2]); | ||
435 | memset(&vals[3], 0, 16); | ||
436 | if (keydata) | ||
437 | memcpy(&vals[3], keydata, keylen); | ||
438 | |||
439 | return ar->exec_cmd(ar, AR9170_CMD_EKEY, | ||
440 | sizeof(vals), (u8 *)vals, | ||
441 | 1, &dummy); | ||
442 | } | ||
443 | |||
444 | int ar9170_disable_key(struct ar9170 *ar, u8 id) | ||
445 | { | ||
446 | __le32 val = cpu_to_le32(id); | ||
447 | u8 dummy; | ||
448 | |||
449 | return ar->exec_cmd(ar, AR9170_CMD_EKEY, | ||
450 | sizeof(val), (u8 *)&val, | ||
451 | 1, &dummy); | ||
452 | } | ||
diff --git a/drivers/net/wireless/ar9170/main.c b/drivers/net/wireless/ar9170/main.c new file mode 100644 index 000000000000..5996ff9f7f47 --- /dev/null +++ b/drivers/net/wireless/ar9170/main.c | |||
@@ -0,0 +1,1671 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * mac80211 interaction code | ||
5 | * | ||
6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> | ||
7 | * Copyright 2009, Christian Lamparter <chunkeey@web.de> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; see the file COPYING. If not, see | ||
21 | * http://www.gnu.org/licenses/. | ||
22 | * | ||
23 | * This file incorporates work covered by the following copyright and | ||
24 | * permission notice: | ||
25 | * Copyright (c) 2007-2008 Atheros Communications, Inc. | ||
26 | * | ||
27 | * Permission to use, copy, modify, and/or distribute this software for any | ||
28 | * purpose with or without fee is hereby granted, provided that the above | ||
29 | * copyright notice and this permission notice appear in all copies. | ||
30 | * | ||
31 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
32 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
33 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
34 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
35 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
36 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
37 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
38 | */ | ||
39 | |||
40 | #include <linux/init.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <linux/etherdevice.h> | ||
43 | #include <net/mac80211.h> | ||
44 | #include "ar9170.h" | ||
45 | #include "hw.h" | ||
46 | #include "cmd.h" | ||
47 | |||
48 | static int modparam_nohwcrypt; | ||
49 | module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); | ||
50 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); | ||
51 | |||
52 | #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \ | ||
53 | .bitrate = (_bitrate), \ | ||
54 | .flags = (_flags), \ | ||
55 | .hw_value = (_hw_rate) | (_txpidx) << 4, \ | ||
56 | } | ||
57 | |||
58 | static struct ieee80211_rate __ar9170_ratetable[] = { | ||
59 | RATE(10, 0, 0, 0), | ||
60 | RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE), | ||
61 | RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE), | ||
62 | RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE), | ||
63 | RATE(60, 0xb, 0, 0), | ||
64 | RATE(90, 0xf, 0, 0), | ||
65 | RATE(120, 0xa, 0, 0), | ||
66 | RATE(180, 0xe, 0, 0), | ||
67 | RATE(240, 0x9, 0, 0), | ||
68 | RATE(360, 0xd, 1, 0), | ||
69 | RATE(480, 0x8, 2, 0), | ||
70 | RATE(540, 0xc, 3, 0), | ||
71 | }; | ||
72 | #undef RATE | ||
73 | |||
74 | #define ar9170_g_ratetable (__ar9170_ratetable + 0) | ||
75 | #define ar9170_g_ratetable_size 12 | ||
76 | #define ar9170_a_ratetable (__ar9170_ratetable + 4) | ||
77 | #define ar9170_a_ratetable_size 8 | ||
78 | |||
79 | /* | ||
80 | * NB: The hw_value is used as an index into the ar9170_phy_freq_params | ||
81 | * array in phy.c so that we don't have to do frequency lookups! | ||
82 | */ | ||
83 | #define CHAN(_freq, _idx) { \ | ||
84 | .center_freq = (_freq), \ | ||
85 | .hw_value = (_idx), \ | ||
86 | .max_power = 18, /* XXX */ \ | ||
87 | } | ||
88 | |||
89 | static struct ieee80211_channel ar9170_2ghz_chantable[] = { | ||
90 | CHAN(2412, 0), | ||
91 | CHAN(2417, 1), | ||
92 | CHAN(2422, 2), | ||
93 | CHAN(2427, 3), | ||
94 | CHAN(2432, 4), | ||
95 | CHAN(2437, 5), | ||
96 | CHAN(2442, 6), | ||
97 | CHAN(2447, 7), | ||
98 | CHAN(2452, 8), | ||
99 | CHAN(2457, 9), | ||
100 | CHAN(2462, 10), | ||
101 | CHAN(2467, 11), | ||
102 | CHAN(2472, 12), | ||
103 | CHAN(2484, 13), | ||
104 | }; | ||
105 | |||
106 | static struct ieee80211_channel ar9170_5ghz_chantable[] = { | ||
107 | CHAN(4920, 14), | ||
108 | CHAN(4940, 15), | ||
109 | CHAN(4960, 16), | ||
110 | CHAN(4980, 17), | ||
111 | CHAN(5040, 18), | ||
112 | CHAN(5060, 19), | ||
113 | CHAN(5080, 20), | ||
114 | CHAN(5180, 21), | ||
115 | CHAN(5200, 22), | ||
116 | CHAN(5220, 23), | ||
117 | CHAN(5240, 24), | ||
118 | CHAN(5260, 25), | ||
119 | CHAN(5280, 26), | ||
120 | CHAN(5300, 27), | ||
121 | CHAN(5320, 28), | ||
122 | CHAN(5500, 29), | ||
123 | CHAN(5520, 30), | ||
124 | CHAN(5540, 31), | ||
125 | CHAN(5560, 32), | ||
126 | CHAN(5580, 33), | ||
127 | CHAN(5600, 34), | ||
128 | CHAN(5620, 35), | ||
129 | CHAN(5640, 36), | ||
130 | CHAN(5660, 37), | ||
131 | CHAN(5680, 38), | ||
132 | CHAN(5700, 39), | ||
133 | CHAN(5745, 40), | ||
134 | CHAN(5765, 41), | ||
135 | CHAN(5785, 42), | ||
136 | CHAN(5805, 43), | ||
137 | CHAN(5825, 44), | ||
138 | CHAN(5170, 45), | ||
139 | CHAN(5190, 46), | ||
140 | CHAN(5210, 47), | ||
141 | CHAN(5230, 48), | ||
142 | }; | ||
143 | #undef CHAN | ||
144 | |||
145 | static struct ieee80211_supported_band ar9170_band_2GHz = { | ||
146 | .channels = ar9170_2ghz_chantable, | ||
147 | .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable), | ||
148 | .bitrates = ar9170_g_ratetable, | ||
149 | .n_bitrates = ar9170_g_ratetable_size, | ||
150 | }; | ||
151 | |||
152 | #ifdef AR9170_QUEUE_DEBUG | ||
153 | /* | ||
154 | * In case some wants works with AR9170's crazy tx_status queueing techniques. | ||
155 | * He might need this rather useful probing function. | ||
156 | * | ||
157 | * NOTE: caller must hold the queue's spinlock! | ||
158 | */ | ||
159 | |||
160 | static void ar9170_print_txheader(struct ar9170 *ar, struct sk_buff *skb) | ||
161 | { | ||
162 | struct ar9170_tx_control *txc = (void *) skb->data; | ||
163 | struct ieee80211_hdr *hdr = (void *)txc->frame_data; | ||
164 | |||
165 | printk(KERN_DEBUG "%s: => FRAME [skb:%p, queue:%d, DA:[%pM] " | ||
166 | "mac_control:%04x, phy_control:%08x]\n", | ||
167 | wiphy_name(ar->hw->wiphy), skb, skb_get_queue_mapping(skb), | ||
168 | ieee80211_get_DA(hdr), le16_to_cpu(txc->mac_control), | ||
169 | le32_to_cpu(txc->phy_control)); | ||
170 | } | ||
171 | |||
172 | static void ar9170_dump_station_tx_status_queue(struct ar9170 *ar, | ||
173 | struct sk_buff_head *queue) | ||
174 | { | ||
175 | struct sk_buff *skb; | ||
176 | int i = 0; | ||
177 | |||
178 | printk(KERN_DEBUG "---[ cut here ]---\n"); | ||
179 | printk(KERN_DEBUG "%s: %d entries in tx_status queue.\n", | ||
180 | wiphy_name(ar->hw->wiphy), skb_queue_len(queue)); | ||
181 | |||
182 | skb_queue_walk(queue, skb) { | ||
183 | struct ar9170_tx_control *txc = (void *) skb->data; | ||
184 | struct ieee80211_hdr *hdr = (void *)txc->frame_data; | ||
185 | |||
186 | printk(KERN_DEBUG "index:%d => \n", i); | ||
187 | ar9170_print_txheader(ar, skb); | ||
188 | } | ||
189 | printk(KERN_DEBUG "---[ end ]---\n"); | ||
190 | } | ||
191 | #endif /* AR9170_QUEUE_DEBUG */ | ||
192 | |||
193 | static struct ieee80211_supported_band ar9170_band_5GHz = { | ||
194 | .channels = ar9170_5ghz_chantable, | ||
195 | .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable), | ||
196 | .bitrates = ar9170_a_ratetable, | ||
197 | .n_bitrates = ar9170_a_ratetable_size, | ||
198 | }; | ||
199 | |||
200 | void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb, | ||
201 | bool valid_status, u16 tx_status) | ||
202 | { | ||
203 | struct ieee80211_tx_info *txinfo; | ||
204 | unsigned int retries = 0, queue = skb_get_queue_mapping(skb); | ||
205 | unsigned long flags; | ||
206 | |||
207 | spin_lock_irqsave(&ar->tx_stats_lock, flags); | ||
208 | ar->tx_stats[queue].len--; | ||
209 | if (ieee80211_queue_stopped(ar->hw, queue)) | ||
210 | ieee80211_wake_queue(ar->hw, queue); | ||
211 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | ||
212 | |||
213 | txinfo = IEEE80211_SKB_CB(skb); | ||
214 | ieee80211_tx_info_clear_status(txinfo); | ||
215 | |||
216 | switch (tx_status) { | ||
217 | case AR9170_TX_STATUS_RETRY: | ||
218 | retries = 2; | ||
219 | case AR9170_TX_STATUS_COMPLETE: | ||
220 | txinfo->flags |= IEEE80211_TX_STAT_ACK; | ||
221 | break; | ||
222 | |||
223 | case AR9170_TX_STATUS_FAILED: | ||
224 | retries = ar->hw->conf.long_frame_max_tx_count; | ||
225 | break; | ||
226 | |||
227 | default: | ||
228 | printk(KERN_ERR "%s: invalid tx_status response (%x).\n", | ||
229 | wiphy_name(ar->hw->wiphy), tx_status); | ||
230 | break; | ||
231 | } | ||
232 | |||
233 | if (valid_status) | ||
234 | txinfo->status.rates[0].count = retries + 1; | ||
235 | |||
236 | skb_pull(skb, sizeof(struct ar9170_tx_control)); | ||
237 | ieee80211_tx_status_irqsafe(ar->hw, skb); | ||
238 | } | ||
239 | |||
240 | static struct sk_buff *ar9170_find_skb_in_queue(struct ar9170 *ar, | ||
241 | const u8 *mac, | ||
242 | const u32 queue, | ||
243 | struct sk_buff_head *q) | ||
244 | { | ||
245 | unsigned long flags; | ||
246 | struct sk_buff *skb; | ||
247 | |||
248 | spin_lock_irqsave(&q->lock, flags); | ||
249 | skb_queue_walk(q, skb) { | ||
250 | struct ar9170_tx_control *txc = (void *) skb->data; | ||
251 | struct ieee80211_hdr *hdr = (void *) txc->frame_data; | ||
252 | u32 txc_queue = (le32_to_cpu(txc->phy_control) & | ||
253 | AR9170_TX_PHY_QOS_MASK) >> | ||
254 | AR9170_TX_PHY_QOS_SHIFT; | ||
255 | |||
256 | if ((queue != txc_queue) || | ||
257 | (compare_ether_addr(ieee80211_get_DA(hdr), mac))) | ||
258 | continue; | ||
259 | |||
260 | __skb_unlink(skb, q); | ||
261 | spin_unlock_irqrestore(&q->lock, flags); | ||
262 | return skb; | ||
263 | } | ||
264 | spin_unlock_irqrestore(&q->lock, flags); | ||
265 | return NULL; | ||
266 | } | ||
267 | |||
268 | static struct sk_buff *ar9170_find_queued_skb(struct ar9170 *ar, const u8 *mac, | ||
269 | const u32 queue) | ||
270 | { | ||
271 | struct ieee80211_sta *sta; | ||
272 | struct sk_buff *skb; | ||
273 | |||
274 | /* | ||
275 | * Unfortunately, the firmware does not tell to which (queued) frame | ||
276 | * this transmission status report belongs to. | ||
277 | * | ||
278 | * So we have to make risky guesses - with the scarce information | ||
279 | * the firmware provided (-> destination MAC, and phy_control) - | ||
280 | * and hope that we picked the right one... | ||
281 | */ | ||
282 | rcu_read_lock(); | ||
283 | sta = ieee80211_find_sta(ar->hw, mac); | ||
284 | |||
285 | if (likely(sta)) { | ||
286 | struct ar9170_sta_info *sta_priv = (void *) sta->drv_priv; | ||
287 | skb = skb_dequeue(&sta_priv->tx_status[queue]); | ||
288 | rcu_read_unlock(); | ||
289 | if (likely(skb)) | ||
290 | return skb; | ||
291 | } else | ||
292 | rcu_read_unlock(); | ||
293 | |||
294 | /* scan the waste queue for candidates */ | ||
295 | skb = ar9170_find_skb_in_queue(ar, mac, queue, | ||
296 | &ar->global_tx_status_waste); | ||
297 | if (!skb) { | ||
298 | /* so it still _must_ be in the global list. */ | ||
299 | skb = ar9170_find_skb_in_queue(ar, mac, queue, | ||
300 | &ar->global_tx_status); | ||
301 | } | ||
302 | |||
303 | #ifdef AR9170_QUEUE_DEBUG | ||
304 | if (unlikely((!skb) && net_ratelimit())) { | ||
305 | printk(KERN_ERR "%s: ESS:[%pM] does not have any " | ||
306 | "outstanding frames in this queue (%d).\n", | ||
307 | wiphy_name(ar->hw->wiphy), mac, queue); | ||
308 | } | ||
309 | #endif /* AR9170_QUEUE_DEBUG */ | ||
310 | return skb; | ||
311 | } | ||
312 | |||
313 | /* | ||
314 | * This worker tries to keep the global tx_status queue empty. | ||
315 | * So we can guarantee that incoming tx_status reports for | ||
316 | * unregistered stations are always synced with the actual | ||
317 | * frame - which we think - belongs to. | ||
318 | */ | ||
319 | |||
320 | static void ar9170_tx_status_janitor(struct work_struct *work) | ||
321 | { | ||
322 | struct ar9170 *ar = container_of(work, struct ar9170, | ||
323 | tx_status_janitor.work); | ||
324 | struct sk_buff *skb; | ||
325 | |||
326 | if (unlikely(!IS_STARTED(ar))) | ||
327 | return ; | ||
328 | |||
329 | mutex_lock(&ar->mutex); | ||
330 | /* recycle the garbage back to mac80211... one by one. */ | ||
331 | while ((skb = skb_dequeue(&ar->global_tx_status_waste))) { | ||
332 | #ifdef AR9170_QUEUE_DEBUG | ||
333 | printk(KERN_DEBUG "%s: dispose queued frame =>\n", | ||
334 | wiphy_name(ar->hw->wiphy)); | ||
335 | ar9170_print_txheader(ar, skb); | ||
336 | #endif /* AR9170_QUEUE_DEBUG */ | ||
337 | ar9170_handle_tx_status(ar, skb, false, | ||
338 | AR9170_TX_STATUS_FAILED); | ||
339 | } | ||
340 | |||
341 | while ((skb = skb_dequeue(&ar->global_tx_status))) { | ||
342 | #ifdef AR9170_QUEUE_DEBUG | ||
343 | printk(KERN_DEBUG "%s: moving frame into waste queue =>\n", | ||
344 | wiphy_name(ar->hw->wiphy)); | ||
345 | |||
346 | ar9170_print_txheader(ar, skb); | ||
347 | #endif /* AR9170_QUEUE_DEBUG */ | ||
348 | skb_queue_tail(&ar->global_tx_status_waste, skb); | ||
349 | } | ||
350 | |||
351 | /* recall the janitor in 100ms - if there's garbage in the can. */ | ||
352 | if (skb_queue_len(&ar->global_tx_status_waste) > 0) | ||
353 | queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor, | ||
354 | msecs_to_jiffies(100)); | ||
355 | |||
356 | mutex_unlock(&ar->mutex); | ||
357 | } | ||
358 | |||
359 | static void ar9170_handle_command_response(struct ar9170 *ar, | ||
360 | void *buf, u32 len) | ||
361 | { | ||
362 | struct ar9170_cmd_response *cmd = (void *) buf; | ||
363 | |||
364 | if ((cmd->type & 0xc0) != 0xc0) { | ||
365 | ar->callback_cmd(ar, len, buf); | ||
366 | return; | ||
367 | } | ||
368 | |||
369 | /* hardware event handlers */ | ||
370 | switch (cmd->type) { | ||
371 | case 0xc1: { | ||
372 | /* | ||
373 | * TX status notification: | ||
374 | * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1 | ||
375 | * | ||
376 | * XX always 81 | ||
377 | * YY always 00 | ||
378 | * M1-M6 is the MAC address | ||
379 | * R1-R4 is the transmit rate | ||
380 | * S1-S2 is the transmit status | ||
381 | */ | ||
382 | |||
383 | struct sk_buff *skb; | ||
384 | u32 queue = (le32_to_cpu(cmd->tx_status.rate) & | ||
385 | AR9170_TX_PHY_QOS_MASK) >> AR9170_TX_PHY_QOS_SHIFT; | ||
386 | |||
387 | skb = ar9170_find_queued_skb(ar, cmd->tx_status.dst, queue); | ||
388 | if (unlikely(!skb)) | ||
389 | return ; | ||
390 | |||
391 | ar9170_handle_tx_status(ar, skb, true, | ||
392 | le16_to_cpu(cmd->tx_status.status)); | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | case 0xc0: | ||
397 | /* | ||
398 | * pre-TBTT event | ||
399 | */ | ||
400 | if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP) | ||
401 | queue_work(ar->hw->workqueue, &ar->beacon_work); | ||
402 | break; | ||
403 | |||
404 | case 0xc2: | ||
405 | /* | ||
406 | * (IBSS) beacon send notification | ||
407 | * bytes: 04 c2 XX YY B4 B3 B2 B1 | ||
408 | * | ||
409 | * XX always 80 | ||
410 | * YY always 00 | ||
411 | * B1-B4 "should" be the number of send out beacons. | ||
412 | */ | ||
413 | break; | ||
414 | |||
415 | case 0xc3: | ||
416 | /* End of Atim Window */ | ||
417 | break; | ||
418 | |||
419 | case 0xc4: | ||
420 | case 0xc5: | ||
421 | /* BlockACK events */ | ||
422 | break; | ||
423 | |||
424 | case 0xc6: | ||
425 | /* Watchdog Interrupt */ | ||
426 | break; | ||
427 | |||
428 | case 0xc9: | ||
429 | /* retransmission issue / SIFS/EIFS collision ?! */ | ||
430 | break; | ||
431 | |||
432 | default: | ||
433 | printk(KERN_INFO "received unhandled event %x\n", cmd->type); | ||
434 | print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len); | ||
435 | break; | ||
436 | } | ||
437 | } | ||
438 | |||
439 | /* | ||
440 | * If the frame alignment is right (or the kernel has | ||
441 | * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there | ||
442 | * is only a single MPDU in the USB frame, then we can | ||
443 | * submit to mac80211 the SKB directly. However, since | ||
444 | * there may be multiple packets in one SKB in stream | ||
445 | * mode, and we need to observe the proper ordering, | ||
446 | * this is non-trivial. | ||
447 | */ | ||
448 | static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len) | ||
449 | { | ||
450 | struct sk_buff *skb; | ||
451 | struct ar9170_rx_head *head = (void *)buf; | ||
452 | struct ar9170_rx_tail *tail; | ||
453 | struct ieee80211_rx_status status; | ||
454 | int mpdu_len, i; | ||
455 | u8 error, antennas = 0, decrypt; | ||
456 | __le16 fc; | ||
457 | int reserved; | ||
458 | |||
459 | if (unlikely(!IS_STARTED(ar))) | ||
460 | return ; | ||
461 | |||
462 | /* Received MPDU */ | ||
463 | mpdu_len = len; | ||
464 | mpdu_len -= sizeof(struct ar9170_rx_head); | ||
465 | mpdu_len -= sizeof(struct ar9170_rx_tail); | ||
466 | BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12); | ||
467 | BUILD_BUG_ON(sizeof(struct ar9170_rx_tail) != 24); | ||
468 | |||
469 | if (mpdu_len <= FCS_LEN) | ||
470 | return; | ||
471 | |||
472 | tail = (void *)(buf + sizeof(struct ar9170_rx_head) + mpdu_len); | ||
473 | |||
474 | for (i = 0; i < 3; i++) | ||
475 | if (tail->rssi[i] != 0x80) | ||
476 | antennas |= BIT(i); | ||
477 | |||
478 | /* post-process RSSI */ | ||
479 | for (i = 0; i < 7; i++) | ||
480 | if (tail->rssi[i] & 0x80) | ||
481 | tail->rssi[i] = ((tail->rssi[i] & 0x7f) + 1) & 0x7f; | ||
482 | |||
483 | memset(&status, 0, sizeof(status)); | ||
484 | |||
485 | status.band = ar->channel->band; | ||
486 | status.freq = ar->channel->center_freq; | ||
487 | status.signal = ar->noise[0] + tail->rssi_combined; | ||
488 | status.noise = ar->noise[0]; | ||
489 | status.antenna = antennas; | ||
490 | |||
491 | switch (tail->status & AR9170_RX_STATUS_MODULATION_MASK) { | ||
492 | case AR9170_RX_STATUS_MODULATION_CCK: | ||
493 | if (tail->status & AR9170_RX_STATUS_SHORT_PREAMBLE) | ||
494 | status.flag |= RX_FLAG_SHORTPRE; | ||
495 | switch (head->plcp[0]) { | ||
496 | case 0x0a: | ||
497 | status.rate_idx = 0; | ||
498 | break; | ||
499 | case 0x14: | ||
500 | status.rate_idx = 1; | ||
501 | break; | ||
502 | case 0x37: | ||
503 | status.rate_idx = 2; | ||
504 | break; | ||
505 | case 0x6e: | ||
506 | status.rate_idx = 3; | ||
507 | break; | ||
508 | default: | ||
509 | if ((!ar->sniffer_enabled) && (net_ratelimit())) | ||
510 | printk(KERN_ERR "%s: invalid plcp cck rate " | ||
511 | "(%x).\n", wiphy_name(ar->hw->wiphy), | ||
512 | head->plcp[0]); | ||
513 | return; | ||
514 | } | ||
515 | break; | ||
516 | case AR9170_RX_STATUS_MODULATION_OFDM: | ||
517 | switch (head->plcp[0] & 0xF) { | ||
518 | case 0xB: | ||
519 | status.rate_idx = 0; | ||
520 | break; | ||
521 | case 0xF: | ||
522 | status.rate_idx = 1; | ||
523 | break; | ||
524 | case 0xA: | ||
525 | status.rate_idx = 2; | ||
526 | break; | ||
527 | case 0xE: | ||
528 | status.rate_idx = 3; | ||
529 | break; | ||
530 | case 0x9: | ||
531 | status.rate_idx = 4; | ||
532 | break; | ||
533 | case 0xD: | ||
534 | status.rate_idx = 5; | ||
535 | break; | ||
536 | case 0x8: | ||
537 | status.rate_idx = 6; | ||
538 | break; | ||
539 | case 0xC: | ||
540 | status.rate_idx = 7; | ||
541 | break; | ||
542 | default: | ||
543 | if ((!ar->sniffer_enabled) && (net_ratelimit())) | ||
544 | printk(KERN_ERR "%s: invalid plcp ofdm rate " | ||
545 | "(%x).\n", wiphy_name(ar->hw->wiphy), | ||
546 | head->plcp[0]); | ||
547 | return; | ||
548 | } | ||
549 | if (status.band == IEEE80211_BAND_2GHZ) | ||
550 | status.rate_idx += 4; | ||
551 | break; | ||
552 | case AR9170_RX_STATUS_MODULATION_HT: | ||
553 | case AR9170_RX_STATUS_MODULATION_DUPOFDM: | ||
554 | /* XXX */ | ||
555 | |||
556 | if (net_ratelimit()) | ||
557 | printk(KERN_ERR "%s: invalid modulation\n", | ||
558 | wiphy_name(ar->hw->wiphy)); | ||
559 | return; | ||
560 | } | ||
561 | |||
562 | error = tail->error; | ||
563 | |||
564 | if (error & AR9170_RX_ERROR_MMIC) { | ||
565 | status.flag |= RX_FLAG_MMIC_ERROR; | ||
566 | error &= ~AR9170_RX_ERROR_MMIC; | ||
567 | } | ||
568 | |||
569 | if (error & AR9170_RX_ERROR_PLCP) { | ||
570 | status.flag |= RX_FLAG_FAILED_PLCP_CRC; | ||
571 | error &= ~AR9170_RX_ERROR_PLCP; | ||
572 | } | ||
573 | |||
574 | if (error & AR9170_RX_ERROR_FCS) { | ||
575 | status.flag |= RX_FLAG_FAILED_FCS_CRC; | ||
576 | error &= ~AR9170_RX_ERROR_FCS; | ||
577 | } | ||
578 | |||
579 | decrypt = ar9170_get_decrypt_type(tail); | ||
580 | if (!(decrypt & AR9170_RX_ENC_SOFTWARE) && | ||
581 | decrypt != AR9170_ENC_ALG_NONE) | ||
582 | status.flag |= RX_FLAG_DECRYPTED; | ||
583 | |||
584 | /* ignore wrong RA errors */ | ||
585 | error &= ~AR9170_RX_ERROR_WRONG_RA; | ||
586 | |||
587 | if (error & AR9170_RX_ERROR_DECRYPT) { | ||
588 | error &= ~AR9170_RX_ERROR_DECRYPT; | ||
589 | |||
590 | /* | ||
591 | * Rx decryption is done in place, | ||
592 | * the original data is lost anyway. | ||
593 | */ | ||
594 | return ; | ||
595 | } | ||
596 | |||
597 | /* drop any other error frames */ | ||
598 | if ((error) && (net_ratelimit())) { | ||
599 | printk(KERN_DEBUG "%s: errors: %#x\n", | ||
600 | wiphy_name(ar->hw->wiphy), error); | ||
601 | return; | ||
602 | } | ||
603 | |||
604 | buf += sizeof(struct ar9170_rx_head); | ||
605 | fc = *(__le16 *)buf; | ||
606 | |||
607 | if (ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc)) | ||
608 | reserved = 32 + 2; | ||
609 | else | ||
610 | reserved = 32; | ||
611 | |||
612 | skb = dev_alloc_skb(mpdu_len + reserved); | ||
613 | if (!skb) | ||
614 | return; | ||
615 | |||
616 | skb_reserve(skb, reserved); | ||
617 | memcpy(skb_put(skb, mpdu_len), buf, mpdu_len); | ||
618 | ieee80211_rx_irqsafe(ar->hw, skb, &status); | ||
619 | } | ||
620 | |||
621 | void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb) | ||
622 | { | ||
623 | unsigned int i, tlen, resplen; | ||
624 | u8 *tbuf, *respbuf; | ||
625 | |||
626 | tbuf = skb->data; | ||
627 | tlen = skb->len; | ||
628 | |||
629 | while (tlen >= 4) { | ||
630 | int clen = tbuf[1] << 8 | tbuf[0]; | ||
631 | int wlen = (clen + 3) & ~3; | ||
632 | |||
633 | /* | ||
634 | * parse stream (if any) | ||
635 | */ | ||
636 | if (tbuf[2] != 0 || tbuf[3] != 0x4e) { | ||
637 | printk(KERN_ERR "%s: missing tag!\n", | ||
638 | wiphy_name(ar->hw->wiphy)); | ||
639 | return ; | ||
640 | } | ||
641 | if (wlen > tlen - 4) { | ||
642 | printk(KERN_ERR "%s: invalid RX (%d, %d, %d)\n", | ||
643 | wiphy_name(ar->hw->wiphy), clen, wlen, tlen); | ||
644 | print_hex_dump(KERN_DEBUG, "data: ", | ||
645 | DUMP_PREFIX_OFFSET, | ||
646 | 16, 1, tbuf, tlen, true); | ||
647 | return ; | ||
648 | } | ||
649 | resplen = clen; | ||
650 | respbuf = tbuf + 4; | ||
651 | tbuf += wlen + 4; | ||
652 | tlen -= wlen + 4; | ||
653 | |||
654 | i = 0; | ||
655 | |||
656 | /* weird thing, but this is the same in the original driver */ | ||
657 | while (resplen > 2 && i < 12 && | ||
658 | respbuf[0] == 0xff && respbuf[1] == 0xff) { | ||
659 | i += 2; | ||
660 | resplen -= 2; | ||
661 | respbuf += 2; | ||
662 | } | ||
663 | |||
664 | if (resplen < 4) | ||
665 | continue; | ||
666 | |||
667 | /* found the 6 * 0xffff marker? */ | ||
668 | if (i == 12) | ||
669 | ar9170_handle_command_response(ar, respbuf, resplen); | ||
670 | else | ||
671 | ar9170_handle_mpdu(ar, respbuf, resplen); | ||
672 | } | ||
673 | |||
674 | if (tlen) | ||
675 | printk(KERN_ERR "%s: buffer remains!\n", | ||
676 | wiphy_name(ar->hw->wiphy)); | ||
677 | } | ||
678 | |||
679 | #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \ | ||
680 | do { \ | ||
681 | queue.aifs = ai_fs; \ | ||
682 | queue.cw_min = cwmin; \ | ||
683 | queue.cw_max = cwmax; \ | ||
684 | queue.txop = _txop; \ | ||
685 | } while (0) | ||
686 | |||
687 | static int ar9170_op_start(struct ieee80211_hw *hw) | ||
688 | { | ||
689 | struct ar9170 *ar = hw->priv; | ||
690 | int err, i; | ||
691 | |||
692 | mutex_lock(&ar->mutex); | ||
693 | |||
694 | /* reinitialize queues statistics */ | ||
695 | memset(&ar->tx_stats, 0, sizeof(ar->tx_stats)); | ||
696 | for (i = 0; i < ARRAY_SIZE(ar->tx_stats); i++) | ||
697 | ar->tx_stats[i].limit = 8; | ||
698 | |||
699 | /* reset QoS defaults */ | ||
700 | AR9170_FILL_QUEUE(ar->edcf[0], 3, 15, 1023, 0); /* BEST EFFORT*/ | ||
701 | AR9170_FILL_QUEUE(ar->edcf[1], 7, 15, 1023, 0); /* BACKGROUND */ | ||
702 | AR9170_FILL_QUEUE(ar->edcf[2], 2, 7, 15, 94); /* VIDEO */ | ||
703 | AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */ | ||
704 | AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */ | ||
705 | |||
706 | err = ar->open(ar); | ||
707 | if (err) | ||
708 | goto out; | ||
709 | |||
710 | err = ar9170_init_mac(ar); | ||
711 | if (err) | ||
712 | goto out; | ||
713 | |||
714 | err = ar9170_set_qos(ar); | ||
715 | if (err) | ||
716 | goto out; | ||
717 | |||
718 | err = ar9170_init_phy(ar, IEEE80211_BAND_2GHZ); | ||
719 | if (err) | ||
720 | goto out; | ||
721 | |||
722 | err = ar9170_init_rf(ar); | ||
723 | if (err) | ||
724 | goto out; | ||
725 | |||
726 | /* start DMA */ | ||
727 | err = ar9170_write_reg(ar, 0x1c3d30, 0x100); | ||
728 | if (err) | ||
729 | goto out; | ||
730 | |||
731 | ar->state = AR9170_STARTED; | ||
732 | |||
733 | out: | ||
734 | mutex_unlock(&ar->mutex); | ||
735 | return err; | ||
736 | } | ||
737 | |||
738 | static void ar9170_op_stop(struct ieee80211_hw *hw) | ||
739 | { | ||
740 | struct ar9170 *ar = hw->priv; | ||
741 | |||
742 | if (IS_STARTED(ar)) | ||
743 | ar->state = AR9170_IDLE; | ||
744 | |||
745 | mutex_lock(&ar->mutex); | ||
746 | |||
747 | cancel_delayed_work_sync(&ar->tx_status_janitor); | ||
748 | cancel_work_sync(&ar->filter_config_work); | ||
749 | cancel_work_sync(&ar->beacon_work); | ||
750 | skb_queue_purge(&ar->global_tx_status_waste); | ||
751 | skb_queue_purge(&ar->global_tx_status); | ||
752 | |||
753 | if (IS_ACCEPTING_CMD(ar)) { | ||
754 | ar9170_set_leds_state(ar, 0); | ||
755 | |||
756 | /* stop DMA */ | ||
757 | ar9170_write_reg(ar, 0x1c3d30, 0); | ||
758 | ar->stop(ar); | ||
759 | } | ||
760 | |||
761 | mutex_unlock(&ar->mutex); | ||
762 | } | ||
763 | |||
764 | int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | ||
765 | { | ||
766 | struct ar9170 *ar = hw->priv; | ||
767 | struct ieee80211_hdr *hdr; | ||
768 | struct ar9170_tx_control *txc; | ||
769 | struct ieee80211_tx_info *info; | ||
770 | struct ieee80211_rate *rate = NULL; | ||
771 | struct ieee80211_tx_rate *txrate; | ||
772 | unsigned int queue = skb_get_queue_mapping(skb); | ||
773 | unsigned long flags = 0; | ||
774 | struct ar9170_sta_info *sta_info = NULL; | ||
775 | u32 power, chains; | ||
776 | u16 keytype = 0; | ||
777 | u16 len, icv = 0; | ||
778 | int err; | ||
779 | bool tx_status; | ||
780 | |||
781 | if (unlikely(!IS_STARTED(ar))) | ||
782 | goto err_free; | ||
783 | |||
784 | hdr = (void *)skb->data; | ||
785 | info = IEEE80211_SKB_CB(skb); | ||
786 | len = skb->len; | ||
787 | |||
788 | spin_lock_irqsave(&ar->tx_stats_lock, flags); | ||
789 | if (ar->tx_stats[queue].limit < ar->tx_stats[queue].len) { | ||
790 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | ||
791 | return NETDEV_TX_OK; | ||
792 | } | ||
793 | |||
794 | ar->tx_stats[queue].len++; | ||
795 | ar->tx_stats[queue].count++; | ||
796 | if (ar->tx_stats[queue].limit == ar->tx_stats[queue].len) | ||
797 | ieee80211_stop_queue(hw, queue); | ||
798 | |||
799 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | ||
800 | |||
801 | txc = (void *)skb_push(skb, sizeof(*txc)); | ||
802 | |||
803 | tx_status = (((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) != 0) || | ||
804 | ((info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) != 0)); | ||
805 | |||
806 | if (info->control.hw_key) { | ||
807 | icv = info->control.hw_key->icv_len; | ||
808 | |||
809 | switch (info->control.hw_key->alg) { | ||
810 | case ALG_WEP: | ||
811 | keytype = AR9170_TX_MAC_ENCR_RC4; | ||
812 | break; | ||
813 | case ALG_TKIP: | ||
814 | keytype = AR9170_TX_MAC_ENCR_RC4; | ||
815 | break; | ||
816 | case ALG_CCMP: | ||
817 | keytype = AR9170_TX_MAC_ENCR_AES; | ||
818 | break; | ||
819 | default: | ||
820 | WARN_ON(1); | ||
821 | goto err_dequeue; | ||
822 | } | ||
823 | } | ||
824 | |||
825 | /* Length */ | ||
826 | txc->length = cpu_to_le16(len + icv + 4); | ||
827 | |||
828 | txc->mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION | | ||
829 | AR9170_TX_MAC_BACKOFF); | ||
830 | txc->mac_control |= cpu_to_le16(ar9170_qos_hwmap[queue] << | ||
831 | AR9170_TX_MAC_QOS_SHIFT); | ||
832 | txc->mac_control |= cpu_to_le16(keytype); | ||
833 | txc->phy_control = cpu_to_le32(0); | ||
834 | |||
835 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) | ||
836 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_NO_ACK); | ||
837 | |||
838 | if (info->flags & IEEE80211_TX_CTL_AMPDU) | ||
839 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_AGGR); | ||
840 | |||
841 | txrate = &info->control.rates[0]; | ||
842 | |||
843 | if (txrate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) | ||
844 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS); | ||
845 | else if (txrate->flags & IEEE80211_TX_RC_USE_RTS_CTS) | ||
846 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS); | ||
847 | |||
848 | if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD) | ||
849 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD); | ||
850 | |||
851 | if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | ||
852 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE); | ||
853 | |||
854 | if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | ||
855 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ); | ||
856 | /* this works because 40 MHz is 2 and dup is 3 */ | ||
857 | if (txrate->flags & IEEE80211_TX_RC_DUP_DATA) | ||
858 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP); | ||
859 | |||
860 | if (txrate->flags & IEEE80211_TX_RC_SHORT_GI) | ||
861 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI); | ||
862 | |||
863 | if (txrate->flags & IEEE80211_TX_RC_MCS) { | ||
864 | u32 r = txrate->idx; | ||
865 | u8 *txpower; | ||
866 | |||
867 | r <<= AR9170_TX_PHY_MCS_SHIFT; | ||
868 | if (WARN_ON(r & ~AR9170_TX_PHY_MCS_MASK)) | ||
869 | goto err_dequeue; | ||
870 | txc->phy_control |= cpu_to_le32(r & AR9170_TX_PHY_MCS_MASK); | ||
871 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_MOD_HT); | ||
872 | |||
873 | if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) { | ||
874 | if (info->band == IEEE80211_BAND_5GHZ) | ||
875 | txpower = ar->power_5G_ht40; | ||
876 | else | ||
877 | txpower = ar->power_2G_ht40; | ||
878 | } else { | ||
879 | if (info->band == IEEE80211_BAND_5GHZ) | ||
880 | txpower = ar->power_5G_ht20; | ||
881 | else | ||
882 | txpower = ar->power_2G_ht20; | ||
883 | } | ||
884 | |||
885 | power = txpower[(txrate->idx) & 7]; | ||
886 | } else { | ||
887 | u8 *txpower; | ||
888 | u32 mod; | ||
889 | u32 phyrate; | ||
890 | u8 idx = txrate->idx; | ||
891 | |||
892 | if (info->band != IEEE80211_BAND_2GHZ) { | ||
893 | idx += 4; | ||
894 | txpower = ar->power_5G_leg; | ||
895 | mod = AR9170_TX_PHY_MOD_OFDM; | ||
896 | } else { | ||
897 | if (idx < 4) { | ||
898 | txpower = ar->power_2G_cck; | ||
899 | mod = AR9170_TX_PHY_MOD_CCK; | ||
900 | } else { | ||
901 | mod = AR9170_TX_PHY_MOD_OFDM; | ||
902 | txpower = ar->power_2G_ofdm; | ||
903 | } | ||
904 | } | ||
905 | |||
906 | rate = &__ar9170_ratetable[idx]; | ||
907 | |||
908 | phyrate = rate->hw_value & 0xF; | ||
909 | power = txpower[(rate->hw_value & 0x30) >> 4]; | ||
910 | phyrate <<= AR9170_TX_PHY_MCS_SHIFT; | ||
911 | |||
912 | txc->phy_control |= cpu_to_le32(mod); | ||
913 | txc->phy_control |= cpu_to_le32(phyrate); | ||
914 | } | ||
915 | |||
916 | power <<= AR9170_TX_PHY_TX_PWR_SHIFT; | ||
917 | power &= AR9170_TX_PHY_TX_PWR_MASK; | ||
918 | txc->phy_control |= cpu_to_le32(power); | ||
919 | |||
920 | /* set TX chains */ | ||
921 | if (ar->eeprom.tx_mask == 1) { | ||
922 | chains = AR9170_TX_PHY_TXCHAIN_1; | ||
923 | } else { | ||
924 | chains = AR9170_TX_PHY_TXCHAIN_2; | ||
925 | |||
926 | /* >= 36M legacy OFDM - use only one chain */ | ||
927 | if (rate && rate->bitrate >= 360) | ||
928 | chains = AR9170_TX_PHY_TXCHAIN_1; | ||
929 | } | ||
930 | txc->phy_control |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_SHIFT); | ||
931 | |||
932 | if (tx_status) { | ||
933 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE); | ||
934 | /* | ||
935 | * WARNING: | ||
936 | * Putting the QoS queue bits into an unexplored territory is | ||
937 | * certainly not elegant. | ||
938 | * | ||
939 | * In my defense: This idea provides a reasonable way to | ||
940 | * smuggle valuable information to the tx_status callback. | ||
941 | * Also, the idea behind this bit-abuse came straight from | ||
942 | * the original driver code. | ||
943 | */ | ||
944 | |||
945 | txc->phy_control |= | ||
946 | cpu_to_le32(queue << AR9170_TX_PHY_QOS_SHIFT); | ||
947 | |||
948 | if (info->control.sta) { | ||
949 | sta_info = (void *) info->control.sta->drv_priv; | ||
950 | skb_queue_tail(&sta_info->tx_status[queue], skb); | ||
951 | } else { | ||
952 | skb_queue_tail(&ar->global_tx_status, skb); | ||
953 | |||
954 | queue_delayed_work(ar->hw->workqueue, | ||
955 | &ar->tx_status_janitor, | ||
956 | msecs_to_jiffies(100)); | ||
957 | } | ||
958 | } | ||
959 | |||
960 | err = ar->tx(ar, skb, tx_status, 0); | ||
961 | if (unlikely(tx_status && err)) { | ||
962 | if (info->control.sta) | ||
963 | skb_unlink(skb, &sta_info->tx_status[queue]); | ||
964 | else | ||
965 | skb_unlink(skb, &ar->global_tx_status); | ||
966 | } | ||
967 | |||
968 | return NETDEV_TX_OK; | ||
969 | |||
970 | err_dequeue: | ||
971 | spin_lock_irqsave(&ar->tx_stats_lock, flags); | ||
972 | ar->tx_stats[queue].len--; | ||
973 | ar->tx_stats[queue].count--; | ||
974 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); | ||
975 | |||
976 | err_free: | ||
977 | dev_kfree_skb(skb); | ||
978 | return NETDEV_TX_OK; | ||
979 | } | ||
980 | |||
981 | static int ar9170_op_add_interface(struct ieee80211_hw *hw, | ||
982 | struct ieee80211_if_init_conf *conf) | ||
983 | { | ||
984 | struct ar9170 *ar = hw->priv; | ||
985 | int err = 0; | ||
986 | |||
987 | mutex_lock(&ar->mutex); | ||
988 | |||
989 | if (ar->vif) { | ||
990 | err = -EBUSY; | ||
991 | goto unlock; | ||
992 | } | ||
993 | |||
994 | ar->vif = conf->vif; | ||
995 | memcpy(ar->mac_addr, conf->mac_addr, ETH_ALEN); | ||
996 | |||
997 | if (modparam_nohwcrypt || (ar->vif->type != NL80211_IFTYPE_STATION)) { | ||
998 | ar->rx_software_decryption = true; | ||
999 | ar->disable_offload = true; | ||
1000 | } | ||
1001 | |||
1002 | ar->cur_filter = 0; | ||
1003 | ar->want_filter = AR9170_MAC_REG_FTF_DEFAULTS; | ||
1004 | err = ar9170_update_frame_filter(ar); | ||
1005 | if (err) | ||
1006 | goto unlock; | ||
1007 | |||
1008 | err = ar9170_set_operating_mode(ar); | ||
1009 | |||
1010 | unlock: | ||
1011 | mutex_unlock(&ar->mutex); | ||
1012 | return err; | ||
1013 | } | ||
1014 | |||
1015 | static void ar9170_op_remove_interface(struct ieee80211_hw *hw, | ||
1016 | struct ieee80211_if_init_conf *conf) | ||
1017 | { | ||
1018 | struct ar9170 *ar = hw->priv; | ||
1019 | |||
1020 | mutex_lock(&ar->mutex); | ||
1021 | ar->vif = NULL; | ||
1022 | ar->want_filter = 0; | ||
1023 | ar9170_update_frame_filter(ar); | ||
1024 | ar9170_set_beacon_timers(ar); | ||
1025 | dev_kfree_skb(ar->beacon); | ||
1026 | ar->beacon = NULL; | ||
1027 | ar->sniffer_enabled = false; | ||
1028 | ar->rx_software_decryption = false; | ||
1029 | ar9170_set_operating_mode(ar); | ||
1030 | mutex_unlock(&ar->mutex); | ||
1031 | } | ||
1032 | |||
1033 | static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed) | ||
1034 | { | ||
1035 | struct ar9170 *ar = hw->priv; | ||
1036 | int err = 0; | ||
1037 | |||
1038 | mutex_lock(&ar->mutex); | ||
1039 | |||
1040 | if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) { | ||
1041 | /* TODO */ | ||
1042 | err = 0; | ||
1043 | } | ||
1044 | |||
1045 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { | ||
1046 | /* TODO */ | ||
1047 | err = 0; | ||
1048 | } | ||
1049 | |||
1050 | if (changed & IEEE80211_CONF_CHANGE_PS) { | ||
1051 | /* TODO */ | ||
1052 | err = 0; | ||
1053 | } | ||
1054 | |||
1055 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | ||
1056 | /* TODO */ | ||
1057 | err = 0; | ||
1058 | } | ||
1059 | |||
1060 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { | ||
1061 | /* | ||
1062 | * is it long_frame_max_tx_count or short_frame_max_tx_count? | ||
1063 | */ | ||
1064 | |||
1065 | err = ar9170_set_hwretry_limit(ar, | ||
1066 | ar->hw->conf.long_frame_max_tx_count); | ||
1067 | if (err) | ||
1068 | goto out; | ||
1069 | } | ||
1070 | |||
1071 | if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL) { | ||
1072 | err = ar9170_set_beacon_timers(ar); | ||
1073 | if (err) | ||
1074 | goto out; | ||
1075 | } | ||
1076 | |||
1077 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | ||
1078 | err = ar9170_set_channel(ar, hw->conf.channel, | ||
1079 | AR9170_RFI_NONE, AR9170_BW_20); | ||
1080 | if (err) | ||
1081 | goto out; | ||
1082 | /* adjust slot time for 5 GHz */ | ||
1083 | if (hw->conf.channel->band == IEEE80211_BAND_5GHZ) | ||
1084 | err = ar9170_write_reg(ar, AR9170_MAC_REG_SLOT_TIME, | ||
1085 | 9 << 10); | ||
1086 | } | ||
1087 | |||
1088 | out: | ||
1089 | mutex_unlock(&ar->mutex); | ||
1090 | return err; | ||
1091 | } | ||
1092 | |||
1093 | static int ar9170_op_config_interface(struct ieee80211_hw *hw, | ||
1094 | struct ieee80211_vif *vif, | ||
1095 | struct ieee80211_if_conf *conf) | ||
1096 | { | ||
1097 | struct ar9170 *ar = hw->priv; | ||
1098 | int err = 0; | ||
1099 | |||
1100 | mutex_lock(&ar->mutex); | ||
1101 | |||
1102 | if (conf->changed & IEEE80211_IFCC_BSSID) { | ||
1103 | memcpy(ar->bssid, conf->bssid, ETH_ALEN); | ||
1104 | err = ar9170_set_operating_mode(ar); | ||
1105 | } | ||
1106 | |||
1107 | if (conf->changed & IEEE80211_IFCC_BEACON) { | ||
1108 | err = ar9170_update_beacon(ar); | ||
1109 | |||
1110 | if (err) | ||
1111 | goto out; | ||
1112 | err = ar9170_set_beacon_timers(ar); | ||
1113 | } | ||
1114 | |||
1115 | out: | ||
1116 | mutex_unlock(&ar->mutex); | ||
1117 | return err; | ||
1118 | } | ||
1119 | |||
1120 | static void ar9170_set_filters(struct work_struct *work) | ||
1121 | { | ||
1122 | struct ar9170 *ar = container_of(work, struct ar9170, | ||
1123 | filter_config_work); | ||
1124 | int err; | ||
1125 | |||
1126 | mutex_lock(&ar->mutex); | ||
1127 | if (unlikely(!IS_STARTED(ar))) | ||
1128 | goto unlock; | ||
1129 | |||
1130 | if (ar->filter_changed & AR9170_FILTER_CHANGED_PROMISC) { | ||
1131 | err = ar9170_set_operating_mode(ar); | ||
1132 | if (err) | ||
1133 | goto unlock; | ||
1134 | } | ||
1135 | |||
1136 | if (ar->filter_changed & AR9170_FILTER_CHANGED_MULTICAST) { | ||
1137 | err = ar9170_update_multicast(ar); | ||
1138 | if (err) | ||
1139 | goto unlock; | ||
1140 | } | ||
1141 | |||
1142 | if (ar->filter_changed & AR9170_FILTER_CHANGED_FRAMEFILTER) | ||
1143 | err = ar9170_update_frame_filter(ar); | ||
1144 | |||
1145 | unlock: | ||
1146 | mutex_unlock(&ar->mutex); | ||
1147 | } | ||
1148 | |||
1149 | static void ar9170_op_configure_filter(struct ieee80211_hw *hw, | ||
1150 | unsigned int changed_flags, | ||
1151 | unsigned int *new_flags, | ||
1152 | int mc_count, struct dev_mc_list *mclist) | ||
1153 | { | ||
1154 | struct ar9170 *ar = hw->priv; | ||
1155 | |||
1156 | /* mask supported flags */ | ||
1157 | *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC | | ||
1158 | FIF_PROMISC_IN_BSS; | ||
1159 | |||
1160 | /* | ||
1161 | * We can support more by setting the sniffer bit and | ||
1162 | * then checking the error flags, later. | ||
1163 | */ | ||
1164 | |||
1165 | if (changed_flags & FIF_ALLMULTI) { | ||
1166 | if (*new_flags & FIF_ALLMULTI) { | ||
1167 | ar->want_mc_hash = ~0ULL; | ||
1168 | } else { | ||
1169 | u64 mchash; | ||
1170 | int i; | ||
1171 | |||
1172 | /* always get broadcast frames */ | ||
1173 | mchash = 1ULL << (0xff>>2); | ||
1174 | |||
1175 | for (i = 0; i < mc_count; i++) { | ||
1176 | if (WARN_ON(!mclist)) | ||
1177 | break; | ||
1178 | mchash |= 1ULL << (mclist->dmi_addr[5] >> 2); | ||
1179 | mclist = mclist->next; | ||
1180 | } | ||
1181 | ar->want_mc_hash = mchash; | ||
1182 | } | ||
1183 | ar->filter_changed |= AR9170_FILTER_CHANGED_MULTICAST; | ||
1184 | } | ||
1185 | |||
1186 | if (changed_flags & FIF_CONTROL) { | ||
1187 | u32 filter = AR9170_MAC_REG_FTF_PSPOLL | | ||
1188 | AR9170_MAC_REG_FTF_RTS | | ||
1189 | AR9170_MAC_REG_FTF_CTS | | ||
1190 | AR9170_MAC_REG_FTF_ACK | | ||
1191 | AR9170_MAC_REG_FTF_CFE | | ||
1192 | AR9170_MAC_REG_FTF_CFE_ACK; | ||
1193 | |||
1194 | if (*new_flags & FIF_CONTROL) | ||
1195 | ar->want_filter = ar->cur_filter | filter; | ||
1196 | else | ||
1197 | ar->want_filter = ar->cur_filter & ~filter; | ||
1198 | |||
1199 | ar->filter_changed |= AR9170_FILTER_CHANGED_FRAMEFILTER; | ||
1200 | } | ||
1201 | |||
1202 | if (changed_flags & FIF_PROMISC_IN_BSS) { | ||
1203 | ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0; | ||
1204 | ar->filter_changed |= AR9170_FILTER_CHANGED_PROMISC; | ||
1205 | } | ||
1206 | |||
1207 | if (likely(IS_STARTED(ar))) | ||
1208 | queue_work(ar->hw->workqueue, &ar->filter_config_work); | ||
1209 | } | ||
1210 | |||
1211 | static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw, | ||
1212 | struct ieee80211_vif *vif, | ||
1213 | struct ieee80211_bss_conf *bss_conf, | ||
1214 | u32 changed) | ||
1215 | { | ||
1216 | struct ar9170 *ar = hw->priv; | ||
1217 | int err = 0; | ||
1218 | |||
1219 | mutex_lock(&ar->mutex); | ||
1220 | |||
1221 | ar9170_regwrite_begin(ar); | ||
1222 | |||
1223 | if (changed & BSS_CHANGED_ASSOC) { | ||
1224 | ar->state = bss_conf->assoc ? AR9170_ASSOCIATED : ar->state; | ||
1225 | |||
1226 | #ifndef CONFIG_AR9170_LEDS | ||
1227 | /* enable assoc LED. */ | ||
1228 | err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0); | ||
1229 | #endif /* CONFIG_AR9170_LEDS */ | ||
1230 | } | ||
1231 | |||
1232 | if (changed & BSS_CHANGED_HT) { | ||
1233 | /* TODO */ | ||
1234 | err = 0; | ||
1235 | } | ||
1236 | |||
1237 | if (changed & BSS_CHANGED_ERP_SLOT) { | ||
1238 | u32 slottime = 20; | ||
1239 | |||
1240 | if (bss_conf->use_short_slot) | ||
1241 | slottime = 9; | ||
1242 | |||
1243 | ar9170_regwrite(AR9170_MAC_REG_SLOT_TIME, slottime << 10); | ||
1244 | } | ||
1245 | |||
1246 | if (changed & BSS_CHANGED_BASIC_RATES) { | ||
1247 | u32 cck, ofdm; | ||
1248 | |||
1249 | if (hw->conf.channel->band == IEEE80211_BAND_5GHZ) { | ||
1250 | ofdm = bss_conf->basic_rates; | ||
1251 | cck = 0; | ||
1252 | } else { | ||
1253 | /* four cck rates */ | ||
1254 | cck = bss_conf->basic_rates & 0xf; | ||
1255 | ofdm = bss_conf->basic_rates >> 4; | ||
1256 | } | ||
1257 | ar9170_regwrite(AR9170_MAC_REG_BASIC_RATE, | ||
1258 | ofdm << 8 | cck); | ||
1259 | } | ||
1260 | |||
1261 | ar9170_regwrite_finish(); | ||
1262 | err = ar9170_regwrite_result(); | ||
1263 | mutex_unlock(&ar->mutex); | ||
1264 | } | ||
1265 | |||
1266 | static u64 ar9170_op_get_tsf(struct ieee80211_hw *hw) | ||
1267 | { | ||
1268 | struct ar9170 *ar = hw->priv; | ||
1269 | int err; | ||
1270 | u32 tsf_low; | ||
1271 | u32 tsf_high; | ||
1272 | u64 tsf; | ||
1273 | |||
1274 | mutex_lock(&ar->mutex); | ||
1275 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_L, &tsf_low); | ||
1276 | if (!err) | ||
1277 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_H, &tsf_high); | ||
1278 | mutex_unlock(&ar->mutex); | ||
1279 | |||
1280 | if (WARN_ON(err)) | ||
1281 | return 0; | ||
1282 | |||
1283 | tsf = tsf_high; | ||
1284 | tsf = (tsf << 32) | tsf_low; | ||
1285 | return tsf; | ||
1286 | } | ||
1287 | |||
1288 | static int ar9170_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | ||
1289 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | ||
1290 | struct ieee80211_key_conf *key) | ||
1291 | { | ||
1292 | struct ar9170 *ar = hw->priv; | ||
1293 | int err = 0, i; | ||
1294 | u8 ktype; | ||
1295 | |||
1296 | if ((!ar->vif) || (ar->disable_offload)) | ||
1297 | return -EOPNOTSUPP; | ||
1298 | |||
1299 | switch (key->alg) { | ||
1300 | case ALG_WEP: | ||
1301 | if (key->keylen == LEN_WEP40) | ||
1302 | ktype = AR9170_ENC_ALG_WEP64; | ||
1303 | else | ||
1304 | ktype = AR9170_ENC_ALG_WEP128; | ||
1305 | break; | ||
1306 | case ALG_TKIP: | ||
1307 | ktype = AR9170_ENC_ALG_TKIP; | ||
1308 | break; | ||
1309 | case ALG_CCMP: | ||
1310 | ktype = AR9170_ENC_ALG_AESCCMP; | ||
1311 | break; | ||
1312 | default: | ||
1313 | return -EOPNOTSUPP; | ||
1314 | } | ||
1315 | |||
1316 | mutex_lock(&ar->mutex); | ||
1317 | if (cmd == SET_KEY) { | ||
1318 | if (unlikely(!IS_STARTED(ar))) { | ||
1319 | err = -EOPNOTSUPP; | ||
1320 | goto out; | ||
1321 | } | ||
1322 | |||
1323 | /* group keys need all-zeroes address */ | ||
1324 | if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | ||
1325 | sta = NULL; | ||
1326 | |||
1327 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { | ||
1328 | for (i = 0; i < 64; i++) | ||
1329 | if (!(ar->usedkeys & BIT(i))) | ||
1330 | break; | ||
1331 | if (i == 64) { | ||
1332 | ar->rx_software_decryption = true; | ||
1333 | ar9170_set_operating_mode(ar); | ||
1334 | err = -ENOSPC; | ||
1335 | goto out; | ||
1336 | } | ||
1337 | } else { | ||
1338 | i = 64 + key->keyidx; | ||
1339 | } | ||
1340 | |||
1341 | key->hw_key_idx = i; | ||
1342 | |||
1343 | err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, ktype, 0, | ||
1344 | key->key, min_t(u8, 16, key->keylen)); | ||
1345 | if (err) | ||
1346 | goto out; | ||
1347 | |||
1348 | if (key->alg == ALG_TKIP) { | ||
1349 | err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, | ||
1350 | ktype, 1, key->key + 16, 16); | ||
1351 | if (err) | ||
1352 | goto out; | ||
1353 | |||
1354 | /* | ||
1355 | * hardware is not capable generating the MMIC | ||
1356 | * for fragmented frames! | ||
1357 | */ | ||
1358 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | ||
1359 | } | ||
1360 | |||
1361 | if (i < 64) | ||
1362 | ar->usedkeys |= BIT(i); | ||
1363 | |||
1364 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | ||
1365 | } else { | ||
1366 | if (unlikely(!IS_STARTED(ar))) { | ||
1367 | /* The device is gone... together with the key ;-) */ | ||
1368 | err = 0; | ||
1369 | goto out; | ||
1370 | } | ||
1371 | |||
1372 | err = ar9170_disable_key(ar, key->hw_key_idx); | ||
1373 | if (err) | ||
1374 | goto out; | ||
1375 | |||
1376 | if (key->hw_key_idx < 64) { | ||
1377 | ar->usedkeys &= ~BIT(key->hw_key_idx); | ||
1378 | } else { | ||
1379 | err = ar9170_upload_key(ar, key->hw_key_idx, NULL, | ||
1380 | AR9170_ENC_ALG_NONE, 0, | ||
1381 | NULL, 0); | ||
1382 | if (err) | ||
1383 | goto out; | ||
1384 | |||
1385 | if (key->alg == ALG_TKIP) { | ||
1386 | err = ar9170_upload_key(ar, key->hw_key_idx, | ||
1387 | NULL, | ||
1388 | AR9170_ENC_ALG_NONE, 1, | ||
1389 | NULL, 0); | ||
1390 | if (err) | ||
1391 | goto out; | ||
1392 | } | ||
1393 | |||
1394 | } | ||
1395 | } | ||
1396 | |||
1397 | ar9170_regwrite_begin(ar); | ||
1398 | ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L, ar->usedkeys); | ||
1399 | ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H, ar->usedkeys >> 32); | ||
1400 | ar9170_regwrite_finish(); | ||
1401 | err = ar9170_regwrite_result(); | ||
1402 | |||
1403 | out: | ||
1404 | mutex_unlock(&ar->mutex); | ||
1405 | |||
1406 | return err; | ||
1407 | } | ||
1408 | |||
1409 | static void ar9170_sta_notify(struct ieee80211_hw *hw, | ||
1410 | struct ieee80211_vif *vif, | ||
1411 | enum sta_notify_cmd cmd, | ||
1412 | struct ieee80211_sta *sta) | ||
1413 | { | ||
1414 | struct ar9170 *ar = hw->priv; | ||
1415 | struct ar9170_sta_info *info = (void *) sta->drv_priv; | ||
1416 | struct sk_buff *skb; | ||
1417 | unsigned int i; | ||
1418 | |||
1419 | switch (cmd) { | ||
1420 | case STA_NOTIFY_ADD: | ||
1421 | for (i = 0; i < ar->hw->queues; i++) | ||
1422 | skb_queue_head_init(&info->tx_status[i]); | ||
1423 | break; | ||
1424 | |||
1425 | case STA_NOTIFY_REMOVE: | ||
1426 | |||
1427 | /* | ||
1428 | * transfer all outstanding frames that need a tx_status | ||
1429 | * reports to the global tx_status queue | ||
1430 | */ | ||
1431 | |||
1432 | for (i = 0; i < ar->hw->queues; i++) { | ||
1433 | while ((skb = skb_dequeue(&info->tx_status[i]))) { | ||
1434 | #ifdef AR9170_QUEUE_DEBUG | ||
1435 | printk(KERN_DEBUG "%s: queueing frame in " | ||
1436 | "global tx_status queue =>\n", | ||
1437 | wiphy_name(ar->hw->wiphy)); | ||
1438 | |||
1439 | ar9170_print_txheader(ar, skb); | ||
1440 | #endif /* AR9170_QUEUE_DEBUG */ | ||
1441 | skb_queue_tail(&ar->global_tx_status, skb); | ||
1442 | } | ||
1443 | } | ||
1444 | queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor, | ||
1445 | msecs_to_jiffies(100)); | ||
1446 | break; | ||
1447 | |||
1448 | default: | ||
1449 | break; | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | static int ar9170_get_stats(struct ieee80211_hw *hw, | ||
1454 | struct ieee80211_low_level_stats *stats) | ||
1455 | { | ||
1456 | struct ar9170 *ar = hw->priv; | ||
1457 | u32 val; | ||
1458 | int err; | ||
1459 | |||
1460 | mutex_lock(&ar->mutex); | ||
1461 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TX_RETRY, &val); | ||
1462 | ar->stats.dot11ACKFailureCount += val; | ||
1463 | |||
1464 | memcpy(stats, &ar->stats, sizeof(*stats)); | ||
1465 | mutex_unlock(&ar->mutex); | ||
1466 | |||
1467 | return 0; | ||
1468 | } | ||
1469 | |||
1470 | static int ar9170_get_tx_stats(struct ieee80211_hw *hw, | ||
1471 | struct ieee80211_tx_queue_stats *tx_stats) | ||
1472 | { | ||
1473 | struct ar9170 *ar = hw->priv; | ||
1474 | |||
1475 | spin_lock_bh(&ar->tx_stats_lock); | ||
1476 | memcpy(tx_stats, ar->tx_stats, sizeof(tx_stats[0]) * hw->queues); | ||
1477 | spin_unlock_bh(&ar->tx_stats_lock); | ||
1478 | |||
1479 | return 0; | ||
1480 | } | ||
1481 | |||
1482 | static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue, | ||
1483 | const struct ieee80211_tx_queue_params *param) | ||
1484 | { | ||
1485 | struct ar9170 *ar = hw->priv; | ||
1486 | int ret; | ||
1487 | |||
1488 | mutex_lock(&ar->mutex); | ||
1489 | if ((param) && !(queue > ar->hw->queues)) { | ||
1490 | memcpy(&ar->edcf[ar9170_qos_hwmap[queue]], | ||
1491 | param, sizeof(*param)); | ||
1492 | |||
1493 | ret = ar9170_set_qos(ar); | ||
1494 | } else | ||
1495 | ret = -EINVAL; | ||
1496 | |||
1497 | mutex_unlock(&ar->mutex); | ||
1498 | return ret; | ||
1499 | } | ||
1500 | |||
1501 | static const struct ieee80211_ops ar9170_ops = { | ||
1502 | .start = ar9170_op_start, | ||
1503 | .stop = ar9170_op_stop, | ||
1504 | .tx = ar9170_op_tx, | ||
1505 | .add_interface = ar9170_op_add_interface, | ||
1506 | .remove_interface = ar9170_op_remove_interface, | ||
1507 | .config = ar9170_op_config, | ||
1508 | .config_interface = ar9170_op_config_interface, | ||
1509 | .configure_filter = ar9170_op_configure_filter, | ||
1510 | .conf_tx = ar9170_conf_tx, | ||
1511 | .bss_info_changed = ar9170_op_bss_info_changed, | ||
1512 | .get_tsf = ar9170_op_get_tsf, | ||
1513 | .set_key = ar9170_set_key, | ||
1514 | .sta_notify = ar9170_sta_notify, | ||
1515 | .get_stats = ar9170_get_stats, | ||
1516 | .get_tx_stats = ar9170_get_tx_stats, | ||
1517 | }; | ||
1518 | |||
1519 | void *ar9170_alloc(size_t priv_size) | ||
1520 | { | ||
1521 | struct ieee80211_hw *hw; | ||
1522 | struct ar9170 *ar; | ||
1523 | int i; | ||
1524 | |||
1525 | hw = ieee80211_alloc_hw(priv_size, &ar9170_ops); | ||
1526 | if (!hw) | ||
1527 | return ERR_PTR(-ENOMEM); | ||
1528 | |||
1529 | ar = hw->priv; | ||
1530 | ar->hw = hw; | ||
1531 | |||
1532 | mutex_init(&ar->mutex); | ||
1533 | spin_lock_init(&ar->cmdlock); | ||
1534 | spin_lock_init(&ar->tx_stats_lock); | ||
1535 | skb_queue_head_init(&ar->global_tx_status); | ||
1536 | skb_queue_head_init(&ar->global_tx_status_waste); | ||
1537 | INIT_WORK(&ar->filter_config_work, ar9170_set_filters); | ||
1538 | INIT_WORK(&ar->beacon_work, ar9170_new_beacon); | ||
1539 | INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor); | ||
1540 | |||
1541 | /* all hw supports 2.4 GHz, so set channel to 1 by default */ | ||
1542 | ar->channel = &ar9170_2ghz_chantable[0]; | ||
1543 | |||
1544 | /* first part of wiphy init */ | ||
1545 | ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | ||
1546 | BIT(NL80211_IFTYPE_WDS) | | ||
1547 | BIT(NL80211_IFTYPE_ADHOC); | ||
1548 | ar->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS | | ||
1549 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | | ||
1550 | IEEE80211_HW_SIGNAL_DBM | | ||
1551 | IEEE80211_HW_NOISE_DBM; | ||
1552 | |||
1553 | ar->hw->queues = __AR9170_NUM_TXQ; | ||
1554 | ar->hw->extra_tx_headroom = 8; | ||
1555 | ar->hw->sta_data_size = sizeof(struct ar9170_sta_info); | ||
1556 | |||
1557 | ar->hw->max_rates = 1; | ||
1558 | ar->hw->max_rate_tries = 3; | ||
1559 | |||
1560 | for (i = 0; i < ARRAY_SIZE(ar->noise); i++) | ||
1561 | ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */ | ||
1562 | |||
1563 | return ar; | ||
1564 | } | ||
1565 | |||
1566 | static int ar9170_read_eeprom(struct ar9170 *ar) | ||
1567 | { | ||
1568 | #define RW 8 /* number of words to read at once */ | ||
1569 | #define RB (sizeof(u32) * RW) | ||
1570 | DECLARE_MAC_BUF(mbuf); | ||
1571 | u8 *eeprom = (void *)&ar->eeprom; | ||
1572 | u8 *addr = ar->eeprom.mac_address; | ||
1573 | __le32 offsets[RW]; | ||
1574 | int i, j, err, bands = 0; | ||
1575 | |||
1576 | BUILD_BUG_ON(sizeof(ar->eeprom) & 3); | ||
1577 | |||
1578 | BUILD_BUG_ON(RB > AR9170_MAX_CMD_LEN - 4); | ||
1579 | #ifndef __CHECKER__ | ||
1580 | /* don't want to handle trailing remains */ | ||
1581 | BUILD_BUG_ON(sizeof(ar->eeprom) % RB); | ||
1582 | #endif | ||
1583 | |||
1584 | for (i = 0; i < sizeof(ar->eeprom)/RB; i++) { | ||
1585 | for (j = 0; j < RW; j++) | ||
1586 | offsets[j] = cpu_to_le32(AR9170_EEPROM_START + | ||
1587 | RB * i + 4 * j); | ||
1588 | |||
1589 | err = ar->exec_cmd(ar, AR9170_CMD_RREG, | ||
1590 | RB, (u8 *) &offsets, | ||
1591 | RB, eeprom + RB * i); | ||
1592 | if (err) | ||
1593 | return err; | ||
1594 | } | ||
1595 | |||
1596 | #undef RW | ||
1597 | #undef RB | ||
1598 | |||
1599 | if (ar->eeprom.length == cpu_to_le16(0xFFFF)) | ||
1600 | return -ENODATA; | ||
1601 | |||
1602 | if (ar->eeprom.operating_flags & AR9170_OPFLAG_2GHZ) { | ||
1603 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar9170_band_2GHz; | ||
1604 | bands++; | ||
1605 | } | ||
1606 | if (ar->eeprom.operating_flags & AR9170_OPFLAG_5GHZ) { | ||
1607 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar9170_band_5GHz; | ||
1608 | bands++; | ||
1609 | } | ||
1610 | /* | ||
1611 | * I measured this, a bandswitch takes roughly | ||
1612 | * 135 ms and a frequency switch about 80. | ||
1613 | * | ||
1614 | * FIXME: measure these values again once EEPROM settings | ||
1615 | * are used, that will influence them! | ||
1616 | */ | ||
1617 | if (bands == 2) | ||
1618 | ar->hw->channel_change_time = 135 * 1000; | ||
1619 | else | ||
1620 | ar->hw->channel_change_time = 80 * 1000; | ||
1621 | |||
1622 | /* second part of wiphy init */ | ||
1623 | SET_IEEE80211_PERM_ADDR(ar->hw, addr); | ||
1624 | |||
1625 | return bands ? 0 : -EINVAL; | ||
1626 | } | ||
1627 | |||
1628 | int ar9170_register(struct ar9170 *ar, struct device *pdev) | ||
1629 | { | ||
1630 | int err; | ||
1631 | |||
1632 | /* try to read EEPROM, init MAC addr */ | ||
1633 | err = ar9170_read_eeprom(ar); | ||
1634 | if (err) | ||
1635 | goto err_out; | ||
1636 | |||
1637 | err = ieee80211_register_hw(ar->hw); | ||
1638 | if (err) | ||
1639 | goto err_out; | ||
1640 | |||
1641 | err = ar9170_init_leds(ar); | ||
1642 | if (err) | ||
1643 | goto err_unreg; | ||
1644 | |||
1645 | #ifdef CONFIG_AR9170_LEDS | ||
1646 | err = ar9170_register_leds(ar); | ||
1647 | if (err) | ||
1648 | goto err_unreg; | ||
1649 | #endif /* CONFIG_AR9170_LEDS */ | ||
1650 | |||
1651 | dev_info(pdev, "Atheros AR9170 is registered as '%s'\n", | ||
1652 | wiphy_name(ar->hw->wiphy)); | ||
1653 | |||
1654 | return err; | ||
1655 | |||
1656 | err_unreg: | ||
1657 | ieee80211_unregister_hw(ar->hw); | ||
1658 | |||
1659 | err_out: | ||
1660 | return err; | ||
1661 | } | ||
1662 | |||
1663 | void ar9170_unregister(struct ar9170 *ar) | ||
1664 | { | ||
1665 | #ifdef CONFIG_AR9170_LEDS | ||
1666 | ar9170_unregister_leds(ar); | ||
1667 | #endif /* CONFIG_AR9170_LEDS */ | ||
1668 | |||
1669 | ieee80211_unregister_hw(ar->hw); | ||
1670 | mutex_destroy(&ar->mutex); | ||
1671 | } | ||
diff --git a/drivers/net/wireless/ar9170/phy.c b/drivers/net/wireless/ar9170/phy.c new file mode 100644 index 000000000000..6ce20754b8e7 --- /dev/null +++ b/drivers/net/wireless/ar9170/phy.c | |||
@@ -0,0 +1,1240 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * PHY and RF code | ||
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 | |||
39 | #include <linux/bitrev.h> | ||
40 | #include "ar9170.h" | ||
41 | #include "cmd.h" | ||
42 | |||
43 | static int ar9170_init_power_cal(struct ar9170 *ar) | ||
44 | { | ||
45 | ar9170_regwrite_begin(ar); | ||
46 | |||
47 | ar9170_regwrite(0x1bc000 + 0x993c, 0x7f); | ||
48 | ar9170_regwrite(0x1bc000 + 0x9934, 0x3f3f3f3f); | ||
49 | ar9170_regwrite(0x1bc000 + 0x9938, 0x3f3f3f3f); | ||
50 | ar9170_regwrite(0x1bc000 + 0xa234, 0x3f3f3f3f); | ||
51 | ar9170_regwrite(0x1bc000 + 0xa238, 0x3f3f3f3f); | ||
52 | ar9170_regwrite(0x1bc000 + 0xa38c, 0x3f3f3f3f); | ||
53 | ar9170_regwrite(0x1bc000 + 0xa390, 0x3f3f3f3f); | ||
54 | ar9170_regwrite(0x1bc000 + 0xa3cc, 0x3f3f3f3f); | ||
55 | ar9170_regwrite(0x1bc000 + 0xa3d0, 0x3f3f3f3f); | ||
56 | ar9170_regwrite(0x1bc000 + 0xa3d4, 0x3f3f3f3f); | ||
57 | |||
58 | ar9170_regwrite_finish(); | ||
59 | return ar9170_regwrite_result(); | ||
60 | } | ||
61 | |||
62 | struct ar9170_phy_init { | ||
63 | u32 reg, _5ghz_20, _5ghz_40, _2ghz_40, _2ghz_20; | ||
64 | }; | ||
65 | |||
66 | static struct ar9170_phy_init ar5416_phy_init[] = { | ||
67 | { 0x1c5800, 0x00000007, 0x00000007, 0x00000007, 0x00000007, }, | ||
68 | { 0x1c5804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, }, | ||
69 | { 0x1c5808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
70 | { 0x1c580c, 0xad848e19, 0xad848e19, 0xad848e19, 0xad848e19, }, | ||
71 | { 0x1c5810, 0x7d14e000, 0x7d14e000, 0x7d14e000, 0x7d14e000, }, | ||
72 | { 0x1c5814, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, }, | ||
73 | { 0x1c5818, 0x00000090, 0x00000090, 0x00000090, 0x00000090, }, | ||
74 | { 0x1c581c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
75 | { 0x1c5820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, }, | ||
76 | { 0x1c5824, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, }, | ||
77 | { 0x1c5828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, }, | ||
78 | { 0x1c582c, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, }, | ||
79 | { 0x1c5830, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
80 | { 0x1c5834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, }, | ||
81 | { 0x1c5838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, }, | ||
82 | { 0x1c583c, 0x00200400, 0x00200400, 0x00200400, 0x00200400, }, | ||
83 | { 0x1c5840, 0x206a002e, 0x206a002e, 0x206a002e, 0x206a002e, }, | ||
84 | { 0x1c5844, 0x1372161e, 0x13721c1e, 0x13721c24, 0x137216a4, }, | ||
85 | { 0x1c5848, 0x001a6a65, 0x001a6a65, 0x00197a68, 0x00197a68, }, | ||
86 | { 0x1c584c, 0x1284233c, 0x1284233c, 0x1284233c, 0x1284233c, }, | ||
87 | { 0x1c5850, 0x6c48b4e4, 0x6c48b4e4, 0x6c48b0e4, 0x6c48b0e4, }, | ||
88 | { 0x1c5854, 0x00000859, 0x00000859, 0x00000859, 0x00000859, }, | ||
89 | { 0x1c5858, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, }, | ||
90 | { 0x1c585c, 0x31395c5e, 0x31395c5e, 0x31395c5e, 0x31395c5e, }, | ||
91 | { 0x1c5860, 0x0004dd10, 0x0004dd10, 0x0004dd20, 0x0004dd20, }, | ||
92 | { 0x1c5868, 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190, }, | ||
93 | { 0x1c586c, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, }, | ||
94 | { 0x1c5900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
95 | { 0x1c5904, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
96 | { 0x1c5908, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
97 | { 0x1c590c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
98 | { 0x1c5914, 0x000007d0, 0x000007d0, 0x00000898, 0x00000898, }, | ||
99 | { 0x1c5918, 0x00000118, 0x00000230, 0x00000268, 0x00000134, }, | ||
100 | { 0x1c591c, 0x10000fff, 0x10000fff, 0x10000fff, 0x10000fff, }, | ||
101 | { 0x1c5920, 0x0510081c, 0x0510081c, 0x0510001c, 0x0510001c, }, | ||
102 | { 0x1c5924, 0xd0058a15, 0xd0058a15, 0xd0058a15, 0xd0058a15, }, | ||
103 | { 0x1c5928, 0x00000001, 0x00000001, 0x00000001, 0x00000001, }, | ||
104 | { 0x1c592c, 0x00000004, 0x00000004, 0x00000004, 0x00000004, }, | ||
105 | { 0x1c5934, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
106 | { 0x1c5938, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
107 | { 0x1c593c, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f, }, | ||
108 | { 0x1c5944, 0xdfb81020, 0xdfb81020, 0xdfb81020, 0xdfb81020, }, | ||
109 | { 0x1c5948, 0x9280b212, 0x9280b212, 0x9280b212, 0x9280b212, }, | ||
110 | { 0x1c594c, 0x00020028, 0x00020028, 0x00020028, 0x00020028, }, | ||
111 | { 0x1c5954, 0x5d50e188, 0x5d50e188, 0x5d50e188, 0x5d50e188, }, | ||
112 | { 0x1c5958, 0x00081fff, 0x00081fff, 0x00081fff, 0x00081fff, }, | ||
113 | { 0x1c5960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, }, | ||
114 | { 0x1c5964, 0x00001120, 0x00001120, 0x00001120, 0x00001120, }, | ||
115 | { 0x1c5970, 0x190fb515, 0x190fb515, 0x190fb515, 0x190fb515, }, | ||
116 | { 0x1c5974, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
117 | { 0x1c5978, 0x00000001, 0x00000001, 0x00000001, 0x00000001, }, | ||
118 | { 0x1c597c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
119 | { 0x1c5980, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
120 | { 0x1c5984, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
121 | { 0x1c5988, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
122 | { 0x1c598c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
123 | { 0x1c5990, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
124 | { 0x1c5994, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
125 | { 0x1c5998, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
126 | { 0x1c599c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
127 | { 0x1c59a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
128 | { 0x1c59a4, 0x00000007, 0x00000007, 0x00000007, 0x00000007, }, | ||
129 | { 0x1c59a8, 0x001fff00, 0x001fff00, 0x001fff00, 0x001fff00, }, | ||
130 | { 0x1c59ac, 0x006f00c4, 0x006f00c4, 0x006f00c4, 0x006f00c4, }, | ||
131 | { 0x1c59b0, 0x03051000, 0x03051000, 0x03051000, 0x03051000, }, | ||
132 | { 0x1c59b4, 0x00000820, 0x00000820, 0x00000820, 0x00000820, }, | ||
133 | { 0x1c59c0, 0x038919be, 0x038919be, 0x038919be, 0x038919be, }, | ||
134 | { 0x1c59c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, }, | ||
135 | { 0x1c59c8, 0x60f6532c, 0x60f6532c, 0x60f6532c, 0x60f6532c, }, | ||
136 | { 0x1c59cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, }, | ||
137 | { 0x1c59d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, }, | ||
138 | { 0x1c59d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
139 | { 0x1c59d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
140 | { 0x1c59dc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
141 | { 0x1c59e0, 0x00000200, 0x00000200, 0x00000200, 0x00000200, }, | ||
142 | { 0x1c59e4, 0x64646464, 0x64646464, 0x64646464, 0x64646464, }, | ||
143 | { 0x1c59e8, 0x3c787878, 0x3c787878, 0x3c787878, 0x3c787878, }, | ||
144 | { 0x1c59ec, 0x000000aa, 0x000000aa, 0x000000aa, 0x000000aa, }, | ||
145 | { 0x1c59f0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
146 | { 0x1c59fc, 0x00001042, 0x00001042, 0x00001042, 0x00001042, }, | ||
147 | { 0x1c5a00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
148 | { 0x1c5a04, 0x00000040, 0x00000040, 0x00000040, 0x00000040, }, | ||
149 | { 0x1c5a08, 0x00000080, 0x00000080, 0x00000080, 0x00000080, }, | ||
150 | { 0x1c5a0c, 0x000001a1, 0x000001a1, 0x00000141, 0x00000141, }, | ||
151 | { 0x1c5a10, 0x000001e1, 0x000001e1, 0x00000181, 0x00000181, }, | ||
152 | { 0x1c5a14, 0x00000021, 0x00000021, 0x000001c1, 0x000001c1, }, | ||
153 | { 0x1c5a18, 0x00000061, 0x00000061, 0x00000001, 0x00000001, }, | ||
154 | { 0x1c5a1c, 0x00000168, 0x00000168, 0x00000041, 0x00000041, }, | ||
155 | { 0x1c5a20, 0x000001a8, 0x000001a8, 0x000001a8, 0x000001a8, }, | ||
156 | { 0x1c5a24, 0x000001e8, 0x000001e8, 0x000001e8, 0x000001e8, }, | ||
157 | { 0x1c5a28, 0x00000028, 0x00000028, 0x00000028, 0x00000028, }, | ||
158 | { 0x1c5a2c, 0x00000068, 0x00000068, 0x00000068, 0x00000068, }, | ||
159 | { 0x1c5a30, 0x00000189, 0x00000189, 0x000000a8, 0x000000a8, }, | ||
160 | { 0x1c5a34, 0x000001c9, 0x000001c9, 0x00000169, 0x00000169, }, | ||
161 | { 0x1c5a38, 0x00000009, 0x00000009, 0x000001a9, 0x000001a9, }, | ||
162 | { 0x1c5a3c, 0x00000049, 0x00000049, 0x000001e9, 0x000001e9, }, | ||
163 | { 0x1c5a40, 0x00000089, 0x00000089, 0x00000029, 0x00000029, }, | ||
164 | { 0x1c5a44, 0x00000170, 0x00000170, 0x00000069, 0x00000069, }, | ||
165 | { 0x1c5a48, 0x000001b0, 0x000001b0, 0x00000190, 0x00000190, }, | ||
166 | { 0x1c5a4c, 0x000001f0, 0x000001f0, 0x000001d0, 0x000001d0, }, | ||
167 | { 0x1c5a50, 0x00000030, 0x00000030, 0x00000010, 0x00000010, }, | ||
168 | { 0x1c5a54, 0x00000070, 0x00000070, 0x00000050, 0x00000050, }, | ||
169 | { 0x1c5a58, 0x00000191, 0x00000191, 0x00000090, 0x00000090, }, | ||
170 | { 0x1c5a5c, 0x000001d1, 0x000001d1, 0x00000151, 0x00000151, }, | ||
171 | { 0x1c5a60, 0x00000011, 0x00000011, 0x00000191, 0x00000191, }, | ||
172 | { 0x1c5a64, 0x00000051, 0x00000051, 0x000001d1, 0x000001d1, }, | ||
173 | { 0x1c5a68, 0x00000091, 0x00000091, 0x00000011, 0x00000011, }, | ||
174 | { 0x1c5a6c, 0x000001b8, 0x000001b8, 0x00000051, 0x00000051, }, | ||
175 | { 0x1c5a70, 0x000001f8, 0x000001f8, 0x00000198, 0x00000198, }, | ||
176 | { 0x1c5a74, 0x00000038, 0x00000038, 0x000001d8, 0x000001d8, }, | ||
177 | { 0x1c5a78, 0x00000078, 0x00000078, 0x00000018, 0x00000018, }, | ||
178 | { 0x1c5a7c, 0x00000199, 0x00000199, 0x00000058, 0x00000058, }, | ||
179 | { 0x1c5a80, 0x000001d9, 0x000001d9, 0x00000098, 0x00000098, }, | ||
180 | { 0x1c5a84, 0x00000019, 0x00000019, 0x00000159, 0x00000159, }, | ||
181 | { 0x1c5a88, 0x00000059, 0x00000059, 0x00000199, 0x00000199, }, | ||
182 | { 0x1c5a8c, 0x00000099, 0x00000099, 0x000001d9, 0x000001d9, }, | ||
183 | { 0x1c5a90, 0x000000d9, 0x000000d9, 0x00000019, 0x00000019, }, | ||
184 | { 0x1c5a94, 0x000000f9, 0x000000f9, 0x00000059, 0x00000059, }, | ||
185 | { 0x1c5a98, 0x000000f9, 0x000000f9, 0x00000099, 0x00000099, }, | ||
186 | { 0x1c5a9c, 0x000000f9, 0x000000f9, 0x000000d9, 0x000000d9, }, | ||
187 | { 0x1c5aa0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
188 | { 0x1c5aa4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
189 | { 0x1c5aa8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
190 | { 0x1c5aac, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
191 | { 0x1c5ab0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
192 | { 0x1c5ab4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
193 | { 0x1c5ab8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
194 | { 0x1c5abc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
195 | { 0x1c5ac0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
196 | { 0x1c5ac4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
197 | { 0x1c5ac8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
198 | { 0x1c5acc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
199 | { 0x1c5ad0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
200 | { 0x1c5ad4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
201 | { 0x1c5ad8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
202 | { 0x1c5adc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
203 | { 0x1c5ae0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
204 | { 0x1c5ae4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
205 | { 0x1c5ae8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
206 | { 0x1c5aec, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
207 | { 0x1c5af0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
208 | { 0x1c5af4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
209 | { 0x1c5af8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
210 | { 0x1c5afc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, }, | ||
211 | { 0x1c5b00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
212 | { 0x1c5b04, 0x00000001, 0x00000001, 0x00000001, 0x00000001, }, | ||
213 | { 0x1c5b08, 0x00000002, 0x00000002, 0x00000002, 0x00000002, }, | ||
214 | { 0x1c5b0c, 0x00000003, 0x00000003, 0x00000003, 0x00000003, }, | ||
215 | { 0x1c5b10, 0x00000004, 0x00000004, 0x00000004, 0x00000004, }, | ||
216 | { 0x1c5b14, 0x00000005, 0x00000005, 0x00000005, 0x00000005, }, | ||
217 | { 0x1c5b18, 0x00000008, 0x00000008, 0x00000008, 0x00000008, }, | ||
218 | { 0x1c5b1c, 0x00000009, 0x00000009, 0x00000009, 0x00000009, }, | ||
219 | { 0x1c5b20, 0x0000000a, 0x0000000a, 0x0000000a, 0x0000000a, }, | ||
220 | { 0x1c5b24, 0x0000000b, 0x0000000b, 0x0000000b, 0x0000000b, }, | ||
221 | { 0x1c5b28, 0x0000000c, 0x0000000c, 0x0000000c, 0x0000000c, }, | ||
222 | { 0x1c5b2c, 0x0000000d, 0x0000000d, 0x0000000d, 0x0000000d, }, | ||
223 | { 0x1c5b30, 0x00000010, 0x00000010, 0x00000010, 0x00000010, }, | ||
224 | { 0x1c5b34, 0x00000011, 0x00000011, 0x00000011, 0x00000011, }, | ||
225 | { 0x1c5b38, 0x00000012, 0x00000012, 0x00000012, 0x00000012, }, | ||
226 | { 0x1c5b3c, 0x00000013, 0x00000013, 0x00000013, 0x00000013, }, | ||
227 | { 0x1c5b40, 0x00000014, 0x00000014, 0x00000014, 0x00000014, }, | ||
228 | { 0x1c5b44, 0x00000015, 0x00000015, 0x00000015, 0x00000015, }, | ||
229 | { 0x1c5b48, 0x00000018, 0x00000018, 0x00000018, 0x00000018, }, | ||
230 | { 0x1c5b4c, 0x00000019, 0x00000019, 0x00000019, 0x00000019, }, | ||
231 | { 0x1c5b50, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, }, | ||
232 | { 0x1c5b54, 0x0000001b, 0x0000001b, 0x0000001b, 0x0000001b, }, | ||
233 | { 0x1c5b58, 0x0000001c, 0x0000001c, 0x0000001c, 0x0000001c, }, | ||
234 | { 0x1c5b5c, 0x0000001d, 0x0000001d, 0x0000001d, 0x0000001d, }, | ||
235 | { 0x1c5b60, 0x00000020, 0x00000020, 0x00000020, 0x00000020, }, | ||
236 | { 0x1c5b64, 0x00000021, 0x00000021, 0x00000021, 0x00000021, }, | ||
237 | { 0x1c5b68, 0x00000022, 0x00000022, 0x00000022, 0x00000022, }, | ||
238 | { 0x1c5b6c, 0x00000023, 0x00000023, 0x00000023, 0x00000023, }, | ||
239 | { 0x1c5b70, 0x00000024, 0x00000024, 0x00000024, 0x00000024, }, | ||
240 | { 0x1c5b74, 0x00000025, 0x00000025, 0x00000025, 0x00000025, }, | ||
241 | { 0x1c5b78, 0x00000028, 0x00000028, 0x00000028, 0x00000028, }, | ||
242 | { 0x1c5b7c, 0x00000029, 0x00000029, 0x00000029, 0x00000029, }, | ||
243 | { 0x1c5b80, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, }, | ||
244 | { 0x1c5b84, 0x0000002b, 0x0000002b, 0x0000002b, 0x0000002b, }, | ||
245 | { 0x1c5b88, 0x0000002c, 0x0000002c, 0x0000002c, 0x0000002c, }, | ||
246 | { 0x1c5b8c, 0x0000002d, 0x0000002d, 0x0000002d, 0x0000002d, }, | ||
247 | { 0x1c5b90, 0x00000030, 0x00000030, 0x00000030, 0x00000030, }, | ||
248 | { 0x1c5b94, 0x00000031, 0x00000031, 0x00000031, 0x00000031, }, | ||
249 | { 0x1c5b98, 0x00000032, 0x00000032, 0x00000032, 0x00000032, }, | ||
250 | { 0x1c5b9c, 0x00000033, 0x00000033, 0x00000033, 0x00000033, }, | ||
251 | { 0x1c5ba0, 0x00000034, 0x00000034, 0x00000034, 0x00000034, }, | ||
252 | { 0x1c5ba4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
253 | { 0x1c5ba8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
254 | { 0x1c5bac, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
255 | { 0x1c5bb0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
256 | { 0x1c5bb4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
257 | { 0x1c5bb8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
258 | { 0x1c5bbc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
259 | { 0x1c5bc0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
260 | { 0x1c5bc4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
261 | { 0x1c5bc8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
262 | { 0x1c5bcc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
263 | { 0x1c5bd0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
264 | { 0x1c5bd4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
265 | { 0x1c5bd8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
266 | { 0x1c5bdc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
267 | { 0x1c5be0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
268 | { 0x1c5be4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
269 | { 0x1c5be8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
270 | { 0x1c5bec, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
271 | { 0x1c5bf0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
272 | { 0x1c5bf4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, }, | ||
273 | { 0x1c5bf8, 0x00000010, 0x00000010, 0x00000010, 0x00000010, }, | ||
274 | { 0x1c5bfc, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, }, | ||
275 | { 0x1c5c00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
276 | { 0x1c5c0c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
277 | { 0x1c5c10, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
278 | { 0x1c5c14, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
279 | { 0x1c5c18, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
280 | { 0x1c5c1c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
281 | { 0x1c5c20, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
282 | { 0x1c5c24, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
283 | { 0x1c5c28, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
284 | { 0x1c5c2c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
285 | { 0x1c5c30, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
286 | { 0x1c5c34, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
287 | { 0x1c5c38, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
288 | { 0x1c5c3c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
289 | { 0x1c5cf0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
290 | { 0x1c5cf4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
291 | { 0x1c5cf8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
292 | { 0x1c5cfc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
293 | { 0x1c6200, 0x00000008, 0x00000008, 0x0000000e, 0x0000000e, }, | ||
294 | { 0x1c6204, 0x00000440, 0x00000440, 0x00000440, 0x00000440, }, | ||
295 | { 0x1c6208, 0xd6be4788, 0xd6be4788, 0xd03e4788, 0xd03e4788, }, | ||
296 | { 0x1c620c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, }, | ||
297 | { 0x1c6210, 0x40806333, 0x40806333, 0x40806333, 0x40806333, }, | ||
298 | { 0x1c6214, 0x00106c10, 0x00106c10, 0x00106c10, 0x00106c10, }, | ||
299 | { 0x1c6218, 0x009c4060, 0x009c4060, 0x009c4060, 0x009c4060, }, | ||
300 | { 0x1c621c, 0x1883800a, 0x1883800a, 0x1883800a, 0x1883800a, }, | ||
301 | { 0x1c6220, 0x018830c6, 0x018830c6, 0x018830c6, 0x018830c6, }, | ||
302 | { 0x1c6224, 0x00000400, 0x00000400, 0x00000400, 0x00000400, }, | ||
303 | { 0x1c6228, 0x000009b5, 0x000009b5, 0x000009b5, 0x000009b5, }, | ||
304 | { 0x1c622c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
305 | { 0x1c6230, 0x00000108, 0x00000210, 0x00000210, 0x00000108, }, | ||
306 | { 0x1c6234, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
307 | { 0x1c6238, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
308 | { 0x1c623c, 0x13c889af, 0x13c889af, 0x13c889af, 0x13c889af, }, | ||
309 | { 0x1c6240, 0x38490a20, 0x38490a20, 0x38490a20, 0x38490a20, }, | ||
310 | { 0x1c6244, 0x00007bb6, 0x00007bb6, 0x00007bb6, 0x00007bb6, }, | ||
311 | { 0x1c6248, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, }, | ||
312 | { 0x1c624c, 0x00000001, 0x00000001, 0x00000001, 0x00000001, }, | ||
313 | { 0x1c6250, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, }, | ||
314 | { 0x1c6254, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
315 | { 0x1c6258, 0x0cc75380, 0x0cc75380, 0x0cc75380, 0x0cc75380, }, | ||
316 | { 0x1c625c, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, }, | ||
317 | { 0x1c6260, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, }, | ||
318 | { 0x1c6264, 0x00418a11, 0x00418a11, 0x00418a11, 0x00418a11, }, | ||
319 | { 0x1c6268, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
320 | { 0x1c626c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, }, | ||
321 | { 0x1c6274, 0x0a1a9caa, 0x0a1a9caa, 0x0a1a7caa, 0x0a1a7caa, }, | ||
322 | { 0x1c6278, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, }, | ||
323 | { 0x1c627c, 0x051701ce, 0x051701ce, 0x051701ce, 0x051701ce, }, | ||
324 | { 0x1c6300, 0x18010000, 0x18010000, 0x18010000, 0x18010000, }, | ||
325 | { 0x1c6304, 0x30032602, 0x30032602, 0x2e032402, 0x2e032402, }, | ||
326 | { 0x1c6308, 0x48073e06, 0x48073e06, 0x4a0a3c06, 0x4a0a3c06, }, | ||
327 | { 0x1c630c, 0x560b4c0a, 0x560b4c0a, 0x621a540b, 0x621a540b, }, | ||
328 | { 0x1c6310, 0x641a600f, 0x641a600f, 0x764f6c1b, 0x764f6c1b, }, | ||
329 | { 0x1c6314, 0x7a4f6e1b, 0x7a4f6e1b, 0x845b7a5a, 0x845b7a5a, }, | ||
330 | { 0x1c6318, 0x8c5b7e5a, 0x8c5b7e5a, 0x950f8ccf, 0x950f8ccf, }, | ||
331 | { 0x1c631c, 0x9d0f96cf, 0x9d0f96cf, 0xa5cf9b4f, 0xa5cf9b4f, }, | ||
332 | { 0x1c6320, 0xb51fa69f, 0xb51fa69f, 0xbddfaf1f, 0xbddfaf1f, }, | ||
333 | { 0x1c6324, 0xcb3fbd07, 0xcb3fbcbf, 0xd1ffc93f, 0xd1ffc93f, }, | ||
334 | { 0x1c6328, 0x0000d7bf, 0x0000d7bf, 0x00000000, 0x00000000, }, | ||
335 | { 0x1c632c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
336 | { 0x1c6330, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
337 | { 0x1c6334, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
338 | { 0x1c6338, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
339 | { 0x1c633c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
340 | { 0x1c6340, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
341 | { 0x1c6344, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
342 | { 0x1c6348, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, }, | ||
343 | { 0x1c634c, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, }, | ||
344 | { 0x1c6350, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, }, | ||
345 | { 0x1c6354, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, }, | ||
346 | { 0x1c6358, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, }, | ||
347 | { 0x1c6388, 0x08000000, 0x08000000, 0x08000000, 0x08000000, }, | ||
348 | { 0x1c638c, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
349 | { 0x1c6390, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
350 | { 0x1c6394, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, }, | ||
351 | { 0x1c6398, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce, }, | ||
352 | { 0x1c639c, 0x00000007, 0x00000007, 0x00000007, 0x00000007, }, | ||
353 | { 0x1c63a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
354 | { 0x1c63a4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
355 | { 0x1c63a8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
356 | { 0x1c63ac, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
357 | { 0x1c63b0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
358 | { 0x1c63b4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
359 | { 0x1c63b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
360 | { 0x1c63bc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
361 | { 0x1c63c0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
362 | { 0x1c63c4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
363 | { 0x1c63c8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
364 | { 0x1c63cc, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
365 | { 0x1c63d0, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
366 | { 0x1c63d4, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, }, | ||
367 | { 0x1c63d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, | ||
368 | { 0x1c63dc, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, }, | ||
369 | { 0x1c63e0, 0x000000c0, 0x000000c0, 0x000000c0, 0x000000c0, }, | ||
370 | { 0x1c6848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, }, | ||
371 | { 0x1c6920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, }, | ||
372 | { 0x1c6960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, }, | ||
373 | { 0x1c720c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, }, | ||
374 | { 0x1c726c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, }, | ||
375 | { 0x1c7848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, }, | ||
376 | { 0x1c7920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, }, | ||
377 | { 0x1c7960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, }, | ||
378 | { 0x1c820c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, }, | ||
379 | { 0x1c826c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, }, | ||
380 | /* { 0x1c8864, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, }, */ | ||
381 | { 0x1c8864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, }, | ||
382 | { 0x1c895c, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, }, | ||
383 | { 0x1c8968, 0x000003ce, 0x000003ce, 0x000003ce, 0x000003ce, }, | ||
384 | { 0x1c89bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, }, | ||
385 | { 0x1c9270, 0x00820820, 0x00820820, 0x00820820, 0x00820820, }, | ||
386 | { 0x1c935c, 0x066c420f, 0x066c420f, 0x066c420f, 0x066c420f, }, | ||
387 | { 0x1c9360, 0x0f282207, 0x0f282207, 0x0f282207, 0x0f282207, }, | ||
388 | { 0x1c9364, 0x17601685, 0x17601685, 0x17601685, 0x17601685, }, | ||
389 | { 0x1c9368, 0x1f801104, 0x1f801104, 0x1f801104, 0x1f801104, }, | ||
390 | { 0x1c936c, 0x37a00c03, 0x37a00c03, 0x37a00c03, 0x37a00c03, }, | ||
391 | { 0x1c9370, 0x3fc40883, 0x3fc40883, 0x3fc40883, 0x3fc40883, }, | ||
392 | { 0x1c9374, 0x57c00803, 0x57c00803, 0x57c00803, 0x57c00803, }, | ||
393 | { 0x1c9378, 0x5fd80682, 0x5fd80682, 0x5fd80682, 0x5fd80682, }, | ||
394 | { 0x1c937c, 0x7fe00482, 0x7fe00482, 0x7fe00482, 0x7fe00482, }, | ||
395 | { 0x1c9380, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, }, | ||
396 | { 0x1c9384, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, } | ||
397 | }; | ||
398 | |||
399 | int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band) | ||
400 | { | ||
401 | int i, err; | ||
402 | u32 val; | ||
403 | bool is_2ghz = band == IEEE80211_BAND_2GHZ; | ||
404 | bool is_40mhz = false; /* XXX: for now */ | ||
405 | |||
406 | ar9170_regwrite_begin(ar); | ||
407 | |||
408 | for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) { | ||
409 | if (is_40mhz) { | ||
410 | if (is_2ghz) | ||
411 | val = ar5416_phy_init[i]._2ghz_40; | ||
412 | else | ||
413 | val = ar5416_phy_init[i]._5ghz_40; | ||
414 | } else { | ||
415 | if (is_2ghz) | ||
416 | val = ar5416_phy_init[i]._2ghz_20; | ||
417 | else | ||
418 | val = ar5416_phy_init[i]._5ghz_20; | ||
419 | } | ||
420 | |||
421 | ar9170_regwrite(ar5416_phy_init[i].reg, val); | ||
422 | } | ||
423 | |||
424 | ar9170_regwrite_finish(); | ||
425 | err = ar9170_regwrite_result(); | ||
426 | if (err) | ||
427 | return err; | ||
428 | |||
429 | /* XXX: use EEPROM data here! */ | ||
430 | |||
431 | err = ar9170_init_power_cal(ar); | ||
432 | if (err) | ||
433 | return err; | ||
434 | |||
435 | /* XXX: remove magic! */ | ||
436 | if (is_2ghz) | ||
437 | err = ar9170_write_reg(ar, 0x1d4014, 0x5163); | ||
438 | else | ||
439 | err = ar9170_write_reg(ar, 0x1d4014, 0x5143); | ||
440 | |||
441 | return err; | ||
442 | } | ||
443 | |||
444 | struct ar9170_rf_init { | ||
445 | u32 reg, _5ghz, _2ghz; | ||
446 | }; | ||
447 | |||
448 | static struct ar9170_rf_init ar9170_rf_init[] = { | ||
449 | /* bank 0 */ | ||
450 | { 0x1c58b0, 0x1e5795e5, 0x1e5795e5}, | ||
451 | { 0x1c58e0, 0x02008020, 0x02008020}, | ||
452 | /* bank 1 */ | ||
453 | { 0x1c58b0, 0x02108421, 0x02108421}, | ||
454 | { 0x1c58ec, 0x00000008, 0x00000008}, | ||
455 | /* bank 2 */ | ||
456 | { 0x1c58b0, 0x0e73ff17, 0x0e73ff17}, | ||
457 | { 0x1c58e0, 0x00000420, 0x00000420}, | ||
458 | /* bank 3 */ | ||
459 | { 0x1c58f0, 0x01400018, 0x01c00018}, | ||
460 | /* bank 4 */ | ||
461 | { 0x1c58b0, 0x000001a1, 0x000001a1}, | ||
462 | { 0x1c58e8, 0x00000001, 0x00000001}, | ||
463 | /* bank 5 */ | ||
464 | { 0x1c58b0, 0x00000013, 0x00000013}, | ||
465 | { 0x1c58e4, 0x00000002, 0x00000002}, | ||
466 | /* bank 6 */ | ||
467 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
468 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
469 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
470 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
471 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
472 | { 0x1c58b0, 0x00004000, 0x00004000}, | ||
473 | { 0x1c58b0, 0x00006c00, 0x00006c00}, | ||
474 | { 0x1c58b0, 0x00002c00, 0x00002c00}, | ||
475 | { 0x1c58b0, 0x00004800, 0x00004800}, | ||
476 | { 0x1c58b0, 0x00004000, 0x00004000}, | ||
477 | { 0x1c58b0, 0x00006000, 0x00006000}, | ||
478 | { 0x1c58b0, 0x00001000, 0x00001000}, | ||
479 | { 0x1c58b0, 0x00004000, 0x00004000}, | ||
480 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
481 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
482 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
483 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
484 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
485 | { 0x1c58b0, 0x00087c00, 0x00087c00}, | ||
486 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
487 | { 0x1c58b0, 0x00005400, 0x00005400}, | ||
488 | { 0x1c58b0, 0x00000c00, 0x00000c00}, | ||
489 | { 0x1c58b0, 0x00001800, 0x00001800}, | ||
490 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
491 | { 0x1c58b0, 0x00006c00, 0x00006c00}, | ||
492 | { 0x1c58b0, 0x00006c00, 0x00006c00}, | ||
493 | { 0x1c58b0, 0x00007c00, 0x00007c00}, | ||
494 | { 0x1c58b0, 0x00002c00, 0x00002c00}, | ||
495 | { 0x1c58b0, 0x00003c00, 0x00003c00}, | ||
496 | { 0x1c58b0, 0x00003800, 0x00003800}, | ||
497 | { 0x1c58b0, 0x00001c00, 0x00001c00}, | ||
498 | { 0x1c58b0, 0x00000800, 0x00000800}, | ||
499 | { 0x1c58b0, 0x00000408, 0x00000408}, | ||
500 | { 0x1c58b0, 0x00004c15, 0x00004c15}, | ||
501 | { 0x1c58b0, 0x00004188, 0x00004188}, | ||
502 | { 0x1c58b0, 0x0000201e, 0x0000201e}, | ||
503 | { 0x1c58b0, 0x00010408, 0x00010408}, | ||
504 | { 0x1c58b0, 0x00000801, 0x00000801}, | ||
505 | { 0x1c58b0, 0x00000c08, 0x00000c08}, | ||
506 | { 0x1c58b0, 0x0000181e, 0x0000181e}, | ||
507 | { 0x1c58b0, 0x00001016, 0x00001016}, | ||
508 | { 0x1c58b0, 0x00002800, 0x00002800}, | ||
509 | { 0x1c58b0, 0x00004010, 0x00004010}, | ||
510 | { 0x1c58b0, 0x0000081c, 0x0000081c}, | ||
511 | { 0x1c58b0, 0x00000115, 0x00000115}, | ||
512 | { 0x1c58b0, 0x00000015, 0x00000015}, | ||
513 | { 0x1c58b0, 0x00000066, 0x00000066}, | ||
514 | { 0x1c58b0, 0x0000001c, 0x0000001c}, | ||
515 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
516 | { 0x1c58b0, 0x00000004, 0x00000004}, | ||
517 | { 0x1c58b0, 0x00000015, 0x00000015}, | ||
518 | { 0x1c58b0, 0x0000001f, 0x0000001f}, | ||
519 | { 0x1c58e0, 0x00000000, 0x00000400}, | ||
520 | /* bank 7 */ | ||
521 | { 0x1c58b0, 0x000000a0, 0x000000a0}, | ||
522 | { 0x1c58b0, 0x00000000, 0x00000000}, | ||
523 | { 0x1c58b0, 0x00000040, 0x00000040}, | ||
524 | { 0x1c58f0, 0x0000001c, 0x0000001c}, | ||
525 | }; | ||
526 | |||
527 | static int ar9170_init_rf_banks_0_7(struct ar9170 *ar, bool band5ghz) | ||
528 | { | ||
529 | int err, i; | ||
530 | |||
531 | ar9170_regwrite_begin(ar); | ||
532 | |||
533 | for (i = 0; i < ARRAY_SIZE(ar9170_rf_init); i++) | ||
534 | ar9170_regwrite(ar9170_rf_init[i].reg, | ||
535 | band5ghz ? ar9170_rf_init[i]._5ghz | ||
536 | : ar9170_rf_init[i]._2ghz); | ||
537 | |||
538 | ar9170_regwrite_finish(); | ||
539 | err = ar9170_regwrite_result(); | ||
540 | if (err) | ||
541 | printk(KERN_ERR "%s: rf init failed\n", | ||
542 | wiphy_name(ar->hw->wiphy)); | ||
543 | return err; | ||
544 | } | ||
545 | |||
546 | static int ar9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz, | ||
547 | u32 freq, enum ar9170_bw bw) | ||
548 | { | ||
549 | int err; | ||
550 | u32 d0, d1, td0, td1, fd0, fd1; | ||
551 | u8 chansel; | ||
552 | u8 refsel0 = 1, refsel1 = 0; | ||
553 | u8 lf_synth = 0; | ||
554 | |||
555 | switch (bw) { | ||
556 | case AR9170_BW_40_ABOVE: | ||
557 | freq += 10; | ||
558 | break; | ||
559 | case AR9170_BW_40_BELOW: | ||
560 | freq -= 10; | ||
561 | break; | ||
562 | case AR9170_BW_20: | ||
563 | break; | ||
564 | case __AR9170_NUM_BW: | ||
565 | BUG(); | ||
566 | } | ||
567 | |||
568 | if (band5ghz) { | ||
569 | if (freq % 10) { | ||
570 | chansel = (freq - 4800) / 5; | ||
571 | } else { | ||
572 | chansel = ((freq - 4800) / 10) * 2; | ||
573 | refsel0 = 0; | ||
574 | refsel1 = 1; | ||
575 | } | ||
576 | chansel = byte_rev_table[chansel]; | ||
577 | } else { | ||
578 | if (freq == 2484) { | ||
579 | chansel = 10 + (freq - 2274) / 5; | ||
580 | lf_synth = 1; | ||
581 | } else | ||
582 | chansel = 16 + (freq - 2272) / 5; | ||
583 | chansel *= 4; | ||
584 | chansel = byte_rev_table[chansel]; | ||
585 | } | ||
586 | |||
587 | d1 = chansel; | ||
588 | d0 = 0x21 | | ||
589 | refsel0 << 3 | | ||
590 | refsel1 << 2 | | ||
591 | lf_synth << 1; | ||
592 | td0 = d0 & 0x1f; | ||
593 | td1 = d1 & 0x1f; | ||
594 | fd0 = td1 << 5 | td0; | ||
595 | |||
596 | td0 = (d0 >> 5) & 0x7; | ||
597 | td1 = (d1 >> 5) & 0x7; | ||
598 | fd1 = td1 << 5 | td0; | ||
599 | |||
600 | ar9170_regwrite_begin(ar); | ||
601 | |||
602 | ar9170_regwrite(0x1c58b0, fd0); | ||
603 | ar9170_regwrite(0x1c58e8, fd1); | ||
604 | |||
605 | ar9170_regwrite_finish(); | ||
606 | err = ar9170_regwrite_result(); | ||
607 | if (err) | ||
608 | return err; | ||
609 | |||
610 | msleep(10); | ||
611 | |||
612 | return 0; | ||
613 | } | ||
614 | |||
615 | struct ar9170_phy_freq_params { | ||
616 | u8 coeff_exp; | ||
617 | u16 coeff_man; | ||
618 | u8 coeff_exp_shgi; | ||
619 | u16 coeff_man_shgi; | ||
620 | }; | ||
621 | |||
622 | struct ar9170_phy_freq_entry { | ||
623 | u16 freq; | ||
624 | struct ar9170_phy_freq_params params[__AR9170_NUM_BW]; | ||
625 | }; | ||
626 | |||
627 | /* NB: must be in sync with channel tables in main! */ | ||
628 | static const struct ar9170_phy_freq_entry ar9170_phy_freq_params[] = { | ||
629 | /* | ||
630 | * freq, | ||
631 | * 20MHz, | ||
632 | * 40MHz (below), | ||
633 | * 40Mhz (above), | ||
634 | */ | ||
635 | { 2412, { | ||
636 | { 3, 21737, 3, 19563, }, | ||
637 | { 3, 21827, 3, 19644, }, | ||
638 | { 3, 21647, 3, 19482, }, | ||
639 | } }, | ||
640 | { 2417, { | ||
641 | { 3, 21692, 3, 19523, }, | ||
642 | { 3, 21782, 3, 19604, }, | ||
643 | { 3, 21602, 3, 19442, }, | ||
644 | } }, | ||
645 | { 2422, { | ||
646 | { 3, 21647, 3, 19482, }, | ||
647 | { 3, 21737, 3, 19563, }, | ||
648 | { 3, 21558, 3, 19402, }, | ||
649 | } }, | ||
650 | { 2427, { | ||
651 | { 3, 21602, 3, 19442, }, | ||
652 | { 3, 21692, 3, 19523, }, | ||
653 | { 3, 21514, 3, 19362, }, | ||
654 | } }, | ||
655 | { 2432, { | ||
656 | { 3, 21558, 3, 19402, }, | ||
657 | { 3, 21647, 3, 19482, }, | ||
658 | { 3, 21470, 3, 19323, }, | ||
659 | } }, | ||
660 | { 2437, { | ||
661 | { 3, 21514, 3, 19362, }, | ||
662 | { 3, 21602, 3, 19442, }, | ||
663 | { 3, 21426, 3, 19283, }, | ||
664 | } }, | ||
665 | { 2442, { | ||
666 | { 3, 21470, 3, 19323, }, | ||
667 | { 3, 21558, 3, 19402, }, | ||
668 | { 3, 21382, 3, 19244, }, | ||
669 | } }, | ||
670 | { 2447, { | ||
671 | { 3, 21426, 3, 19283, }, | ||
672 | { 3, 21514, 3, 19362, }, | ||
673 | { 3, 21339, 3, 19205, }, | ||
674 | } }, | ||
675 | { 2452, { | ||
676 | { 3, 21382, 3, 19244, }, | ||
677 | { 3, 21470, 3, 19323, }, | ||
678 | { 3, 21295, 3, 19166, }, | ||
679 | } }, | ||
680 | { 2457, { | ||
681 | { 3, 21339, 3, 19205, }, | ||
682 | { 3, 21426, 3, 19283, }, | ||
683 | { 3, 21252, 3, 19127, }, | ||
684 | } }, | ||
685 | { 2462, { | ||
686 | { 3, 21295, 3, 19166, }, | ||
687 | { 3, 21382, 3, 19244, }, | ||
688 | { 3, 21209, 3, 19088, }, | ||
689 | } }, | ||
690 | { 2467, { | ||
691 | { 3, 21252, 3, 19127, }, | ||
692 | { 3, 21339, 3, 19205, }, | ||
693 | { 3, 21166, 3, 19050, }, | ||
694 | } }, | ||
695 | { 2472, { | ||
696 | { 3, 21209, 3, 19088, }, | ||
697 | { 3, 21295, 3, 19166, }, | ||
698 | { 3, 21124, 3, 19011, }, | ||
699 | } }, | ||
700 | { 2484, { | ||
701 | { 3, 21107, 3, 18996, }, | ||
702 | { 3, 21192, 3, 19073, }, | ||
703 | { 3, 21022, 3, 18920, }, | ||
704 | } }, | ||
705 | { 4920, { | ||
706 | { 4, 21313, 4, 19181, }, | ||
707 | { 4, 21356, 4, 19220, }, | ||
708 | { 4, 21269, 4, 19142, }, | ||
709 | } }, | ||
710 | { 4940, { | ||
711 | { 4, 21226, 4, 19104, }, | ||
712 | { 4, 21269, 4, 19142, }, | ||
713 | { 4, 21183, 4, 19065, }, | ||
714 | } }, | ||
715 | { 4960, { | ||
716 | { 4, 21141, 4, 19027, }, | ||
717 | { 4, 21183, 4, 19065, }, | ||
718 | { 4, 21098, 4, 18988, }, | ||
719 | } }, | ||
720 | { 4980, { | ||
721 | { 4, 21056, 4, 18950, }, | ||
722 | { 4, 21098, 4, 18988, }, | ||
723 | { 4, 21014, 4, 18912, }, | ||
724 | } }, | ||
725 | { 5040, { | ||
726 | { 4, 20805, 4, 18725, }, | ||
727 | { 4, 20846, 4, 18762, }, | ||
728 | { 4, 20764, 4, 18687, }, | ||
729 | } }, | ||
730 | { 5060, { | ||
731 | { 4, 20723, 4, 18651, }, | ||
732 | { 4, 20764, 4, 18687, }, | ||
733 | { 4, 20682, 4, 18614, }, | ||
734 | } }, | ||
735 | { 5080, { | ||
736 | { 4, 20641, 4, 18577, }, | ||
737 | { 4, 20682, 4, 18614, }, | ||
738 | { 4, 20601, 4, 18541, }, | ||
739 | } }, | ||
740 | { 5180, { | ||
741 | { 4, 20243, 4, 18219, }, | ||
742 | { 4, 20282, 4, 18254, }, | ||
743 | { 4, 20204, 4, 18183, }, | ||
744 | } }, | ||
745 | { 5200, { | ||
746 | { 4, 20165, 4, 18148, }, | ||
747 | { 4, 20204, 4, 18183, }, | ||
748 | { 4, 20126, 4, 18114, }, | ||
749 | } }, | ||
750 | { 5220, { | ||
751 | { 4, 20088, 4, 18079, }, | ||
752 | { 4, 20126, 4, 18114, }, | ||
753 | { 4, 20049, 4, 18044, }, | ||
754 | } }, | ||
755 | { 5240, { | ||
756 | { 4, 20011, 4, 18010, }, | ||
757 | { 4, 20049, 4, 18044, }, | ||
758 | { 4, 19973, 4, 17976, }, | ||
759 | } }, | ||
760 | { 5260, { | ||
761 | { 4, 19935, 4, 17941, }, | ||
762 | { 4, 19973, 4, 17976, }, | ||
763 | { 4, 19897, 4, 17907, }, | ||
764 | } }, | ||
765 | { 5280, { | ||
766 | { 4, 19859, 4, 17873, }, | ||
767 | { 4, 19897, 4, 17907, }, | ||
768 | { 4, 19822, 4, 17840, }, | ||
769 | } }, | ||
770 | { 5300, { | ||
771 | { 4, 19784, 4, 17806, }, | ||
772 | { 4, 19822, 4, 17840, }, | ||
773 | { 4, 19747, 4, 17772, }, | ||
774 | } }, | ||
775 | { 5320, { | ||
776 | { 4, 19710, 4, 17739, }, | ||
777 | { 4, 19747, 4, 17772, }, | ||
778 | { 4, 19673, 4, 17706, }, | ||
779 | } }, | ||
780 | { 5500, { | ||
781 | { 4, 19065, 4, 17159, }, | ||
782 | { 4, 19100, 4, 17190, }, | ||
783 | { 4, 19030, 4, 17127, }, | ||
784 | } }, | ||
785 | { 5520, { | ||
786 | { 4, 18996, 4, 17096, }, | ||
787 | { 4, 19030, 4, 17127, }, | ||
788 | { 4, 18962, 4, 17065, }, | ||
789 | } }, | ||
790 | { 5540, { | ||
791 | { 4, 18927, 4, 17035, }, | ||
792 | { 4, 18962, 4, 17065, }, | ||
793 | { 4, 18893, 4, 17004, }, | ||
794 | } }, | ||
795 | { 5560, { | ||
796 | { 4, 18859, 4, 16973, }, | ||
797 | { 4, 18893, 4, 17004, }, | ||
798 | { 4, 18825, 4, 16943, }, | ||
799 | } }, | ||
800 | { 5580, { | ||
801 | { 4, 18792, 4, 16913, }, | ||
802 | { 4, 18825, 4, 16943, }, | ||
803 | { 4, 18758, 4, 16882, }, | ||
804 | } }, | ||
805 | { 5600, { | ||
806 | { 4, 18725, 4, 16852, }, | ||
807 | { 4, 18758, 4, 16882, }, | ||
808 | { 4, 18691, 4, 16822, }, | ||
809 | } }, | ||
810 | { 5620, { | ||
811 | { 4, 18658, 4, 16792, }, | ||
812 | { 4, 18691, 4, 16822, }, | ||
813 | { 4, 18625, 4, 16762, }, | ||
814 | } }, | ||
815 | { 5640, { | ||
816 | { 4, 18592, 4, 16733, }, | ||
817 | { 4, 18625, 4, 16762, }, | ||
818 | { 4, 18559, 4, 16703, }, | ||
819 | } }, | ||
820 | { 5660, { | ||
821 | { 4, 18526, 4, 16673, }, | ||
822 | { 4, 18559, 4, 16703, }, | ||
823 | { 4, 18493, 4, 16644, }, | ||
824 | } }, | ||
825 | { 5680, { | ||
826 | { 4, 18461, 4, 16615, }, | ||
827 | { 4, 18493, 4, 16644, }, | ||
828 | { 4, 18428, 4, 16586, }, | ||
829 | } }, | ||
830 | { 5700, { | ||
831 | { 4, 18396, 4, 16556, }, | ||
832 | { 4, 18428, 4, 16586, }, | ||
833 | { 4, 18364, 4, 16527, }, | ||
834 | } }, | ||
835 | { 5745, { | ||
836 | { 4, 18252, 4, 16427, }, | ||
837 | { 4, 18284, 4, 16455, }, | ||
838 | { 4, 18220, 4, 16398, }, | ||
839 | } }, | ||
840 | { 5765, { | ||
841 | { 4, 18189, 5, 32740, }, | ||
842 | { 4, 18220, 4, 16398, }, | ||
843 | { 4, 18157, 5, 32683, }, | ||
844 | } }, | ||
845 | { 5785, { | ||
846 | { 4, 18126, 5, 32626, }, | ||
847 | { 4, 18157, 5, 32683, }, | ||
848 | { 4, 18094, 5, 32570, }, | ||
849 | } }, | ||
850 | { 5805, { | ||
851 | { 4, 18063, 5, 32514, }, | ||
852 | { 4, 18094, 5, 32570, }, | ||
853 | { 4, 18032, 5, 32458, }, | ||
854 | } }, | ||
855 | { 5825, { | ||
856 | { 4, 18001, 5, 32402, }, | ||
857 | { 4, 18032, 5, 32458, }, | ||
858 | { 4, 17970, 5, 32347, }, | ||
859 | } }, | ||
860 | { 5170, { | ||
861 | { 4, 20282, 4, 18254, }, | ||
862 | { 4, 20321, 4, 18289, }, | ||
863 | { 4, 20243, 4, 18219, }, | ||
864 | } }, | ||
865 | { 5190, { | ||
866 | { 4, 20204, 4, 18183, }, | ||
867 | { 4, 20243, 4, 18219, }, | ||
868 | { 4, 20165, 4, 18148, }, | ||
869 | } }, | ||
870 | { 5210, { | ||
871 | { 4, 20126, 4, 18114, }, | ||
872 | { 4, 20165, 4, 18148, }, | ||
873 | { 4, 20088, 4, 18079, }, | ||
874 | } }, | ||
875 | { 5230, { | ||
876 | { 4, 20049, 4, 18044, }, | ||
877 | { 4, 20088, 4, 18079, }, | ||
878 | { 4, 20011, 4, 18010, }, | ||
879 | } }, | ||
880 | }; | ||
881 | |||
882 | static const struct ar9170_phy_freq_params * | ||
883 | ar9170_get_hw_dyn_params(struct ieee80211_channel *channel, | ||
884 | enum ar9170_bw bw) | ||
885 | { | ||
886 | unsigned int chanidx = 0; | ||
887 | u16 freq = 2412; | ||
888 | |||
889 | if (channel) { | ||
890 | chanidx = channel->hw_value; | ||
891 | freq = channel->center_freq; | ||
892 | } | ||
893 | |||
894 | BUG_ON(chanidx >= ARRAY_SIZE(ar9170_phy_freq_params)); | ||
895 | |||
896 | BUILD_BUG_ON(__AR9170_NUM_BW != 3); | ||
897 | |||
898 | WARN_ON(ar9170_phy_freq_params[chanidx].freq != freq); | ||
899 | |||
900 | return &ar9170_phy_freq_params[chanidx].params[bw]; | ||
901 | } | ||
902 | |||
903 | |||
904 | int ar9170_init_rf(struct ar9170 *ar) | ||
905 | { | ||
906 | const struct ar9170_phy_freq_params *freqpar; | ||
907 | __le32 cmd[7]; | ||
908 | int err; | ||
909 | |||
910 | err = ar9170_init_rf_banks_0_7(ar, false); | ||
911 | if (err) | ||
912 | return err; | ||
913 | |||
914 | err = ar9170_init_rf_bank4_pwr(ar, false, 2412, AR9170_BW_20); | ||
915 | if (err) | ||
916 | return err; | ||
917 | |||
918 | freqpar = ar9170_get_hw_dyn_params(NULL, AR9170_BW_20); | ||
919 | |||
920 | cmd[0] = cpu_to_le32(2412 * 1000); | ||
921 | cmd[1] = cpu_to_le32(0); | ||
922 | cmd[2] = cpu_to_le32(1); | ||
923 | cmd[3] = cpu_to_le32(freqpar->coeff_exp); | ||
924 | cmd[4] = cpu_to_le32(freqpar->coeff_man); | ||
925 | cmd[5] = cpu_to_le32(freqpar->coeff_exp_shgi); | ||
926 | cmd[6] = cpu_to_le32(freqpar->coeff_man_shgi); | ||
927 | |||
928 | /* RF_INIT echoes the command back to us */ | ||
929 | err = ar->exec_cmd(ar, AR9170_CMD_RF_INIT, | ||
930 | sizeof(cmd), (u8 *)cmd, | ||
931 | sizeof(cmd), (u8 *)cmd); | ||
932 | if (err) | ||
933 | return err; | ||
934 | |||
935 | msleep(1000); | ||
936 | |||
937 | return ar9170_echo_test(ar, 0xaabbccdd); | ||
938 | } | ||
939 | |||
940 | static int ar9170_find_freq_idx(int nfreqs, u8 *freqs, u8 f) | ||
941 | { | ||
942 | int idx = nfreqs - 2; | ||
943 | |||
944 | while (idx >= 0) { | ||
945 | if (f >= freqs[idx]) | ||
946 | return idx; | ||
947 | idx--; | ||
948 | } | ||
949 | |||
950 | return 0; | ||
951 | } | ||
952 | |||
953 | static s32 ar9170_interpolate_s32(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) | ||
954 | { | ||
955 | /* nothing to interpolate, it's horizontal */ | ||
956 | if (y2 == y1) | ||
957 | return y1; | ||
958 | |||
959 | /* check if we hit one of the edges */ | ||
960 | if (x == x1) | ||
961 | return y1; | ||
962 | if (x == x2) | ||
963 | return y2; | ||
964 | |||
965 | /* x1 == x2 is bad, hopefully == x */ | ||
966 | if (x2 == x1) | ||
967 | return y1; | ||
968 | |||
969 | return y1 + (((y2 - y1) * (x - x1)) / (x2 - x1)); | ||
970 | } | ||
971 | |||
972 | static u8 ar9170_interpolate_u8(u8 x, u8 x1, u8 y1, u8 x2, u8 y2) | ||
973 | { | ||
974 | #define SHIFT 8 | ||
975 | s32 y; | ||
976 | |||
977 | y = ar9170_interpolate_s32(x << SHIFT, | ||
978 | x1 << SHIFT, y1 << SHIFT, | ||
979 | x2 << SHIFT, y2 << SHIFT); | ||
980 | |||
981 | /* | ||
982 | * XXX: unwrap this expression | ||
983 | * Isn't it just DIV_ROUND_UP(y, 1<<SHIFT)? | ||
984 | * Can we rely on the compiler to optimise away the div? | ||
985 | */ | ||
986 | return (y >> SHIFT) + ((y & (1<<(SHIFT-1))) >> (SHIFT - 1)); | ||
987 | #undef SHIFT | ||
988 | } | ||
989 | |||
990 | static int ar9170_set_power_cal(struct ar9170 *ar, u32 freq, enum ar9170_bw bw) | ||
991 | { | ||
992 | struct ar9170_calibration_target_power_legacy *ctpl; | ||
993 | struct ar9170_calibration_target_power_ht *ctph; | ||
994 | u8 *ctpres; | ||
995 | int ntargets; | ||
996 | int idx, i, n; | ||
997 | u8 ackpower, ackchains, f; | ||
998 | u8 pwr_freqs[AR5416_MAX_NUM_TGT_PWRS]; | ||
999 | |||
1000 | if (freq < 3000) | ||
1001 | f = freq - 2300; | ||
1002 | else | ||
1003 | f = (freq - 4800)/5; | ||
1004 | |||
1005 | /* | ||
1006 | * cycle through the various modes | ||
1007 | * | ||
1008 | * legacy modes first: 5G, 2G CCK, 2G OFDM | ||
1009 | */ | ||
1010 | for (i = 0; i < 3; i++) { | ||
1011 | switch (i) { | ||
1012 | case 0: /* 5 GHz legacy */ | ||
1013 | ctpl = &ar->eeprom.cal_tgt_pwr_5G[0]; | ||
1014 | ntargets = AR5416_NUM_5G_TARGET_PWRS; | ||
1015 | ctpres = ar->power_5G_leg; | ||
1016 | break; | ||
1017 | case 1: /* 2.4 GHz CCK */ | ||
1018 | ctpl = &ar->eeprom.cal_tgt_pwr_2G_cck[0]; | ||
1019 | ntargets = AR5416_NUM_2G_CCK_TARGET_PWRS; | ||
1020 | ctpres = ar->power_2G_cck; | ||
1021 | break; | ||
1022 | case 2: /* 2.4 GHz OFDM */ | ||
1023 | ctpl = &ar->eeprom.cal_tgt_pwr_2G_ofdm[0]; | ||
1024 | ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS; | ||
1025 | ctpres = ar->power_2G_ofdm; | ||
1026 | break; | ||
1027 | default: | ||
1028 | BUG(); | ||
1029 | } | ||
1030 | |||
1031 | for (n = 0; n < ntargets; n++) { | ||
1032 | if (ctpl[n].freq == 0xff) | ||
1033 | break; | ||
1034 | pwr_freqs[n] = ctpl[n].freq; | ||
1035 | } | ||
1036 | ntargets = n; | ||
1037 | idx = ar9170_find_freq_idx(ntargets, pwr_freqs, f); | ||
1038 | for (n = 0; n < 4; n++) | ||
1039 | ctpres[n] = ar9170_interpolate_u8( | ||
1040 | f, | ||
1041 | ctpl[idx + 0].freq, | ||
1042 | ctpl[idx + 0].power[n], | ||
1043 | ctpl[idx + 1].freq, | ||
1044 | ctpl[idx + 1].power[n]); | ||
1045 | } | ||
1046 | |||
1047 | /* | ||
1048 | * HT modes now: 5G HT20, 5G HT40, 2G CCK, 2G OFDM, 2G HT20, 2G HT40 | ||
1049 | */ | ||
1050 | for (i = 0; i < 4; i++) { | ||
1051 | switch (i) { | ||
1052 | case 0: /* 5 GHz HT 20 */ | ||
1053 | ctph = &ar->eeprom.cal_tgt_pwr_5G_ht20[0]; | ||
1054 | ntargets = AR5416_NUM_5G_TARGET_PWRS; | ||
1055 | ctpres = ar->power_5G_ht20; | ||
1056 | break; | ||
1057 | case 1: /* 5 GHz HT 40 */ | ||
1058 | ctph = &ar->eeprom.cal_tgt_pwr_5G_ht40[0]; | ||
1059 | ntargets = AR5416_NUM_5G_TARGET_PWRS; | ||
1060 | ctpres = ar->power_5G_ht40; | ||
1061 | break; | ||
1062 | case 2: /* 2.4 GHz HT 20 */ | ||
1063 | ctph = &ar->eeprom.cal_tgt_pwr_2G_ht20[0]; | ||
1064 | ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS; | ||
1065 | ctpres = ar->power_2G_ht20; | ||
1066 | break; | ||
1067 | case 3: /* 2.4 GHz HT 40 */ | ||
1068 | ctph = &ar->eeprom.cal_tgt_pwr_2G_ht40[0]; | ||
1069 | ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS; | ||
1070 | ctpres = ar->power_2G_ht40; | ||
1071 | break; | ||
1072 | default: | ||
1073 | BUG(); | ||
1074 | } | ||
1075 | |||
1076 | for (n = 0; n < ntargets; n++) { | ||
1077 | if (ctph[n].freq == 0xff) | ||
1078 | break; | ||
1079 | pwr_freqs[n] = ctph[n].freq; | ||
1080 | } | ||
1081 | ntargets = n; | ||
1082 | idx = ar9170_find_freq_idx(ntargets, pwr_freqs, f); | ||
1083 | for (n = 0; n < 8; n++) | ||
1084 | ctpres[n] = ar9170_interpolate_u8( | ||
1085 | f, | ||
1086 | ctph[idx + 0].freq, | ||
1087 | ctph[idx + 0].power[n], | ||
1088 | ctph[idx + 1].freq, | ||
1089 | ctph[idx + 1].power[n]); | ||
1090 | } | ||
1091 | |||
1092 | /* set ACK/CTS TX power */ | ||
1093 | ar9170_regwrite_begin(ar); | ||
1094 | |||
1095 | if (ar->eeprom.tx_mask != 1) | ||
1096 | ackchains = AR9170_TX_PHY_TXCHAIN_2; | ||
1097 | else | ||
1098 | ackchains = AR9170_TX_PHY_TXCHAIN_1; | ||
1099 | |||
1100 | if (freq < 3000) | ||
1101 | ackpower = ar->power_2G_ofdm[0] & 0x3f; | ||
1102 | else | ||
1103 | ackpower = ar->power_5G_leg[0] & 0x3f; | ||
1104 | |||
1105 | ar9170_regwrite(0x1c3694, ackpower << 20 | ackchains << 26); | ||
1106 | ar9170_regwrite(0x1c3bb4, ackpower << 5 | ackchains << 11 | | ||
1107 | ackpower << 21 | ackchains << 27); | ||
1108 | |||
1109 | ar9170_regwrite_finish(); | ||
1110 | return ar9170_regwrite_result(); | ||
1111 | } | ||
1112 | |||
1113 | static int ar9170_calc_noise_dbm(u32 raw_noise) | ||
1114 | { | ||
1115 | if (raw_noise & 0x100) | ||
1116 | return ~((raw_noise & 0x0ff) >> 1); | ||
1117 | else | ||
1118 | return (raw_noise & 0xff) >> 1; | ||
1119 | } | ||
1120 | |||
1121 | int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel, | ||
1122 | enum ar9170_rf_init_mode rfi, enum ar9170_bw bw) | ||
1123 | { | ||
1124 | const struct ar9170_phy_freq_params *freqpar; | ||
1125 | u32 cmd, tmp, offs; | ||
1126 | __le32 vals[8]; | ||
1127 | int i, err; | ||
1128 | bool bandswitch; | ||
1129 | |||
1130 | /* clear BB heavy clip enable */ | ||
1131 | err = ar9170_write_reg(ar, 0x1c59e0, 0x200); | ||
1132 | if (err) | ||
1133 | return err; | ||
1134 | |||
1135 | /* may be NULL at first setup */ | ||
1136 | if (ar->channel) | ||
1137 | bandswitch = ar->channel->band != channel->band; | ||
1138 | else | ||
1139 | bandswitch = true; | ||
1140 | |||
1141 | /* HW workaround */ | ||
1142 | if (!ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] && | ||
1143 | channel->center_freq <= 2417) | ||
1144 | bandswitch = true; | ||
1145 | |||
1146 | err = ar->exec_cmd(ar, AR9170_CMD_FREQ_START, 0, NULL, 0, NULL); | ||
1147 | if (err) | ||
1148 | return err; | ||
1149 | |||
1150 | if (rfi != AR9170_RFI_NONE || bandswitch) { | ||
1151 | u32 val = 0x400; | ||
1152 | |||
1153 | if (rfi == AR9170_RFI_COLD) | ||
1154 | val = 0x800; | ||
1155 | |||
1156 | /* warm/cold reset BB/ADDA */ | ||
1157 | err = ar9170_write_reg(ar, 0x1d4004, val); | ||
1158 | if (err) | ||
1159 | return err; | ||
1160 | |||
1161 | err = ar9170_write_reg(ar, 0x1d4004, 0x0); | ||
1162 | if (err) | ||
1163 | return err; | ||
1164 | |||
1165 | err = ar9170_init_phy(ar, channel->band); | ||
1166 | if (err) | ||
1167 | return err; | ||
1168 | |||
1169 | err = ar9170_init_rf_banks_0_7(ar, | ||
1170 | channel->band == IEEE80211_BAND_5GHZ); | ||
1171 | if (err) | ||
1172 | return err; | ||
1173 | |||
1174 | cmd = AR9170_CMD_RF_INIT; | ||
1175 | } else { | ||
1176 | cmd = AR9170_CMD_FREQUENCY; | ||
1177 | } | ||
1178 | |||
1179 | err = ar9170_init_rf_bank4_pwr(ar, | ||
1180 | channel->band == IEEE80211_BAND_5GHZ, | ||
1181 | channel->center_freq, bw); | ||
1182 | if (err) | ||
1183 | return err; | ||
1184 | |||
1185 | switch (bw) { | ||
1186 | case AR9170_BW_20: | ||
1187 | tmp = 0x240; | ||
1188 | offs = 0; | ||
1189 | break; | ||
1190 | case AR9170_BW_40_BELOW: | ||
1191 | tmp = 0x2c4; | ||
1192 | offs = 3; | ||
1193 | break; | ||
1194 | case AR9170_BW_40_ABOVE: | ||
1195 | tmp = 0x2d4; | ||
1196 | offs = 1; | ||
1197 | break; | ||
1198 | default: | ||
1199 | BUG(); | ||
1200 | return -ENOSYS; | ||
1201 | } | ||
1202 | |||
1203 | if (0 /* 2 streams capable */) | ||
1204 | tmp |= 0x100; | ||
1205 | |||
1206 | err = ar9170_write_reg(ar, 0x1c5804, tmp); | ||
1207 | if (err) | ||
1208 | return err; | ||
1209 | |||
1210 | err = ar9170_set_power_cal(ar, channel->center_freq, bw); | ||
1211 | if (err) | ||
1212 | return err; | ||
1213 | |||
1214 | freqpar = ar9170_get_hw_dyn_params(channel, bw); | ||
1215 | |||
1216 | vals[0] = cpu_to_le32(channel->center_freq * 1000); | ||
1217 | vals[1] = cpu_to_le32(bw == AR9170_BW_20 ? 0 : 1); | ||
1218 | vals[2] = cpu_to_le32(offs << 2 | 1); | ||
1219 | vals[3] = cpu_to_le32(freqpar->coeff_exp); | ||
1220 | vals[4] = cpu_to_le32(freqpar->coeff_man); | ||
1221 | vals[5] = cpu_to_le32(freqpar->coeff_exp_shgi); | ||
1222 | vals[6] = cpu_to_le32(freqpar->coeff_man_shgi); | ||
1223 | vals[7] = cpu_to_le32(1000); | ||
1224 | |||
1225 | err = ar->exec_cmd(ar, cmd, sizeof(vals), (u8 *)vals, | ||
1226 | sizeof(vals), (u8 *)vals); | ||
1227 | if (err) | ||
1228 | return err; | ||
1229 | |||
1230 | for (i = 0; i < 2; i++) { | ||
1231 | ar->noise[i] = ar9170_calc_noise_dbm( | ||
1232 | (le32_to_cpu(vals[2 + i]) >> 19) & 0x1ff); | ||
1233 | |||
1234 | ar->noise[i + 2] = ar9170_calc_noise_dbm( | ||
1235 | (le32_to_cpu(vals[5 + i]) >> 23) & 0x1ff); | ||
1236 | } | ||
1237 | |||
1238 | ar->channel = channel; | ||
1239 | return 0; | ||
1240 | } | ||
diff --git a/drivers/net/wireless/ar9170/usb.c b/drivers/net/wireless/ar9170/usb.c new file mode 100644 index 000000000000..ad296840893e --- /dev/null +++ b/drivers/net/wireless/ar9170/usb.c | |||
@@ -0,0 +1,748 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 driver | ||
3 | * | ||
4 | * USB - frontend | ||
5 | * | ||
6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> | ||
7 | * Copyright 2009, Christian Lamparter <chunkeey@web.de> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; see the file COPYING. If not, see | ||
21 | * http://www.gnu.org/licenses/. | ||
22 | * | ||
23 | * This file incorporates work covered by the following copyright and | ||
24 | * permission notice: | ||
25 | * Copyright (c) 2007-2008 Atheros Communications, Inc. | ||
26 | * | ||
27 | * Permission to use, copy, modify, and/or distribute this software for any | ||
28 | * purpose with or without fee is hereby granted, provided that the above | ||
29 | * copyright notice and this permission notice appear in all copies. | ||
30 | * | ||
31 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
32 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
33 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
34 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
35 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
36 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
37 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
38 | */ | ||
39 | |||
40 | #include <linux/module.h> | ||
41 | #include <linux/usb.h> | ||
42 | #include <linux/firmware.h> | ||
43 | #include <linux/etherdevice.h> | ||
44 | #include <net/mac80211.h> | ||
45 | #include "ar9170.h" | ||
46 | #include "cmd.h" | ||
47 | #include "hw.h" | ||
48 | #include "usb.h" | ||
49 | |||
50 | MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>"); | ||
51 | MODULE_AUTHOR("Christian Lamparter <chunkeey@web.de>"); | ||
52 | MODULE_LICENSE("GPL"); | ||
53 | MODULE_DESCRIPTION("Atheros AR9170 802.11n USB wireless"); | ||
54 | MODULE_FIRMWARE("ar9170-1.fw"); | ||
55 | MODULE_FIRMWARE("ar9170-2.fw"); | ||
56 | |||
57 | static struct usb_device_id ar9170_usb_ids[] = { | ||
58 | /* Atheros 9170 */ | ||
59 | { USB_DEVICE(0x0cf3, 0x9170) }, | ||
60 | /* Atheros TG121N */ | ||
61 | { USB_DEVICE(0x0cf3, 0x1001) }, | ||
62 | /* D-Link DWA 160A */ | ||
63 | { USB_DEVICE(0x07d1, 0x3c10) }, | ||
64 | /* Netgear WNDA3100 */ | ||
65 | { USB_DEVICE(0x0846, 0x9010) }, | ||
66 | /* Netgear WN111 v2 */ | ||
67 | { USB_DEVICE(0x0846, 0x9001) }, | ||
68 | /* Zydas ZD1221 */ | ||
69 | { USB_DEVICE(0x0ace, 0x1221) }, | ||
70 | /* Z-Com UB81 BG */ | ||
71 | { USB_DEVICE(0x0cde, 0x0023) }, | ||
72 | /* Z-Com UB82 ABG */ | ||
73 | { USB_DEVICE(0x0cde, 0x0026) }, | ||
74 | /* Arcadyan WN7512 */ | ||
75 | { USB_DEVICE(0x083a, 0xf522) }, | ||
76 | /* Planex GWUS300 */ | ||
77 | { USB_DEVICE(0x2019, 0x5304) }, | ||
78 | /* IO-Data WNGDNUS2 */ | ||
79 | { USB_DEVICE(0x04bb, 0x093f) }, | ||
80 | |||
81 | /* terminate */ | ||
82 | {} | ||
83 | }; | ||
84 | MODULE_DEVICE_TABLE(usb, ar9170_usb_ids); | ||
85 | |||
86 | static void ar9170_usb_tx_urb_complete_free(struct urb *urb) | ||
87 | { | ||
88 | struct sk_buff *skb = urb->context; | ||
89 | struct ar9170_usb *aru = (struct ar9170_usb *) | ||
90 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); | ||
91 | |||
92 | if (!aru) { | ||
93 | dev_kfree_skb_irq(skb); | ||
94 | return ; | ||
95 | } | ||
96 | |||
97 | ar9170_handle_tx_status(&aru->common, skb, false, | ||
98 | AR9170_TX_STATUS_COMPLETE); | ||
99 | } | ||
100 | |||
101 | static void ar9170_usb_tx_urb_complete(struct urb *urb) | ||
102 | { | ||
103 | } | ||
104 | |||
105 | static void ar9170_usb_irq_completed(struct urb *urb) | ||
106 | { | ||
107 | struct ar9170_usb *aru = urb->context; | ||
108 | |||
109 | switch (urb->status) { | ||
110 | /* everything is fine */ | ||
111 | case 0: | ||
112 | break; | ||
113 | |||
114 | /* disconnect */ | ||
115 | case -ENOENT: | ||
116 | case -ECONNRESET: | ||
117 | case -ENODEV: | ||
118 | case -ESHUTDOWN: | ||
119 | goto free; | ||
120 | |||
121 | default: | ||
122 | goto resubmit; | ||
123 | } | ||
124 | |||
125 | print_hex_dump_bytes("ar9170 irq: ", DUMP_PREFIX_OFFSET, | ||
126 | urb->transfer_buffer, urb->actual_length); | ||
127 | |||
128 | resubmit: | ||
129 | usb_anchor_urb(urb, &aru->rx_submitted); | ||
130 | if (usb_submit_urb(urb, GFP_ATOMIC)) { | ||
131 | usb_unanchor_urb(urb); | ||
132 | goto free; | ||
133 | } | ||
134 | |||
135 | return; | ||
136 | |||
137 | free: | ||
138 | usb_buffer_free(aru->udev, 64, urb->transfer_buffer, urb->transfer_dma); | ||
139 | } | ||
140 | |||
141 | static void ar9170_usb_rx_completed(struct urb *urb) | ||
142 | { | ||
143 | struct sk_buff *skb = urb->context; | ||
144 | struct ar9170_usb *aru = (struct ar9170_usb *) | ||
145 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); | ||
146 | int err; | ||
147 | |||
148 | if (!aru) | ||
149 | goto free; | ||
150 | |||
151 | switch (urb->status) { | ||
152 | /* everything is fine */ | ||
153 | case 0: | ||
154 | break; | ||
155 | |||
156 | /* disconnect */ | ||
157 | case -ENOENT: | ||
158 | case -ECONNRESET: | ||
159 | case -ENODEV: | ||
160 | case -ESHUTDOWN: | ||
161 | goto free; | ||
162 | |||
163 | default: | ||
164 | goto resubmit; | ||
165 | } | ||
166 | |||
167 | skb_put(skb, urb->actual_length); | ||
168 | ar9170_rx(&aru->common, skb); | ||
169 | |||
170 | resubmit: | ||
171 | skb_reset_tail_pointer(skb); | ||
172 | skb_trim(skb, 0); | ||
173 | |||
174 | usb_anchor_urb(urb, &aru->rx_submitted); | ||
175 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
176 | if (err) { | ||
177 | usb_unanchor_urb(urb); | ||
178 | dev_kfree_skb_irq(skb); | ||
179 | } | ||
180 | |||
181 | return ; | ||
182 | |||
183 | free: | ||
184 | dev_kfree_skb_irq(skb); | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | static int ar9170_usb_prep_rx_urb(struct ar9170_usb *aru, | ||
189 | struct urb *urb, gfp_t gfp) | ||
190 | { | ||
191 | struct sk_buff *skb; | ||
192 | |||
193 | skb = __dev_alloc_skb(AR9170_MAX_RX_BUFFER_SIZE + 32, gfp); | ||
194 | if (!skb) | ||
195 | return -ENOMEM; | ||
196 | |||
197 | /* reserve some space for mac80211's radiotap */ | ||
198 | skb_reserve(skb, 32); | ||
199 | |||
200 | usb_fill_bulk_urb(urb, aru->udev, | ||
201 | usb_rcvbulkpipe(aru->udev, AR9170_EP_RX), | ||
202 | skb->data, min(skb_tailroom(skb), | ||
203 | AR9170_MAX_RX_BUFFER_SIZE), | ||
204 | ar9170_usb_rx_completed, skb); | ||
205 | |||
206 | return 0; | ||
207 | } | ||
208 | |||
209 | static int ar9170_usb_alloc_rx_irq_urb(struct ar9170_usb *aru) | ||
210 | { | ||
211 | struct urb *urb = NULL; | ||
212 | void *ibuf; | ||
213 | int err = -ENOMEM; | ||
214 | |||
215 | /* initialize interrupt endpoint */ | ||
216 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
217 | if (!urb) | ||
218 | goto out; | ||
219 | |||
220 | ibuf = usb_buffer_alloc(aru->udev, 64, GFP_KERNEL, &urb->transfer_dma); | ||
221 | if (!ibuf) | ||
222 | goto out; | ||
223 | |||
224 | usb_fill_int_urb(urb, aru->udev, | ||
225 | usb_rcvintpipe(aru->udev, AR9170_EP_IRQ), ibuf, | ||
226 | 64, ar9170_usb_irq_completed, aru, 1); | ||
227 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
228 | |||
229 | usb_anchor_urb(urb, &aru->rx_submitted); | ||
230 | err = usb_submit_urb(urb, GFP_KERNEL); | ||
231 | if (err) { | ||
232 | usb_unanchor_urb(urb); | ||
233 | usb_buffer_free(aru->udev, 64, urb->transfer_buffer, | ||
234 | urb->transfer_dma); | ||
235 | } | ||
236 | |||
237 | out: | ||
238 | usb_free_urb(urb); | ||
239 | return err; | ||
240 | } | ||
241 | |||
242 | static int ar9170_usb_alloc_rx_bulk_urbs(struct ar9170_usb *aru) | ||
243 | { | ||
244 | struct urb *urb; | ||
245 | int i; | ||
246 | int err = -EINVAL; | ||
247 | |||
248 | for (i = 0; i < AR9170_NUM_RX_URBS; i++) { | ||
249 | err = -ENOMEM; | ||
250 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
251 | if (!urb) | ||
252 | goto err_out; | ||
253 | |||
254 | err = ar9170_usb_prep_rx_urb(aru, urb, GFP_KERNEL); | ||
255 | if (err) { | ||
256 | usb_free_urb(urb); | ||
257 | goto err_out; | ||
258 | } | ||
259 | |||
260 | usb_anchor_urb(urb, &aru->rx_submitted); | ||
261 | err = usb_submit_urb(urb, GFP_KERNEL); | ||
262 | if (err) { | ||
263 | usb_unanchor_urb(urb); | ||
264 | dev_kfree_skb_any((void *) urb->transfer_buffer); | ||
265 | usb_free_urb(urb); | ||
266 | goto err_out; | ||
267 | } | ||
268 | usb_free_urb(urb); | ||
269 | } | ||
270 | |||
271 | /* the device now waiting for a firmware. */ | ||
272 | aru->common.state = AR9170_IDLE; | ||
273 | return 0; | ||
274 | |||
275 | err_out: | ||
276 | |||
277 | usb_kill_anchored_urbs(&aru->rx_submitted); | ||
278 | return err; | ||
279 | } | ||
280 | |||
281 | static void ar9170_usb_cancel_urbs(struct ar9170_usb *aru) | ||
282 | { | ||
283 | int ret; | ||
284 | |||
285 | aru->common.state = AR9170_UNKNOWN_STATE; | ||
286 | |||
287 | usb_unlink_anchored_urbs(&aru->tx_submitted); | ||
288 | |||
289 | /* give the LED OFF command and the deauth frame a chance to air. */ | ||
290 | ret = usb_wait_anchor_empty_timeout(&aru->tx_submitted, | ||
291 | msecs_to_jiffies(100)); | ||
292 | if (ret == 0) | ||
293 | dev_err(&aru->udev->dev, "kill pending tx urbs.\n"); | ||
294 | usb_poison_anchored_urbs(&aru->tx_submitted); | ||
295 | |||
296 | usb_poison_anchored_urbs(&aru->rx_submitted); | ||
297 | } | ||
298 | |||
299 | static int ar9170_usb_exec_cmd(struct ar9170 *ar, enum ar9170_cmd cmd, | ||
300 | unsigned int plen, void *payload, | ||
301 | unsigned int outlen, void *out) | ||
302 | { | ||
303 | struct ar9170_usb *aru = (void *) ar; | ||
304 | struct urb *urb = NULL; | ||
305 | unsigned long flags; | ||
306 | int err = -ENOMEM; | ||
307 | |||
308 | if (unlikely(!IS_ACCEPTING_CMD(ar))) | ||
309 | return -EPERM; | ||
310 | |||
311 | if (WARN_ON(plen > AR9170_MAX_CMD_LEN - 4)) | ||
312 | return -EINVAL; | ||
313 | |||
314 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
315 | if (unlikely(!urb)) | ||
316 | goto err_free; | ||
317 | |||
318 | ar->cmdbuf[0] = cpu_to_le32(plen); | ||
319 | ar->cmdbuf[0] |= cpu_to_le32(cmd << 8); | ||
320 | /* writing multiple regs fills this buffer already */ | ||
321 | if (plen && payload != (u8 *)(&ar->cmdbuf[1])) | ||
322 | memcpy(&ar->cmdbuf[1], payload, plen); | ||
323 | |||
324 | spin_lock_irqsave(&aru->common.cmdlock, flags); | ||
325 | aru->readbuf = (u8 *)out; | ||
326 | aru->readlen = outlen; | ||
327 | spin_unlock_irqrestore(&aru->common.cmdlock, flags); | ||
328 | |||
329 | usb_fill_int_urb(urb, aru->udev, | ||
330 | usb_sndbulkpipe(aru->udev, AR9170_EP_CMD), | ||
331 | aru->common.cmdbuf, plen + 4, | ||
332 | ar9170_usb_tx_urb_complete, NULL, 1); | ||
333 | |||
334 | usb_anchor_urb(urb, &aru->tx_submitted); | ||
335 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
336 | if (err) { | ||
337 | usb_unanchor_urb(urb); | ||
338 | usb_free_urb(urb); | ||
339 | goto err_unbuf; | ||
340 | } | ||
341 | usb_free_urb(urb); | ||
342 | |||
343 | err = wait_for_completion_timeout(&aru->cmd_wait, HZ); | ||
344 | if (err == 0) { | ||
345 | err = -ETIMEDOUT; | ||
346 | goto err_unbuf; | ||
347 | } | ||
348 | |||
349 | if (outlen >= 0 && aru->readlen != outlen) { | ||
350 | err = -EMSGSIZE; | ||
351 | goto err_unbuf; | ||
352 | } | ||
353 | |||
354 | return 0; | ||
355 | |||
356 | err_unbuf: | ||
357 | /* Maybe the device was removed in the second we were waiting? */ | ||
358 | if (IS_STARTED(ar)) { | ||
359 | dev_err(&aru->udev->dev, "no command feedback " | ||
360 | "received (%d).\n", err); | ||
361 | |||
362 | /* provide some maybe useful debug information */ | ||
363 | print_hex_dump_bytes("ar9170 cmd: ", DUMP_PREFIX_NONE, | ||
364 | aru->common.cmdbuf, plen + 4); | ||
365 | dump_stack(); | ||
366 | } | ||
367 | |||
368 | /* invalidate to avoid completing the next prematurely */ | ||
369 | spin_lock_irqsave(&aru->common.cmdlock, flags); | ||
370 | aru->readbuf = NULL; | ||
371 | aru->readlen = 0; | ||
372 | spin_unlock_irqrestore(&aru->common.cmdlock, flags); | ||
373 | |||
374 | err_free: | ||
375 | |||
376 | return err; | ||
377 | } | ||
378 | |||
379 | static int ar9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb, | ||
380 | bool txstatus_needed, unsigned int extra_len) | ||
381 | { | ||
382 | struct ar9170_usb *aru = (struct ar9170_usb *) ar; | ||
383 | struct urb *urb; | ||
384 | int err; | ||
385 | |||
386 | if (unlikely(!IS_STARTED(ar))) { | ||
387 | /* Seriously, what were you drink... err... thinking!? */ | ||
388 | return -EPERM; | ||
389 | } | ||
390 | |||
391 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
392 | if (unlikely(!urb)) | ||
393 | return -ENOMEM; | ||
394 | |||
395 | usb_fill_bulk_urb(urb, aru->udev, | ||
396 | usb_sndbulkpipe(aru->udev, AR9170_EP_TX), | ||
397 | skb->data, skb->len + extra_len, (txstatus_needed ? | ||
398 | ar9170_usb_tx_urb_complete : | ||
399 | ar9170_usb_tx_urb_complete_free), skb); | ||
400 | urb->transfer_flags |= URB_ZERO_PACKET; | ||
401 | |||
402 | usb_anchor_urb(urb, &aru->tx_submitted); | ||
403 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
404 | if (unlikely(err)) | ||
405 | usb_unanchor_urb(urb); | ||
406 | |||
407 | usb_free_urb(urb); | ||
408 | return err; | ||
409 | } | ||
410 | |||
411 | static void ar9170_usb_callback_cmd(struct ar9170 *ar, u32 len , void *buffer) | ||
412 | { | ||
413 | struct ar9170_usb *aru = (void *) ar; | ||
414 | unsigned long flags; | ||
415 | u32 in, out; | ||
416 | |||
417 | if (!buffer) | ||
418 | return ; | ||
419 | |||
420 | in = le32_to_cpup((__le32 *)buffer); | ||
421 | out = le32_to_cpu(ar->cmdbuf[0]); | ||
422 | |||
423 | /* mask off length byte */ | ||
424 | out &= ~0xFF; | ||
425 | |||
426 | if (aru->readlen >= 0) { | ||
427 | /* add expected length */ | ||
428 | out |= aru->readlen; | ||
429 | } else { | ||
430 | /* add obtained length */ | ||
431 | out |= in & 0xFF; | ||
432 | } | ||
433 | |||
434 | /* | ||
435 | * Some commands (e.g: AR9170_CMD_FREQUENCY) have a variable response | ||
436 | * length and we cannot predict the correct length in advance. | ||
437 | * So we only check if we provided enough space for the data. | ||
438 | */ | ||
439 | if (unlikely(out < in)) { | ||
440 | dev_warn(&aru->udev->dev, "received invalid command response " | ||
441 | "got %d bytes, instead of %d bytes " | ||
442 | "and the resp length is %d bytes\n", | ||
443 | in, out, len); | ||
444 | print_hex_dump_bytes("ar9170 invalid resp: ", | ||
445 | DUMP_PREFIX_OFFSET, buffer, len); | ||
446 | /* | ||
447 | * Do not complete, then the command times out, | ||
448 | * and we get a stack trace from there. | ||
449 | */ | ||
450 | return ; | ||
451 | } | ||
452 | |||
453 | spin_lock_irqsave(&aru->common.cmdlock, flags); | ||
454 | if (aru->readbuf && len > 0) { | ||
455 | memcpy(aru->readbuf, buffer + 4, len - 4); | ||
456 | aru->readbuf = NULL; | ||
457 | } | ||
458 | complete(&aru->cmd_wait); | ||
459 | spin_unlock_irqrestore(&aru->common.cmdlock, flags); | ||
460 | } | ||
461 | |||
462 | static int ar9170_usb_upload(struct ar9170_usb *aru, const void *data, | ||
463 | size_t len, u32 addr, bool complete) | ||
464 | { | ||
465 | int transfer, err; | ||
466 | u8 *buf = kmalloc(4096, GFP_KERNEL); | ||
467 | |||
468 | if (!buf) | ||
469 | return -ENOMEM; | ||
470 | |||
471 | while (len) { | ||
472 | transfer = min_t(int, len, 4096); | ||
473 | memcpy(buf, data, transfer); | ||
474 | |||
475 | err = usb_control_msg(aru->udev, usb_sndctrlpipe(aru->udev, 0), | ||
476 | 0x30 /* FW DL */, 0x40 | USB_DIR_OUT, | ||
477 | addr >> 8, 0, buf, transfer, 1000); | ||
478 | |||
479 | if (err < 0) { | ||
480 | kfree(buf); | ||
481 | return err; | ||
482 | } | ||
483 | |||
484 | len -= transfer; | ||
485 | data += transfer; | ||
486 | addr += transfer; | ||
487 | } | ||
488 | kfree(buf); | ||
489 | |||
490 | if (complete) { | ||
491 | err = usb_control_msg(aru->udev, usb_sndctrlpipe(aru->udev, 0), | ||
492 | 0x31 /* FW DL COMPLETE */, | ||
493 | 0x40 | USB_DIR_OUT, 0, 0, NULL, 0, 5000); | ||
494 | } | ||
495 | |||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static int ar9170_usb_request_firmware(struct ar9170_usb *aru) | ||
500 | { | ||
501 | int err = 0; | ||
502 | |||
503 | err = request_firmware(&aru->init_values, "ar9170-1.fw", | ||
504 | &aru->udev->dev); | ||
505 | if (err) { | ||
506 | dev_err(&aru->udev->dev, "file with init values not found.\n"); | ||
507 | return err; | ||
508 | } | ||
509 | |||
510 | err = request_firmware(&aru->firmware, "ar9170-2.fw", &aru->udev->dev); | ||
511 | if (err) { | ||
512 | release_firmware(aru->init_values); | ||
513 | dev_err(&aru->udev->dev, "firmware file not found.\n"); | ||
514 | return err; | ||
515 | } | ||
516 | |||
517 | return err; | ||
518 | } | ||
519 | |||
520 | static int ar9170_usb_reset(struct ar9170_usb *aru) | ||
521 | { | ||
522 | int ret, lock = (aru->intf->condition != USB_INTERFACE_BINDING); | ||
523 | |||
524 | if (lock) { | ||
525 | ret = usb_lock_device_for_reset(aru->udev, aru->intf); | ||
526 | if (ret < 0) { | ||
527 | dev_err(&aru->udev->dev, "unable to lock device " | ||
528 | "for reset (%d).\n", ret); | ||
529 | return ret; | ||
530 | } | ||
531 | } | ||
532 | |||
533 | ret = usb_reset_device(aru->udev); | ||
534 | if (lock) | ||
535 | usb_unlock_device(aru->udev); | ||
536 | |||
537 | /* let it rest - for a second - */ | ||
538 | msleep(1000); | ||
539 | |||
540 | return ret; | ||
541 | } | ||
542 | |||
543 | static int ar9170_usb_upload_firmware(struct ar9170_usb *aru) | ||
544 | { | ||
545 | int err; | ||
546 | |||
547 | /* First, upload initial values to device RAM */ | ||
548 | err = ar9170_usb_upload(aru, aru->init_values->data, | ||
549 | aru->init_values->size, 0x102800, false); | ||
550 | if (err) { | ||
551 | dev_err(&aru->udev->dev, "firmware part 1 " | ||
552 | "upload failed (%d).\n", err); | ||
553 | return err; | ||
554 | } | ||
555 | |||
556 | /* Then, upload the firmware itself and start it */ | ||
557 | return ar9170_usb_upload(aru, aru->firmware->data, aru->firmware->size, | ||
558 | 0x200000, true); | ||
559 | } | ||
560 | |||
561 | static int ar9170_usb_init_transport(struct ar9170_usb *aru) | ||
562 | { | ||
563 | struct ar9170 *ar = (void *) &aru->common; | ||
564 | int err; | ||
565 | |||
566 | ar9170_regwrite_begin(ar); | ||
567 | |||
568 | /* Set USB Rx stream mode MAX packet number to 2 */ | ||
569 | ar9170_regwrite(AR9170_USB_REG_MAX_AGG_UPLOAD, 0x4); | ||
570 | |||
571 | /* Set USB Rx stream mode timeout to 10us */ | ||
572 | ar9170_regwrite(AR9170_USB_REG_UPLOAD_TIME_CTL, 0x80); | ||
573 | |||
574 | ar9170_regwrite_finish(); | ||
575 | |||
576 | err = ar9170_regwrite_result(); | ||
577 | if (err) | ||
578 | dev_err(&aru->udev->dev, "USB setup failed (%d).\n", err); | ||
579 | |||
580 | return err; | ||
581 | } | ||
582 | |||
583 | static void ar9170_usb_stop(struct ar9170 *ar) | ||
584 | { | ||
585 | struct ar9170_usb *aru = (void *) ar; | ||
586 | int ret; | ||
587 | |||
588 | if (IS_ACCEPTING_CMD(ar)) | ||
589 | aru->common.state = AR9170_STOPPED; | ||
590 | |||
591 | /* lets wait a while until the tx - queues are dried out */ | ||
592 | ret = usb_wait_anchor_empty_timeout(&aru->tx_submitted, | ||
593 | msecs_to_jiffies(1000)); | ||
594 | if (ret == 0) | ||
595 | dev_err(&aru->udev->dev, "kill pending tx urbs.\n"); | ||
596 | |||
597 | usb_poison_anchored_urbs(&aru->tx_submitted); | ||
598 | |||
599 | /* | ||
600 | * Note: | ||
601 | * So far we freed all tx urbs, but we won't dare to touch any rx urbs. | ||
602 | * Else we would end up with a unresponsive device... | ||
603 | */ | ||
604 | } | ||
605 | |||
606 | static int ar9170_usb_open(struct ar9170 *ar) | ||
607 | { | ||
608 | struct ar9170_usb *aru = (void *) ar; | ||
609 | int err; | ||
610 | |||
611 | usb_unpoison_anchored_urbs(&aru->tx_submitted); | ||
612 | err = ar9170_usb_init_transport(aru); | ||
613 | if (err) { | ||
614 | usb_poison_anchored_urbs(&aru->tx_submitted); | ||
615 | return err; | ||
616 | } | ||
617 | |||
618 | aru->common.state = AR9170_IDLE; | ||
619 | return 0; | ||
620 | } | ||
621 | |||
622 | static int ar9170_usb_probe(struct usb_interface *intf, | ||
623 | const struct usb_device_id *id) | ||
624 | { | ||
625 | struct ar9170_usb *aru; | ||
626 | struct ar9170 *ar; | ||
627 | struct usb_device *udev; | ||
628 | int err; | ||
629 | |||
630 | aru = ar9170_alloc(sizeof(*aru)); | ||
631 | if (IS_ERR(aru)) { | ||
632 | err = PTR_ERR(aru); | ||
633 | goto out; | ||
634 | } | ||
635 | |||
636 | udev = interface_to_usbdev(intf); | ||
637 | usb_get_dev(udev); | ||
638 | aru->udev = udev; | ||
639 | aru->intf = intf; | ||
640 | ar = &aru->common; | ||
641 | |||
642 | usb_set_intfdata(intf, aru); | ||
643 | SET_IEEE80211_DEV(ar->hw, &udev->dev); | ||
644 | |||
645 | init_usb_anchor(&aru->rx_submitted); | ||
646 | init_usb_anchor(&aru->tx_submitted); | ||
647 | init_completion(&aru->cmd_wait); | ||
648 | |||
649 | aru->common.stop = ar9170_usb_stop; | ||
650 | aru->common.open = ar9170_usb_open; | ||
651 | aru->common.tx = ar9170_usb_tx; | ||
652 | aru->common.exec_cmd = ar9170_usb_exec_cmd; | ||
653 | aru->common.callback_cmd = ar9170_usb_callback_cmd; | ||
654 | |||
655 | err = ar9170_usb_reset(aru); | ||
656 | if (err) | ||
657 | goto err_unlock; | ||
658 | |||
659 | err = ar9170_usb_request_firmware(aru); | ||
660 | if (err) | ||
661 | goto err_unlock; | ||
662 | |||
663 | err = ar9170_usb_alloc_rx_irq_urb(aru); | ||
664 | if (err) | ||
665 | goto err_freefw; | ||
666 | |||
667 | err = ar9170_usb_alloc_rx_bulk_urbs(aru); | ||
668 | if (err) | ||
669 | goto err_unrx; | ||
670 | |||
671 | err = ar9170_usb_upload_firmware(aru); | ||
672 | if (err) { | ||
673 | err = ar9170_echo_test(&aru->common, 0x60d43110); | ||
674 | if (err) { | ||
675 | /* force user invention, by disabling the device */ | ||
676 | err = usb_driver_set_configuration(aru->udev, -1); | ||
677 | dev_err(&aru->udev->dev, "device is in a bad state. " | ||
678 | "please reconnect it!\n"); | ||
679 | goto err_unrx; | ||
680 | } | ||
681 | } | ||
682 | |||
683 | err = ar9170_usb_open(ar); | ||
684 | if (err) | ||
685 | goto err_unrx; | ||
686 | |||
687 | err = ar9170_register(ar, &udev->dev); | ||
688 | |||
689 | ar9170_usb_stop(ar); | ||
690 | if (err) | ||
691 | goto err_unrx; | ||
692 | |||
693 | return 0; | ||
694 | |||
695 | err_unrx: | ||
696 | ar9170_usb_cancel_urbs(aru); | ||
697 | |||
698 | err_freefw: | ||
699 | release_firmware(aru->init_values); | ||
700 | release_firmware(aru->firmware); | ||
701 | |||
702 | err_unlock: | ||
703 | usb_set_intfdata(intf, NULL); | ||
704 | usb_put_dev(udev); | ||
705 | ieee80211_free_hw(ar->hw); | ||
706 | out: | ||
707 | return err; | ||
708 | } | ||
709 | |||
710 | static void ar9170_usb_disconnect(struct usb_interface *intf) | ||
711 | { | ||
712 | struct ar9170_usb *aru = usb_get_intfdata(intf); | ||
713 | |||
714 | if (!aru) | ||
715 | return; | ||
716 | |||
717 | aru->common.state = AR9170_IDLE; | ||
718 | ar9170_unregister(&aru->common); | ||
719 | ar9170_usb_cancel_urbs(aru); | ||
720 | |||
721 | release_firmware(aru->init_values); | ||
722 | release_firmware(aru->firmware); | ||
723 | |||
724 | usb_put_dev(aru->udev); | ||
725 | usb_set_intfdata(intf, NULL); | ||
726 | ieee80211_free_hw(aru->common.hw); | ||
727 | } | ||
728 | |||
729 | static struct usb_driver ar9170_driver = { | ||
730 | .name = "ar9170usb", | ||
731 | .probe = ar9170_usb_probe, | ||
732 | .disconnect = ar9170_usb_disconnect, | ||
733 | .id_table = ar9170_usb_ids, | ||
734 | .soft_unbind = 1, | ||
735 | }; | ||
736 | |||
737 | static int __init ar9170_init(void) | ||
738 | { | ||
739 | return usb_register(&ar9170_driver); | ||
740 | } | ||
741 | |||
742 | static void __exit ar9170_exit(void) | ||
743 | { | ||
744 | usb_deregister(&ar9170_driver); | ||
745 | } | ||
746 | |||
747 | module_init(ar9170_init); | ||
748 | module_exit(ar9170_exit); | ||
diff --git a/drivers/net/wireless/ar9170/usb.h b/drivers/net/wireless/ar9170/usb.h new file mode 100644 index 000000000000..f5852924cd64 --- /dev/null +++ b/drivers/net/wireless/ar9170/usb.h | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * Atheros AR9170 USB driver | ||
3 | * | ||
4 | * Driver specific definitions | ||
5 | * | ||
6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> | ||
7 | * Copyright 2009, Christian Lamparter <chunkeey@web.de> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; see the file COPYING. If not, see | ||
21 | * http://www.gnu.org/licenses/. | ||
22 | * | ||
23 | * This file incorporates work covered by the following copyright and | ||
24 | * permission notice: | ||
25 | * Copyright (c) 2007-2008 Atheros Communications, Inc. | ||
26 | * | ||
27 | * Permission to use, copy, modify, and/or distribute this software for any | ||
28 | * purpose with or without fee is hereby granted, provided that the above | ||
29 | * copyright notice and this permission notice appear in all copies. | ||
30 | * | ||
31 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
32 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
33 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
34 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
35 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
36 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
37 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
38 | */ | ||
39 | #ifndef __USB_H | ||
40 | #define __USB_H | ||
41 | |||
42 | #include <linux/usb.h> | ||
43 | #include <linux/completion.h> | ||
44 | #include <linux/spinlock.h> | ||
45 | #include <linux/leds.h> | ||
46 | #include <net/wireless.h> | ||
47 | #include <net/mac80211.h> | ||
48 | #include <linux/firmware.h> | ||
49 | #include "eeprom.h" | ||
50 | #include "hw.h" | ||
51 | #include "ar9170.h" | ||
52 | |||
53 | #define AR9170_NUM_RX_URBS 16 | ||
54 | |||
55 | struct firmware; | ||
56 | |||
57 | struct ar9170_usb { | ||
58 | struct ar9170 common; | ||
59 | struct usb_device *udev; | ||
60 | struct usb_interface *intf; | ||
61 | |||
62 | struct usb_anchor rx_submitted; | ||
63 | struct usb_anchor tx_submitted; | ||
64 | |||
65 | spinlock_t cmdlock; | ||
66 | struct completion cmd_wait; | ||
67 | int readlen; | ||
68 | u8 *readbuf; | ||
69 | |||
70 | const struct firmware *init_values; | ||
71 | const struct firmware *firmware; | ||
72 | }; | ||
73 | |||
74 | #endif /* __USB_H */ | ||