1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/pci.h>
24#include <linux/slab.h>
25#include "ath5k.h"
26#include "reg.h"
27#include "debug.h"
28
29
30
31
32
33static int ath5k_hw_post(struct ath5k_hw *ah)
34{
35
36 static const u32 static_pattern[4] = {
37 0x55555555, 0xaaaaaaaa,
38 0x66666666, 0x99999999
39 };
40 static const u16 regs[2] = { AR5K_STA_ID0, AR5K_PHY(8) };
41 int i, c;
42 u16 cur_reg;
43 u32 var_pattern;
44 u32 init_val;
45 u32 cur_val;
46
47 for (c = 0; c < 2; c++) {
48
49 cur_reg = regs[c];
50
51
52 init_val = ath5k_hw_reg_read(ah, cur_reg);
53
54 for (i = 0; i < 256; i++) {
55 var_pattern = i << 16 | i;
56 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
57 cur_val = ath5k_hw_reg_read(ah, cur_reg);
58
59 if (cur_val != var_pattern) {
60 ATH5K_ERR(ah, "POST Failed !!!\n");
61 return -EAGAIN;
62 }
63
64
65 var_pattern = 0x0039080f;
66 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
67 }
68
69 for (i = 0; i < 4; i++) {
70 var_pattern = static_pattern[i];
71 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
72 cur_val = ath5k_hw_reg_read(ah, cur_reg);
73
74 if (cur_val != var_pattern) {
75 ATH5K_ERR(ah, "POST Failed !!!\n");
76 return -EAGAIN;
77 }
78
79
80 var_pattern = 0x003b080f;
81 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
82 }
83
84
85 ath5k_hw_reg_write(ah, init_val, cur_reg);
86
87 }
88
89 return 0;
90
91}
92
93
94
95
96
97
98
99
100
101
102int ath5k_hw_init(struct ath5k_hw *ah)
103{
104 static const u8 zero_mac[ETH_ALEN] = { };
105 struct ath_common *common = ath5k_hw_common(ah);
106 struct pci_dev *pdev = ah->pdev;
107 struct ath5k_eeprom_info *ee;
108 int ret;
109 u32 srev;
110
111
112
113
114 ah->ah_bwmode = AR5K_BWMODE_DEFAULT;
115 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
116 ah->ah_imr = 0;
117 ah->ah_retry_short = AR5K_INIT_RETRY_SHORT;
118 ah->ah_retry_long = AR5K_INIT_RETRY_LONG;
119 ah->ah_ant_mode = AR5K_ANTMODE_DEFAULT;
120 ah->ah_noise_floor = -95;
121 ah->ani_state.ani_mode = ATH5K_ANI_MODE_AUTO;
122 ah->ah_current_channel = &ah->channels[0];
123
124
125
126
127 ath5k_hw_read_srev(ah);
128 srev = ah->ah_mac_srev;
129 if (srev < AR5K_SREV_AR5311)
130 ah->ah_version = AR5K_AR5210;
131 else if (srev < AR5K_SREV_AR5212)
132 ah->ah_version = AR5K_AR5211;
133 else
134 ah->ah_version = AR5K_AR5212;
135
136
137 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
138
139
140 ret = ath5k_hw_init_desc_functions(ah);
141 if (ret)
142 goto err;
143
144
145 ret = ath5k_hw_nic_wakeup(ah, NULL);
146 if (ret)
147 goto err;
148
149
150 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
151 0xffffffff;
152 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
153 IEEE80211_BAND_5GHZ);
154
155
156 switch (ah->ah_radio_5ghz_revision & 0xf0) {
157 case AR5K_SREV_RAD_5111:
158 ah->ah_radio = AR5K_RF5111;
159 ah->ah_single_chip = false;
160 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
161 IEEE80211_BAND_2GHZ);
162 break;
163 case AR5K_SREV_RAD_5112:
164 case AR5K_SREV_RAD_2112:
165 ah->ah_radio = AR5K_RF5112;
166 ah->ah_single_chip = false;
167 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
168 IEEE80211_BAND_2GHZ);
169 break;
170 case AR5K_SREV_RAD_2413:
171 ah->ah_radio = AR5K_RF2413;
172 ah->ah_single_chip = true;
173 break;
174 case AR5K_SREV_RAD_5413:
175 ah->ah_radio = AR5K_RF5413;
176 ah->ah_single_chip = true;
177 break;
178 case AR5K_SREV_RAD_2316:
179 ah->ah_radio = AR5K_RF2316;
180 ah->ah_single_chip = true;
181 break;
182 case AR5K_SREV_RAD_2317:
183 ah->ah_radio = AR5K_RF2317;
184 ah->ah_single_chip = true;
185 break;
186 case AR5K_SREV_RAD_5424:
187 if (ah->ah_mac_version == AR5K_SREV_AR2425 ||
188 ah->ah_mac_version == AR5K_SREV_AR2417) {
189 ah->ah_radio = AR5K_RF2425;
190 ah->ah_single_chip = true;
191 } else {
192 ah->ah_radio = AR5K_RF5413;
193 ah->ah_single_chip = true;
194 }
195 break;
196 default:
197
198 if (ah->ah_version == AR5K_AR5210) {
199 ah->ah_radio = AR5K_RF5110;
200 ah->ah_single_chip = false;
201 } else if (ah->ah_version == AR5K_AR5211) {
202 ah->ah_radio = AR5K_RF5111;
203 ah->ah_single_chip = false;
204 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
205 IEEE80211_BAND_2GHZ);
206 } else if (ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4) ||
207 ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4) ||
208 ah->ah_phy_revision == AR5K_SREV_PHY_2425) {
209 ah->ah_radio = AR5K_RF2425;
210 ah->ah_single_chip = true;
211 ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2425;
212 } else if (srev == AR5K_SREV_AR5213A &&
213 ah->ah_phy_revision == AR5K_SREV_PHY_5212B) {
214 ah->ah_radio = AR5K_RF5112;
215 ah->ah_single_chip = false;
216 ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_5112B;
217 } else if (ah->ah_mac_version == (AR5K_SREV_AR2415 >> 4) ||
218 ah->ah_mac_version == (AR5K_SREV_AR2315_R6 >> 4)) {
219 ah->ah_radio = AR5K_RF2316;
220 ah->ah_single_chip = true;
221 ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2316;
222 } else if (ah->ah_mac_version == (AR5K_SREV_AR5414 >> 4) ||
223 ah->ah_phy_revision == AR5K_SREV_PHY_5413) {
224 ah->ah_radio = AR5K_RF5413;
225 ah->ah_single_chip = true;
226 ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_5413;
227 } else if (ah->ah_mac_version == (AR5K_SREV_AR2414 >> 4) ||
228 ah->ah_phy_revision == AR5K_SREV_PHY_2413) {
229 ah->ah_radio = AR5K_RF2413;
230 ah->ah_single_chip = true;
231 ah->ah_radio_5ghz_revision = AR5K_SREV_RAD_2413;
232 } else {
233 ATH5K_ERR(ah, "Couldn't identify radio revision.\n");
234 ret = -ENODEV;
235 goto err;
236 }
237 }
238
239
240
241 if ((srev >= AR5K_SREV_AR5416) && (srev < AR5K_SREV_AR2425)) {
242 ATH5K_ERR(ah, "Device not yet supported.\n");
243 ret = -ENODEV;
244 goto err;
245 }
246
247
248
249
250 ret = ath5k_hw_post(ah);
251 if (ret)
252 goto err;
253
254
255 if (srev >= AR5K_SREV_AR5213A)
256 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_RETRY_FIX);
257
258
259
260
261
262 ret = ath5k_eeprom_init(ah);
263 if (ret) {
264 ATH5K_ERR(ah, "unable to init EEPROM\n");
265 goto err;
266 }
267
268 ee = &ah->ah_capabilities.cap_eeprom;
269
270
271
272
273 if ((ah->ah_version == AR5K_AR5212) && pdev && (pci_is_pcie(pdev))) {
274 ath5k_hw_reg_write(ah, 0x9248fc00, AR5K_PCIE_SERDES);
275 ath5k_hw_reg_write(ah, 0x24924924, AR5K_PCIE_SERDES);
276
277
278 ath5k_hw_reg_write(ah, 0x28000039, AR5K_PCIE_SERDES);
279 ath5k_hw_reg_write(ah, 0x53160824, AR5K_PCIE_SERDES);
280
281
282
283
284 if (ee->ee_serdes)
285 ath5k_hw_reg_write(ah, 0xe5980579, AR5K_PCIE_SERDES);
286 else
287 ath5k_hw_reg_write(ah, 0xf6800579, AR5K_PCIE_SERDES);
288
289
290 ath5k_hw_reg_write(ah, 0x001defff, AR5K_PCIE_SERDES);
291
292
293 ath5k_hw_reg_write(ah, 0x1aaabe40, AR5K_PCIE_SERDES);
294 ath5k_hw_reg_write(ah, 0xbe105554, AR5K_PCIE_SERDES);
295 ath5k_hw_reg_write(ah, 0x000e3007, AR5K_PCIE_SERDES);
296
297
298 ath5k_hw_reg_write(ah, 0x00000000, AR5K_PCIE_SERDES_RESET);
299 usleep_range(1000, 1500);
300 }
301
302
303 ret = ath5k_hw_set_capabilities(ah);
304 if (ret) {
305 ATH5K_ERR(ah, "unable to get device capabilities\n");
306 goto err;
307 }
308
309
310 common->keymax = (ah->ah_version == AR5K_AR5210 ?
311 AR5K_KEYTABLE_SIZE_5210 : AR5K_KEYTABLE_SIZE_5211);
312
313 if (srev >= AR5K_SREV_AR5212_V4 &&
314 (ee->ee_version < AR5K_EEPROM_VERSION_5_0 ||
315 !AR5K_EEPROM_AES_DIS(ee->ee_misc5)))
316 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
317
318 if (srev >= AR5K_SREV_AR2414) {
319 common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
320 AR5K_REG_ENABLE_BITS(ah, AR5K_MISC_MODE,
321 AR5K_MISC_MODE_COMBINED_MIC);
322 }
323
324
325 ath5k_hw_set_lladdr(ah, zero_mac);
326
327
328 memcpy(common->curbssid, ath_bcast_mac, ETH_ALEN);
329 ath5k_hw_set_bssid(ah);
330 ath5k_hw_set_opmode(ah, ah->opmode);
331
332 ath5k_hw_rfgain_opt_init(ah);
333
334 ath5k_hw_init_nfcal_hist(ah);
335
336
337 ath5k_hw_set_ledstate(ah, AR5K_LED_INIT);
338
339 return 0;
340err:
341 return ret;
342}
343
344
345
346
347
348void ath5k_hw_deinit(struct ath5k_hw *ah)
349{
350 __set_bit(ATH_STAT_INVALID, ah->status);
351
352 if (ah->ah_rf_banks != NULL)
353 kfree(ah->ah_rf_banks);
354
355 ath5k_eeprom_detach(ah);
356
357
358}
359