xref: /linux/drivers/net/wireless/ath/ath9k/pci.c (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 
19 #include <linux/nl80211.h>
20 #include <linux/pci.h>
21 #include <linux/module.h>
22 #include "ath9k.h"
23 
24 static const struct pci_device_id ath_pci_id_table[] = {
25 	{ PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI   */
26 	{ PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
27 	{ PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI   */
28 
29 #ifdef CONFIG_ATH9K_PCOEM
30 	/* Mini PCI AR9220 MB92 cards: Compex WLM200NX, Wistron DNMA-92 */
31 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
32 			 0x0029,
33 			 PCI_VENDOR_ID_ATHEROS,
34 			 0x2096),
35 	  .driver_data = ATH9K_PCI_LED_ACT_HI },
36 #endif
37 
38 	{ PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI   */
39 
40 #ifdef CONFIG_ATH9K_PCOEM
41 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
42 			 0x002A,
43 			 PCI_VENDOR_ID_AZWAVE,
44 			 0x1C71),
45 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
46 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
47 			 0x002A,
48 			 PCI_VENDOR_ID_FOXCONN,
49 			 0xE01F),
50 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
51 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
52 			 0x002A,
53 			 0x11AD, /* LITEON */
54 			 0x6632),
55 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
56 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
57 			 0x002A,
58 			 0x11AD, /* LITEON */
59 			 0x6642),
60 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
61 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
62 			 0x002A,
63 			 PCI_VENDOR_ID_QMI,
64 			 0x0306),
65 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
66 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
67 			 0x002A,
68 			 0x185F, /* WNC */
69 			 0x309D),
70 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
71 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
72 			 0x002A,
73 			 0x10CF, /* Fujitsu */
74 			 0x147C),
75 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
76 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
77 			 0x002A,
78 			 0x10CF, /* Fujitsu */
79 			 0x147D),
80 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
81 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
82 			 0x002A,
83 			 0x10CF, /* Fujitsu */
84 			 0x1536),
85 	  .driver_data = ATH9K_PCI_D3_L1_WAR },
86 #endif
87 
88 	{ PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
89 
90 #ifdef CONFIG_ATH9K_PCOEM
91 	/* AR9285 card for Asus */
92 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
93 			 0x002B,
94 			 PCI_VENDOR_ID_AZWAVE,
95 			 0x2C37),
96 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
97 #endif
98 
99 	{ PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
100 	{ PCI_VDEVICE(ATHEROS, 0x002C) }, /* PCI-E 802.11n bonded out */
101 	{ PCI_VDEVICE(ATHEROS, 0x002D) }, /* PCI   */
102 	{ PCI_VDEVICE(ATHEROS, 0x002E) }, /* PCI-E */
103 
104 	/* Killer Wireless (3x3) */
105 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
106 			 0x0030,
107 			 0x1A56,
108 			 0x2000),
109 	  .driver_data = ATH9K_PCI_KILLER },
110 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
111 			 0x0030,
112 			 0x1A56,
113 			 0x2001),
114 	  .driver_data = ATH9K_PCI_KILLER },
115 
116 	{ PCI_VDEVICE(ATHEROS, 0x0030) }, /* PCI-E  AR9300 */
117 
118 #ifdef CONFIG_ATH9K_PCOEM
119 	/* PCI-E CUS198 */
120 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
121 			 0x0032,
122 			 PCI_VENDOR_ID_AZWAVE,
123 			 0x2086),
124 	  .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
125 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
126 			 0x0032,
127 			 PCI_VENDOR_ID_AZWAVE,
128 			 0x1237),
129 	  .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
130 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
131 			 0x0032,
132 			 PCI_VENDOR_ID_AZWAVE,
133 			 0x2126),
134 	  .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
135 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
136 			 0x0032,
137 			 PCI_VENDOR_ID_AZWAVE,
138 			 0x126A),
139 	  .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
140 
141 	/* PCI-E CUS230 */
142 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
143 			 0x0032,
144 			 PCI_VENDOR_ID_AZWAVE,
145 			 0x2152),
146 	  .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
147 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
148 			 0x0032,
149 			 PCI_VENDOR_ID_FOXCONN,
150 			 0xE075),
151 	  .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
152 
153 	/* WB225 */
154 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
155 			 0x0032,
156 			 PCI_VENDOR_ID_ATHEROS,
157 			 0x3119),
158 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
159 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
160 			 0x0032,
161 			 PCI_VENDOR_ID_ATHEROS,
162 			 0x3122),
163 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
164 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
165 			 0x0032,
166 			 0x185F, /* WNC */
167 			 0x3119),
168 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
169 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
170 			 0x0032,
171 			 0x185F, /* WNC */
172 			 0x3027),
173 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
174 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
175 			 0x0032,
176 			 PCI_VENDOR_ID_SAMSUNG,
177 			 0x4105),
178 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
179 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
180 			 0x0032,
181 			 PCI_VENDOR_ID_SAMSUNG,
182 			 0x4106),
183 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
184 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
185 			 0x0032,
186 			 PCI_VENDOR_ID_SAMSUNG,
187 			 0x410D),
188 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
189 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
190 			 0x0032,
191 			 PCI_VENDOR_ID_SAMSUNG,
192 			 0x410E),
193 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
194 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
195 			 0x0032,
196 			 PCI_VENDOR_ID_SAMSUNG,
197 			 0x410F),
198 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
199 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
200 			 0x0032,
201 			 PCI_VENDOR_ID_SAMSUNG,
202 			 0xC706),
203 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
204 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
205 			 0x0032,
206 			 PCI_VENDOR_ID_SAMSUNG,
207 			 0xC680),
208 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
209 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
210 			 0x0032,
211 			 PCI_VENDOR_ID_SAMSUNG,
212 			 0xC708),
213 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
214 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
215 			 0x0032,
216 			 PCI_VENDOR_ID_LENOVO,
217 			 0x3218),
218 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
219 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
220 			 0x0032,
221 			 PCI_VENDOR_ID_LENOVO,
222 			 0x3219),
223 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
224 
225 	/* AR9485 cards with PLL power-save disabled by default. */
226 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
227 			 0x0032,
228 			 PCI_VENDOR_ID_AZWAVE,
229 			 0x2C97),
230 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
231 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
232 			 0x0032,
233 			 PCI_VENDOR_ID_AZWAVE,
234 			 0x2100),
235 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
236 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
237 			 0x0032,
238 			 0x1C56, /* ASKEY */
239 			 0x4001),
240 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
241 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
242 			 0x0032,
243 			 0x11AD, /* LITEON */
244 			 0x6627),
245 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
246 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
247 			 0x0032,
248 			 0x11AD, /* LITEON */
249 			 0x6628),
250 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
251 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
252 			 0x0032,
253 			 PCI_VENDOR_ID_FOXCONN,
254 			 0xE04E),
255 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
256 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
257 			 0x0032,
258 			 PCI_VENDOR_ID_FOXCONN,
259 			 0xE04F),
260 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
261 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
262 			 0x0032,
263 			 0x144F, /* ASKEY */
264 			 0x7197),
265 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
266 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
267 			 0x0032,
268 			 0x1B9A, /* XAVI */
269 			 0x2000),
270 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
271 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
272 			 0x0032,
273 			 0x1B9A, /* XAVI */
274 			 0x2001),
275 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
276 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
277 			 0x0032,
278 			 PCI_VENDOR_ID_AZWAVE,
279 			 0x1186),
280 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
281 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
282 			 0x0032,
283 			 PCI_VENDOR_ID_AZWAVE,
284 			 0x1F86),
285 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
286 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
287 			 0x0032,
288 			 PCI_VENDOR_ID_AZWAVE,
289 			 0x1195),
290 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
291 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
292 			 0x0032,
293 			 PCI_VENDOR_ID_AZWAVE,
294 			 0x1F95),
295 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
296 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
297 			 0x0032,
298 			 0x1B9A, /* XAVI */
299 			 0x1C00),
300 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
301 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
302 			 0x0032,
303 			 0x1B9A, /* XAVI */
304 			 0x1C01),
305 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
306 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
307 			 0x0032,
308 			 PCI_VENDOR_ID_ASUSTEK,
309 			 0x850D),
310 	  .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
311 #endif
312 
313 	{ PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E  AR9485 */
314 	{ PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E  AR9580 */
315 
316 #ifdef CONFIG_ATH9K_PCOEM
317 	/* PCI-E CUS217 */
318 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
319 			 0x0034,
320 			 PCI_VENDOR_ID_AZWAVE,
321 			 0x2116),
322 	  .driver_data = ATH9K_PCI_CUS217 },
323 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
324 			 0x0034,
325 			 0x11AD, /* LITEON */
326 			 0x6661),
327 	  .driver_data = ATH9K_PCI_CUS217 },
328 
329 	/* AR9462 with WoW support */
330 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
331 			 0x0034,
332 			 PCI_VENDOR_ID_ATHEROS,
333 			 0x3117),
334 	  .driver_data = ATH9K_PCI_WOW },
335 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
336 			 0x0034,
337 			 PCI_VENDOR_ID_LENOVO,
338 			 0x3214),
339 	  .driver_data = ATH9K_PCI_WOW },
340 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
341 			 0x0034,
342 			 PCI_VENDOR_ID_ATTANSIC,
343 			 0x0091),
344 	  .driver_data = ATH9K_PCI_WOW },
345 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
346 			 0x0034,
347 			 PCI_VENDOR_ID_AZWAVE,
348 			 0x2110),
349 	  .driver_data = ATH9K_PCI_WOW },
350 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
351 			 0x0034,
352 			 PCI_VENDOR_ID_ASUSTEK,
353 			 0x850E),
354 	  .driver_data = ATH9K_PCI_WOW },
355 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
356 			 0x0034,
357 			 0x11AD, /* LITEON */
358 			 0x6631),
359 	  .driver_data = ATH9K_PCI_WOW },
360 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
361 			 0x0034,
362 			 0x11AD, /* LITEON */
363 			 0x6641),
364 	  .driver_data = ATH9K_PCI_WOW },
365 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
366 			 0x0034,
367 			 PCI_VENDOR_ID_HP,
368 			 0x1864),
369 	  .driver_data = ATH9K_PCI_WOW },
370 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
371 			 0x0034,
372 			 0x14CD, /* USI */
373 			 0x0063),
374 	  .driver_data = ATH9K_PCI_WOW },
375 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
376 			 0x0034,
377 			 0x14CD, /* USI */
378 			 0x0064),
379 	  .driver_data = ATH9K_PCI_WOW },
380 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
381 			 0x0034,
382 			 0x10CF, /* Fujitsu */
383 			 0x1783),
384 	  .driver_data = ATH9K_PCI_WOW },
385 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
386 			 0x0034,
387 			 PCI_VENDOR_ID_DELL,
388 			 0x020B),
389 	  .driver_data = ATH9K_PCI_WOW },
390 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
391 			 0x0034,
392 			 PCI_VENDOR_ID_DELL,
393 			 0x0300),
394 	  .driver_data = ATH9K_PCI_WOW },
395 
396 	/* Killer Wireless (2x2) */
397 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
398 			 0x0030,
399 			 0x1A56,
400 			 0x2003),
401 	  .driver_data = ATH9K_PCI_KILLER },
402 
403 	{ PCI_VDEVICE(ATHEROS, 0x0034) }, /* PCI-E  AR9462 */
404 	{ PCI_VDEVICE(ATHEROS, 0x0037) }, /* PCI-E  AR1111/AR9485 */
405 
406 	/* CUS252 */
407 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
408 			 0x0036,
409 			 PCI_VENDOR_ID_ATHEROS,
410 			 0x3028),
411 	  .driver_data = ATH9K_PCI_CUS252 |
412 			 ATH9K_PCI_AR9565_2ANT |
413 			 ATH9K_PCI_BT_ANT_DIV },
414 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
415 			 0x0036,
416 			 PCI_VENDOR_ID_AZWAVE,
417 			 0x2176),
418 	  .driver_data = ATH9K_PCI_CUS252 |
419 			 ATH9K_PCI_AR9565_2ANT |
420 			 ATH9K_PCI_BT_ANT_DIV },
421 
422 	/* WB335 1-ANT */
423 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
424 			 0x0036,
425 			 PCI_VENDOR_ID_FOXCONN,
426 			 0xE068),
427 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
428 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
429 			 0x0036,
430 			 0x185F, /* WNC */
431 			 0xA119),
432 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
433 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
434 			 0x0036,
435 			 0x11AD, /* LITEON */
436 			 0x0632),
437 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
438 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
439 			 0x0036,
440 			 0x11AD, /* LITEON */
441 			 0x06B2),
442 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
443 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
444 			 0x0036,
445 			 0x11AD, /* LITEON */
446 			 0x0842),
447 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
448 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
449 			 0x0036,
450 			 0x11AD, /* LITEON */
451 			 0x1842),
452 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
453 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
454 			 0x0036,
455 			 0x11AD, /* LITEON */
456 			 0x6671),
457 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
458 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
459 			 0x0036,
460 			 0x1B9A, /* XAVI */
461 			 0x2811),
462 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
463 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
464 			 0x0036,
465 			 0x1B9A, /* XAVI */
466 			 0x2812),
467 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
468 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
469 			 0x0036,
470 			 0x1B9A, /* XAVI */
471 			 0x28A1),
472 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
473 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
474 			 0x0036,
475 			 0x1B9A, /* XAVI */
476 			 0x28A3),
477 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
478 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
479 			 0x0036,
480 			 PCI_VENDOR_ID_AZWAVE,
481 			 0x218A),
482 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
483 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
484 			 0x0036,
485 			 PCI_VENDOR_ID_AZWAVE,
486 			 0x2F8A),
487 	  .driver_data = ATH9K_PCI_AR9565_1ANT },
488 
489 	/* WB335 1-ANT / Antenna Diversity */
490 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
491 			 0x0036,
492 			 PCI_VENDOR_ID_ATHEROS,
493 			 0x3025),
494 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
495 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
496 			 0x0036,
497 			 PCI_VENDOR_ID_ATHEROS,
498 			 0x3026),
499 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
500 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
501 			 0x0036,
502 			 PCI_VENDOR_ID_ATHEROS,
503 			 0x302B),
504 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
505 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
506 			 0x0036,
507 			 PCI_VENDOR_ID_FOXCONN,
508 			 0xE069),
509 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
510 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
511 			 0x0036,
512 			 0x185F, /* WNC */
513 			 0x3028),
514 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
515 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
516 			 0x0036,
517 			 0x11AD, /* LITEON */
518 			 0x0622),
519 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
520 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
521 			 0x0036,
522 			 0x11AD, /* LITEON */
523 			 0x0672),
524 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
525 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
526 			 0x0036,
527 			 0x11AD, /* LITEON */
528 			 0x0662),
529 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
530 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
531 			 0x0036,
532 			 0x11AD, /* LITEON */
533 			 0x06A2),
534 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
535 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
536 			 0x0036,
537 			 0x11AD, /* LITEON */
538 			 0x0682),
539 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
540 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
541 			 0x0036,
542 			 PCI_VENDOR_ID_AZWAVE,
543 			 0x213A),
544 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
545 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
546 			 0x0036,
547 			 PCI_VENDOR_ID_AZWAVE,
548 			 0x213C),
549 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
550 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
551 			 0x0036,
552 			 PCI_VENDOR_ID_HP,
553 			 0x18E3),
554 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
555 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
556 			 0x0036,
557 			 PCI_VENDOR_ID_HP,
558 			 0x217F),
559 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
560 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
561 			 0x0036,
562 			 PCI_VENDOR_ID_HP,
563 			 0x2005),
564 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
565 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
566 			 0x0036,
567 			 PCI_VENDOR_ID_DELL,
568 			 0x020C),
569 	  .driver_data = ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_BT_ANT_DIV },
570 
571 	/* WB335 2-ANT / Antenna-Diversity */
572 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
573 			 0x0036,
574 			 PCI_VENDOR_ID_SAMSUNG,
575 			 0x411A),
576 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
577 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
578 			 0x0036,
579 			 PCI_VENDOR_ID_SAMSUNG,
580 			 0x411B),
581 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
582 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
583 			 0x0036,
584 			 PCI_VENDOR_ID_SAMSUNG,
585 			 0x411C),
586 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
587 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
588 			 0x0036,
589 			 PCI_VENDOR_ID_SAMSUNG,
590 			 0x411D),
591 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
592 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
593 			 0x0036,
594 			 PCI_VENDOR_ID_SAMSUNG,
595 			 0x411E),
596 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
597 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
598 			 0x0036,
599 			 PCI_VENDOR_ID_SAMSUNG,
600 			 0x4129),
601 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
602 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
603 			 0x0036,
604 			 PCI_VENDOR_ID_SAMSUNG,
605 			 0x412A),
606 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
607 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
608 			 0x0036,
609 			 PCI_VENDOR_ID_ATHEROS,
610 			 0x3027),
611 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
612 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
613 			 0x0036,
614 			 PCI_VENDOR_ID_ATHEROS,
615 			 0x302C),
616 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
617 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
618 			 0x0036,
619 			 0x11AD, /* LITEON */
620 			 0x0642),
621 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
622 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
623 			 0x0036,
624 			 0x11AD, /* LITEON */
625 			 0x0652),
626 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
627 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
628 			 0x0036,
629 			 0x11AD, /* LITEON */
630 			 0x0612),
631 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
632 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
633 			 0x0036,
634 			 0x11AD, /* LITEON */
635 			 0x0832),
636 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
637 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
638 			 0x0036,
639 			 0x11AD, /* LITEON */
640 			 0x1832),
641 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
642 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
643 			 0x0036,
644 			 0x11AD, /* LITEON */
645 			 0x0692),
646 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
647 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
648 			 0x0036,
649 			 0x11AD, /* LITEON */
650 			 0x0803),
651 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
652 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
653 			 0x0036,
654 			 0x11AD, /* LITEON */
655 			 0x0813),
656 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
657 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
658 			 0x0036,
659 			 PCI_VENDOR_ID_AZWAVE,
660 			 0x2130),
661 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
662 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
663 			 0x0036,
664 			 PCI_VENDOR_ID_AZWAVE,
665 			 0x213B),
666 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
667 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
668 			 0x0036,
669 			 PCI_VENDOR_ID_AZWAVE,
670 			 0x2182),
671 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
672 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
673 			 0x0036,
674 			 PCI_VENDOR_ID_AZWAVE,
675 			 0x218B),
676 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
677 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
678 			 0x0036,
679 			 PCI_VENDOR_ID_AZWAVE,
680 			 0x218C),
681 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
682 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
683 			 0x0036,
684 			 PCI_VENDOR_ID_AZWAVE,
685 			 0x2F82),
686 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
687 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
688 			 0x0036,
689 			 0x144F, /* ASKEY */
690 			 0x7202),
691 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
692 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
693 			 0x0036,
694 			 0x1B9A, /* XAVI */
695 			 0x2810),
696 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
697 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
698 			 0x0036,
699 			 0x1B9A, /* XAVI */
700 			 0x2813),
701 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
702 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
703 			 0x0036,
704 			 0x1B9A, /* XAVI */
705 			 0x28A2),
706 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
707 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
708 			 0x0036,
709 			 0x1B9A, /* XAVI */
710 			 0x28A4),
711 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
712 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
713 			 0x0036,
714 			 0x185F, /* WNC */
715 			 0x3027),
716 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
717 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
718 			 0x0036,
719 			 0x185F, /* WNC */
720 			 0xA120),
721 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
722 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
723 			 0x0036,
724 			 PCI_VENDOR_ID_FOXCONN,
725 			 0xE07F),
726 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
727 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
728 			 0x0036,
729 			 PCI_VENDOR_ID_FOXCONN,
730 			 0xE08F),
731 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
732 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
733 			 0x0036,
734 			 PCI_VENDOR_ID_FOXCONN,
735 			 0xE081),
736 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
737 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
738 			 0x0036,
739 			 PCI_VENDOR_ID_FOXCONN,
740 			 0xE091),
741 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
742 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
743 			 0x0036,
744 			 PCI_VENDOR_ID_FOXCONN,
745 			 0xE099),
746 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
747 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
748 			 0x0036,
749 			 PCI_VENDOR_ID_LENOVO,
750 			 0x3026),
751 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
752 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
753 			 0x0036,
754 			 PCI_VENDOR_ID_LENOVO,
755 			 0x4026),
756 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
757 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
758 			 0x0036,
759 			 PCI_VENDOR_ID_ASUSTEK,
760 			 0x85F2),
761 	  .driver_data = ATH9K_PCI_AR9565_2ANT | ATH9K_PCI_BT_ANT_DIV },
762 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
763 			 0x0036,
764 			 PCI_VENDOR_ID_DELL,
765 			 0x020E),
766 	  .driver_data = ATH9K_PCI_AR9565_2ANT |
767 			 ATH9K_PCI_BT_ANT_DIV |
768 			 ATH9K_PCI_LED_ACT_HI},
769 
770 	/* PCI-E AR9565 (WB335) */
771 	{ PCI_VDEVICE(ATHEROS, 0x0036),
772 	  .driver_data = ATH9K_PCI_BT_ANT_DIV },
773 #endif
774 
775 	{ 0 }
776 };
777 
778 
779 /* return bus cachesize in 4B word units */
ath_pci_read_cachesize(struct ath_common * common,int * csz)780 static void ath_pci_read_cachesize(struct ath_common *common, int *csz)
781 {
782 	struct ath_softc *sc = common->priv;
783 	u8 u8tmp;
784 
785 	pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE, &u8tmp);
786 	*csz = (int)u8tmp;
787 
788 	/*
789 	 * This check was put in to avoid "unpleasant" consequences if
790 	 * the bootrom has not fully initialized all PCI devices.
791 	 * Sometimes the cache line size register is not set
792 	 */
793 
794 	if (*csz == 0)
795 		*csz = DEFAULT_CACHELINE >> 2;   /* Use the default size */
796 }
797 
ath_pci_eeprom_read(struct ath_common * common,u32 off,u16 * data)798 static bool ath_pci_eeprom_read(struct ath_common *common, u32 off, u16 *data)
799 {
800 	struct ath_hw *ah = common->ah;
801 
802 	common->ops->read(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
803 
804 	if (!ath9k_hw_wait(ah,
805 				AR_EEPROM_STATUS_DATA(ah),
806 				AR_EEPROM_STATUS_DATA_BUSY |
807 				AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
808 				AH_WAIT_TIMEOUT)) {
809 		return false;
810 	}
811 
812 	*data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA(ah)),
813 			AR_EEPROM_STATUS_DATA_VAL);
814 
815 	return true;
816 }
817 
818 /* Need to be called after we discover btcoex capabilities */
ath_pci_aspm_init(struct ath_common * common)819 static void ath_pci_aspm_init(struct ath_common *common)
820 {
821 	struct ath_softc *sc = common->priv;
822 	struct ath_hw *ah = sc->sc_ah;
823 	struct pci_dev *pdev = to_pci_dev(sc->dev);
824 	struct pci_dev *parent;
825 	u16 aspm;
826 	int ret;
827 
828 	if (!ah->is_pciexpress)
829 		return;
830 
831 	parent = pdev->bus->self;
832 	if (!parent)
833 		return;
834 
835 	if ((ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) &&
836 	    (AR_SREV_9285(ah))) {
837 		/* Bluetooth coexistence requires disabling ASPM. */
838 		pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL,
839 			PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1);
840 
841 		/*
842 		 * Both upstream and downstream PCIe components should
843 		 * have the same ASPM settings.
844 		 */
845 		pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
846 			PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1);
847 
848 		ath_info(common, "Disabling ASPM since BTCOEX is enabled\n");
849 		return;
850 	}
851 
852 	/*
853 	 * 0x70c - Ack Frequency Register.
854 	 *
855 	 * Bits 27:29 - DEFAULT_L1_ENTRANCE_LATENCY.
856 	 *
857 	 * 000 : 1 us
858 	 * 001 : 2 us
859 	 * 010 : 4 us
860 	 * 011 : 8 us
861 	 * 100 : 16 us
862 	 * 101 : 32 us
863 	 * 110/111 : 64 us
864 	 */
865 	if (AR_SREV_9462(ah))
866 		pci_read_config_dword(pdev, 0x70c, &ah->config.aspm_l1_fix);
867 
868 	ret = pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
869 	if (!ret && (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1))) {
870 		ah->aspm_enabled = true;
871 		/* Initialize PCIe PM and SERDES registers. */
872 		ath9k_hw_configpcipowersave(ah, false);
873 		ath_info(common, "ASPM enabled: 0x%x\n", aspm);
874 	}
875 }
876 
877 static const struct ath_bus_ops ath_pci_bus_ops = {
878 	.ath_bus_type = ATH_PCI,
879 	.read_cachesize = ath_pci_read_cachesize,
880 	.eeprom_read = ath_pci_eeprom_read,
881 	.aspm_init = ath_pci_aspm_init,
882 };
883 
ath_pci_probe(struct pci_dev * pdev,const struct pci_device_id * id)884 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
885 {
886 	struct ath_softc *sc;
887 	struct ieee80211_hw *hw;
888 	u8 csz;
889 	u32 val;
890 	int ret = 0;
891 	char hw_name[64];
892 	int msi_enabled = 0;
893 
894 	if (pcim_enable_device(pdev))
895 		return -EIO;
896 
897 	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
898 	if (ret) {
899 		pr_err("32-bit DMA not available\n");
900 		return ret;
901 	}
902 
903 	/*
904 	 * Cache line size is used to size and align various
905 	 * structures used to communicate with the hardware.
906 	 */
907 	pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
908 	if (csz == 0) {
909 		/*
910 		 * Linux 2.4.18 (at least) writes the cache line size
911 		 * register as a 16-bit wide register which is wrong.
912 		 * We must have this setup properly for rx buffer
913 		 * DMA to work so force a reasonable value here if it
914 		 * comes up zero.
915 		 */
916 		csz = L1_CACHE_BYTES / sizeof(u32);
917 		pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
918 	}
919 	/*
920 	 * The default setting of latency timer yields poor results,
921 	 * set it to the value used by other systems. It may be worth
922 	 * tweaking this setting more.
923 	 */
924 	pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
925 
926 	pci_set_master(pdev);
927 
928 	/*
929 	 * Disable the RETRY_TIMEOUT register (0x41) to keep
930 	 * PCI Tx retries from interfering with C3 CPU state.
931 	 */
932 	pci_read_config_dword(pdev, 0x40, &val);
933 	if ((val & 0x0000ff00) != 0)
934 		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
935 
936 	ret = pcim_iomap_regions(pdev, BIT(0), "ath9k");
937 	if (ret) {
938 		dev_err(&pdev->dev, "PCI memory region reserve error\n");
939 		return -ENODEV;
940 	}
941 
942 	ath9k_fill_chanctx_ops();
943 	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
944 	if (!hw) {
945 		dev_err(&pdev->dev, "No memory for ieee80211_hw\n");
946 		return -ENOMEM;
947 	}
948 
949 	SET_IEEE80211_DEV(hw, &pdev->dev);
950 	pci_set_drvdata(pdev, hw);
951 
952 	sc = hw->priv;
953 	sc->hw = hw;
954 	sc->dev = &pdev->dev;
955 	sc->mem = pcim_iomap_table(pdev)[0];
956 	sc->driver_data = id->driver_data;
957 
958 	if (ath9k_use_msi) {
959 		if (pci_enable_msi(pdev) == 0) {
960 			msi_enabled = 1;
961 			dev_err(&pdev->dev, "Using MSI\n");
962 		} else {
963 			dev_err(&pdev->dev, "Using INTx\n");
964 		}
965 	}
966 
967 	if (!msi_enabled)
968 		ret = request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath9k", sc);
969 	else
970 		ret = request_irq(pdev->irq, ath_isr, 0, "ath9k", sc);
971 
972 	if (ret) {
973 		dev_err(&pdev->dev, "request_irq failed\n");
974 		goto err_irq;
975 	}
976 
977 	sc->irq = pdev->irq;
978 
979 	ret = ath9k_init_device(id->device, sc, &ath_pci_bus_ops);
980 	if (ret) {
981 		dev_err(&pdev->dev, "Failed to initialize device\n");
982 		goto err_init;
983 	}
984 
985 	sc->sc_ah->msi_enabled = msi_enabled;
986 	sc->sc_ah->msi_reg = 0;
987 
988 	ath9k_hw_name(sc->sc_ah, hw_name, sizeof(hw_name));
989 	wiphy_info(hw->wiphy, "%s mem=0x%p, irq=%d\n",
990 		   hw_name, sc->mem, pdev->irq);
991 
992 	return 0;
993 
994 err_init:
995 	free_irq(sc->irq, sc);
996 err_irq:
997 	ieee80211_free_hw(hw);
998 	return ret;
999 }
1000 
ath_pci_remove(struct pci_dev * pdev)1001 static void ath_pci_remove(struct pci_dev *pdev)
1002 {
1003 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1004 	struct ath_softc *sc = hw->priv;
1005 
1006 	if (!is_ath9k_unloaded)
1007 		sc->sc_ah->ah_flags |= AH_UNPLUGGED;
1008 	ath9k_deinit_device(sc);
1009 	free_irq(sc->irq, sc);
1010 	ieee80211_free_hw(sc->hw);
1011 }
1012 
1013 #ifdef CONFIG_PM_SLEEP
1014 
ath_pci_suspend(struct device * device)1015 static int ath_pci_suspend(struct device *device)
1016 {
1017 	struct ieee80211_hw *hw = dev_get_drvdata(device);
1018 	struct ath_softc *sc = hw->priv;
1019 	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1020 
1021 	if (test_bit(ATH_OP_WOW_ENABLED, &common->op_flags)) {
1022 		dev_info(device, "WOW is enabled, bypassing PCI suspend\n");
1023 		return 0;
1024 	}
1025 
1026 	/* The device has to be moved to FULLSLEEP forcibly.
1027 	 * Otherwise the chip never moved to full sleep,
1028 	 * when no interface is up.
1029 	 */
1030 	ath9k_stop_btcoex(sc);
1031 	ath9k_hw_disable(sc->sc_ah);
1032 	del_timer_sync(&sc->sleep_timer);
1033 	ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
1034 
1035 	return 0;
1036 }
1037 
ath_pci_resume(struct device * device)1038 static int ath_pci_resume(struct device *device)
1039 {
1040 	struct pci_dev *pdev = to_pci_dev(device);
1041 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1042 	struct ath_softc *sc = hw->priv;
1043 	struct ath_hw *ah = sc->sc_ah;
1044 	struct ath_common *common = ath9k_hw_common(ah);
1045 	u32 val;
1046 
1047 	/*
1048 	 * Suspend/Resume resets the PCI configuration space, so we have to
1049 	 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1050 	 * PCI Tx retries from interfering with C3 CPU state
1051 	 */
1052 	pci_read_config_dword(pdev, 0x40, &val);
1053 	if ((val & 0x0000ff00) != 0)
1054 		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1055 
1056 	ath_pci_aspm_init(common);
1057 	ah->reset_power_on = false;
1058 
1059 	return 0;
1060 }
1061 
1062 static SIMPLE_DEV_PM_OPS(ath9k_pm_ops, ath_pci_suspend, ath_pci_resume);
1063 
1064 #define ATH9K_PM_OPS	(&ath9k_pm_ops)
1065 
1066 #else /* !CONFIG_PM_SLEEP */
1067 
1068 #define ATH9K_PM_OPS	NULL
1069 
1070 #endif /* !CONFIG_PM_SLEEP */
1071 
1072 
1073 MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
1074 
1075 static struct pci_driver ath_pci_driver = {
1076 	.name       = "ath9k",
1077 	.id_table   = ath_pci_id_table,
1078 	.probe      = ath_pci_probe,
1079 	.remove     = ath_pci_remove,
1080 	.driver.pm  = ATH9K_PM_OPS,
1081 };
1082 
ath_pci_init(void)1083 int ath_pci_init(void)
1084 {
1085 	return pci_register_driver(&ath_pci_driver);
1086 }
1087 
ath_pci_exit(void)1088 void ath_pci_exit(void)
1089 {
1090 	pci_unregister_driver(&ath_pci_driver);
1091 }
1092