blob: 255300c912d489ca6aafb8889bf16dcb304bd1e4 [file] [log] [blame]
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001/*
2 * RTL8XXXU mac80211 USB driver
3 *
4 * Copyright (c) 2014 - 2015 Jes Sorensen <Jes.Sorensen@redhat.com>
5 *
6 * Portions, notably calibration code:
7 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
8 *
9 * This driver was written as a replacement for the vendor provided
10 * rtl8723au driver. As the Realtek 8xxx chips are very similar in
11 * their programming interface, I have started adding support for
12 * additional 8xxx chips like the 8192cu, 8188cus, etc.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of version 2 of the GNU General Public License as
16 * published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */
23
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/errno.h>
28#include <linux/slab.h>
29#include <linux/module.h>
30#include <linux/spinlock.h>
31#include <linux/list.h>
32#include <linux/usb.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/ethtool.h>
36#include <linux/wireless.h>
37#include <linux/firmware.h>
38#include <linux/moduleparam.h>
39#include <net/mac80211.h>
40#include "rtl8xxxu.h"
41#include "rtl8xxxu_regs.h"
42
43#define DRIVER_NAME "rtl8xxxu"
44
Jes Sorensen3307d842016-02-29 17:03:59 -050045static int rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE;
Jes Sorensen26f1fad2015-10-14 20:44:51 -040046static bool rtl8xxxu_ht40_2g;
47
48MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@redhat.com>");
49MODULE_DESCRIPTION("RTL8XXXu USB mac80211 Wireless LAN Driver");
50MODULE_LICENSE("GPL");
51MODULE_FIRMWARE("rtlwifi/rtl8723aufw_A.bin");
52MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B.bin");
53MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B_NoBT.bin");
54MODULE_FIRMWARE("rtlwifi/rtl8192cufw_A.bin");
55MODULE_FIRMWARE("rtlwifi/rtl8192cufw_B.bin");
56MODULE_FIRMWARE("rtlwifi/rtl8192cufw_TMSC.bin");
Jes Sorensenb001e082016-02-29 17:04:02 -050057MODULE_FIRMWARE("rtlwifi/rtl8192eu_nic.bin");
Jes Sorensen35a741f2016-02-29 17:04:10 -050058MODULE_FIRMWARE("rtlwifi/rtl8723bu_nic.bin");
59MODULE_FIRMWARE("rtlwifi/rtl8723bu_bt.bin");
Jes Sorensen26f1fad2015-10-14 20:44:51 -040060
61module_param_named(debug, rtl8xxxu_debug, int, 0600);
62MODULE_PARM_DESC(debug, "Set debug mask");
63module_param_named(ht40_2g, rtl8xxxu_ht40_2g, bool, 0600);
64MODULE_PARM_DESC(ht40_2g, "Enable HT40 support on the 2.4GHz band");
65
66#define USB_VENDOR_ID_REALTEK 0x0bda
67/* Minimum IEEE80211_MAX_FRAME_LEN */
68#define RTL_RX_BUFFER_SIZE IEEE80211_MAX_FRAME_LEN
69#define RTL8XXXU_RX_URBS 32
70#define RTL8XXXU_RX_URB_PENDING_WATER 8
71#define RTL8XXXU_TX_URBS 64
72#define RTL8XXXU_TX_URB_LOW_WATER 25
73#define RTL8XXXU_TX_URB_HIGH_WATER 32
74
75static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
76 struct rtl8xxxu_rx_urb *rx_urb);
77
78static struct ieee80211_rate rtl8xxxu_rates[] = {
79 { .bitrate = 10, .hw_value = DESC_RATE_1M, .flags = 0 },
80 { .bitrate = 20, .hw_value = DESC_RATE_2M, .flags = 0 },
81 { .bitrate = 55, .hw_value = DESC_RATE_5_5M, .flags = 0 },
82 { .bitrate = 110, .hw_value = DESC_RATE_11M, .flags = 0 },
83 { .bitrate = 60, .hw_value = DESC_RATE_6M, .flags = 0 },
84 { .bitrate = 90, .hw_value = DESC_RATE_9M, .flags = 0 },
85 { .bitrate = 120, .hw_value = DESC_RATE_12M, .flags = 0 },
86 { .bitrate = 180, .hw_value = DESC_RATE_18M, .flags = 0 },
87 { .bitrate = 240, .hw_value = DESC_RATE_24M, .flags = 0 },
88 { .bitrate = 360, .hw_value = DESC_RATE_36M, .flags = 0 },
89 { .bitrate = 480, .hw_value = DESC_RATE_48M, .flags = 0 },
90 { .bitrate = 540, .hw_value = DESC_RATE_54M, .flags = 0 },
91};
92
93static struct ieee80211_channel rtl8xxxu_channels_2g[] = {
94 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412,
95 .hw_value = 1, .max_power = 30 },
96 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417,
97 .hw_value = 2, .max_power = 30 },
98 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422,
99 .hw_value = 3, .max_power = 30 },
100 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427,
101 .hw_value = 4, .max_power = 30 },
102 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432,
103 .hw_value = 5, .max_power = 30 },
104 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437,
105 .hw_value = 6, .max_power = 30 },
106 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442,
107 .hw_value = 7, .max_power = 30 },
108 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447,
109 .hw_value = 8, .max_power = 30 },
110 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452,
111 .hw_value = 9, .max_power = 30 },
112 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457,
113 .hw_value = 10, .max_power = 30 },
114 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462,
115 .hw_value = 11, .max_power = 30 },
116 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467,
117 .hw_value = 12, .max_power = 30 },
118 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472,
119 .hw_value = 13, .max_power = 30 },
120 { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484,
121 .hw_value = 14, .max_power = 30 }
122};
123
124static struct ieee80211_supported_band rtl8xxxu_supported_band = {
125 .channels = rtl8xxxu_channels_2g,
126 .n_channels = ARRAY_SIZE(rtl8xxxu_channels_2g),
127 .bitrates = rtl8xxxu_rates,
128 .n_bitrates = ARRAY_SIZE(rtl8xxxu_rates),
129};
130
131static struct rtl8xxxu_reg8val rtl8723a_mac_init_table[] = {
132 {0x420, 0x80}, {0x423, 0x00}, {0x430, 0x00}, {0x431, 0x00},
133 {0x432, 0x00}, {0x433, 0x01}, {0x434, 0x04}, {0x435, 0x05},
134 {0x436, 0x06}, {0x437, 0x07}, {0x438, 0x00}, {0x439, 0x00},
135 {0x43a, 0x00}, {0x43b, 0x01}, {0x43c, 0x04}, {0x43d, 0x05},
136 {0x43e, 0x06}, {0x43f, 0x07}, {0x440, 0x5d}, {0x441, 0x01},
137 {0x442, 0x00}, {0x444, 0x15}, {0x445, 0xf0}, {0x446, 0x0f},
138 {0x447, 0x00}, {0x458, 0x41}, {0x459, 0xa8}, {0x45a, 0x72},
139 {0x45b, 0xb9}, {0x460, 0x66}, {0x461, 0x66}, {0x462, 0x08},
140 {0x463, 0x03}, {0x4c8, 0xff}, {0x4c9, 0x08}, {0x4cc, 0xff},
141 {0x4cd, 0xff}, {0x4ce, 0x01}, {0x500, 0x26}, {0x501, 0xa2},
142 {0x502, 0x2f}, {0x503, 0x00}, {0x504, 0x28}, {0x505, 0xa3},
143 {0x506, 0x5e}, {0x507, 0x00}, {0x508, 0x2b}, {0x509, 0xa4},
144 {0x50a, 0x5e}, {0x50b, 0x00}, {0x50c, 0x4f}, {0x50d, 0xa4},
145 {0x50e, 0x00}, {0x50f, 0x00}, {0x512, 0x1c}, {0x514, 0x0a},
146 {0x515, 0x10}, {0x516, 0x0a}, {0x517, 0x10}, {0x51a, 0x16},
147 {0x524, 0x0f}, {0x525, 0x4f}, {0x546, 0x40}, {0x547, 0x00},
148 {0x550, 0x10}, {0x551, 0x10}, {0x559, 0x02}, {0x55a, 0x02},
149 {0x55d, 0xff}, {0x605, 0x30}, {0x608, 0x0e}, {0x609, 0x2a},
150 {0x652, 0x20}, {0x63c, 0x0a}, {0x63d, 0x0a}, {0x63e, 0x0e},
151 {0x63f, 0x0e}, {0x66e, 0x05}, {0x700, 0x21}, {0x701, 0x43},
152 {0x702, 0x65}, {0x703, 0x87}, {0x708, 0x21}, {0x709, 0x43},
153 {0x70a, 0x65}, {0x70b, 0x87}, {0xffff, 0xff},
154};
155
156static struct rtl8xxxu_reg32val rtl8723a_phy_1t_init_table[] = {
157 {0x800, 0x80040000}, {0x804, 0x00000003},
158 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
159 {0x810, 0x10001331}, {0x814, 0x020c3d10},
160 {0x818, 0x02200385}, {0x81c, 0x00000000},
161 {0x820, 0x01000100}, {0x824, 0x00390004},
162 {0x828, 0x00000000}, {0x82c, 0x00000000},
163 {0x830, 0x00000000}, {0x834, 0x00000000},
164 {0x838, 0x00000000}, {0x83c, 0x00000000},
165 {0x840, 0x00010000}, {0x844, 0x00000000},
166 {0x848, 0x00000000}, {0x84c, 0x00000000},
167 {0x850, 0x00000000}, {0x854, 0x00000000},
168 {0x858, 0x569a569a}, {0x85c, 0x001b25a4},
169 {0x860, 0x66f60110}, {0x864, 0x061f0130},
170 {0x868, 0x00000000}, {0x86c, 0x32323200},
171 {0x870, 0x07000760}, {0x874, 0x22004000},
172 {0x878, 0x00000808}, {0x87c, 0x00000000},
173 {0x880, 0xc0083070}, {0x884, 0x000004d5},
174 {0x888, 0x00000000}, {0x88c, 0xccc000c0},
175 {0x890, 0x00000800}, {0x894, 0xfffffffe},
176 {0x898, 0x40302010}, {0x89c, 0x00706050},
177 {0x900, 0x00000000}, {0x904, 0x00000023},
178 {0x908, 0x00000000}, {0x90c, 0x81121111},
179 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
180 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
181 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
182 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
183 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
184 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
185 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
186 {0xa78, 0x00000900},
187 {0xc00, 0x48071d40}, {0xc04, 0x03a05611},
188 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
189 {0xc10, 0x08800000}, {0xc14, 0x40000100},
190 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
191 {0xc20, 0x00000000}, {0xc24, 0x00000000},
192 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
193 {0xc30, 0x69e9ac44}, {0xc34, 0x469652af},
194 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
195 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
196 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
197 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
198 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
199 {0xc60, 0x00000000}, {0xc64, 0x7112848b},
200 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
201 {0xc70, 0x2c7f000d}, {0xc74, 0x018610db},
202 {0xc78, 0x0000001f}, {0xc7c, 0x00b91612},
203 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
204 {0xc88, 0x40000100}, {0xc8c, 0x20200000},
205 {0xc90, 0x00121820}, {0xc94, 0x00000000},
206 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
207 {0xca0, 0x00000000}, {0xca4, 0x00000080},
208 {0xca8, 0x00000000}, {0xcac, 0x00000000},
209 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
210 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
211 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
212 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
213 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
214 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
215 {0xce0, 0x00222222}, {0xce4, 0x00000000},
216 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
217 {0xd00, 0x00080740}, {0xd04, 0x00020401},
218 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
219 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
220 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
221 {0xd30, 0x00000000}, {0xd34, 0x80608000},
222 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
223 {0xd40, 0x00000000}, {0xd44, 0x00000000},
224 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
225 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
226 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
227 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
228 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
229 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
230 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
231 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
232 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
233 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
234 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
235 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
236 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
237 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
238 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
239 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
240 {0xe5c, 0x28160d05}, {0xe60, 0x00000008},
241 {0xe68, 0x001b25a4}, {0xe6c, 0x631b25a0},
242 {0xe70, 0x631b25a0}, {0xe74, 0x081b25a0},
243 {0xe78, 0x081b25a0}, {0xe7c, 0x081b25a0},
244 {0xe80, 0x081b25a0}, {0xe84, 0x631b25a0},
245 {0xe88, 0x081b25a0}, {0xe8c, 0x631b25a0},
246 {0xed0, 0x631b25a0}, {0xed4, 0x631b25a0},
247 {0xed8, 0x631b25a0}, {0xedc, 0x001b25a0},
248 {0xee0, 0x001b25a0}, {0xeec, 0x6b1b25a0},
249 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
250 {0xf00, 0x00000300},
251 {0xffff, 0xffffffff},
252};
253
254static struct rtl8xxxu_reg32val rtl8192cu_phy_2t_init_table[] = {
255 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
256 {0x800, 0x80040002}, {0x804, 0x00000003},
257 {0x808, 0x0000fc00}, {0x80c, 0x0000000a},
258 {0x810, 0x10000330}, {0x814, 0x020c3d10},
259 {0x818, 0x02200385}, {0x81c, 0x00000000},
260 {0x820, 0x01000100}, {0x824, 0x00390004},
261 {0x828, 0x01000100}, {0x82c, 0x00390004},
262 {0x830, 0x27272727}, {0x834, 0x27272727},
263 {0x838, 0x27272727}, {0x83c, 0x27272727},
264 {0x840, 0x00010000}, {0x844, 0x00010000},
265 {0x848, 0x27272727}, {0x84c, 0x27272727},
266 {0x850, 0x00000000}, {0x854, 0x00000000},
267 {0x858, 0x569a569a}, {0x85c, 0x0c1b25a4},
268 {0x860, 0x66e60230}, {0x864, 0x061f0130},
269 {0x868, 0x27272727}, {0x86c, 0x2b2b2b27},
270 {0x870, 0x07000700}, {0x874, 0x22184000},
271 {0x878, 0x08080808}, {0x87c, 0x00000000},
272 {0x880, 0xc0083070}, {0x884, 0x000004d5},
273 {0x888, 0x00000000}, {0x88c, 0xcc0000c0},
274 {0x890, 0x00000800}, {0x894, 0xfffffffe},
275 {0x898, 0x40302010}, {0x89c, 0x00706050},
276 {0x900, 0x00000000}, {0x904, 0x00000023},
277 {0x908, 0x00000000}, {0x90c, 0x81121313},
278 {0xa00, 0x00d047c8}, {0xa04, 0x80ff000c},
279 {0xa08, 0x8c838300}, {0xa0c, 0x2e68120f},
280 {0xa10, 0x9500bb78}, {0xa14, 0x11144028},
281 {0xa18, 0x00881117}, {0xa1c, 0x89140f00},
282 {0xa20, 0x1a1b0000}, {0xa24, 0x090e1317},
283 {0xa28, 0x00000204}, {0xa2c, 0x00d30000},
284 {0xa70, 0x101fbf00}, {0xa74, 0x00000007},
285 {0xc00, 0x48071d40}, {0xc04, 0x03a05633},
286 {0xc08, 0x000000e4}, {0xc0c, 0x6c6c6c6c},
287 {0xc10, 0x08800000}, {0xc14, 0x40000100},
288 {0xc18, 0x08800000}, {0xc1c, 0x40000100},
289 {0xc20, 0x00000000}, {0xc24, 0x00000000},
290 {0xc28, 0x00000000}, {0xc2c, 0x00000000},
291 {0xc30, 0x69e9ac44}, {0xc34, 0x469652cf},
292 {0xc38, 0x49795994}, {0xc3c, 0x0a97971c},
293 {0xc40, 0x1f7c403f}, {0xc44, 0x000100b7},
294 {0xc48, 0xec020107}, {0xc4c, 0x007f037f},
295 {0xc50, 0x69543420}, {0xc54, 0x43bc0094},
296 {0xc58, 0x69543420}, {0xc5c, 0x433c0094},
297 {0xc60, 0x00000000}, {0xc64, 0x5116848b},
298 {0xc68, 0x47c00bff}, {0xc6c, 0x00000036},
299 {0xc70, 0x2c7f000d}, {0xc74, 0x2186115b},
300 {0xc78, 0x0000001f}, {0xc7c, 0x00b99612},
301 {0xc80, 0x40000100}, {0xc84, 0x20f60000},
302 {0xc88, 0x40000100}, {0xc8c, 0xa0e40000},
303 {0xc90, 0x00121820}, {0xc94, 0x00000000},
304 {0xc98, 0x00121820}, {0xc9c, 0x00007f7f},
305 {0xca0, 0x00000000}, {0xca4, 0x00000080},
306 {0xca8, 0x00000000}, {0xcac, 0x00000000},
307 {0xcb0, 0x00000000}, {0xcb4, 0x00000000},
308 {0xcb8, 0x00000000}, {0xcbc, 0x28000000},
309 {0xcc0, 0x00000000}, {0xcc4, 0x00000000},
310 {0xcc8, 0x00000000}, {0xccc, 0x00000000},
311 {0xcd0, 0x00000000}, {0xcd4, 0x00000000},
312 {0xcd8, 0x64b22427}, {0xcdc, 0x00766932},
313 {0xce0, 0x00222222}, {0xce4, 0x00000000},
314 {0xce8, 0x37644302}, {0xcec, 0x2f97d40c},
315 {0xd00, 0x00080740}, {0xd04, 0x00020403},
316 {0xd08, 0x0000907f}, {0xd0c, 0x20010201},
317 {0xd10, 0xa0633333}, {0xd14, 0x3333bc43},
318 {0xd18, 0x7a8f5b6b}, {0xd2c, 0xcc979975},
319 {0xd30, 0x00000000}, {0xd34, 0x80608000},
320 {0xd38, 0x00000000}, {0xd3c, 0x00027293},
321 {0xd40, 0x00000000}, {0xd44, 0x00000000},
322 {0xd48, 0x00000000}, {0xd4c, 0x00000000},
323 {0xd50, 0x6437140a}, {0xd54, 0x00000000},
324 {0xd58, 0x00000000}, {0xd5c, 0x30032064},
325 {0xd60, 0x4653de68}, {0xd64, 0x04518a3c},
326 {0xd68, 0x00002101}, {0xd6c, 0x2a201c16},
327 {0xd70, 0x1812362e}, {0xd74, 0x322c2220},
328 {0xd78, 0x000e3c24}, {0xe00, 0x2a2a2a2a},
329 {0xe04, 0x2a2a2a2a}, {0xe08, 0x03902a2a},
330 {0xe10, 0x2a2a2a2a}, {0xe14, 0x2a2a2a2a},
331 {0xe18, 0x2a2a2a2a}, {0xe1c, 0x2a2a2a2a},
332 {0xe28, 0x00000000}, {0xe30, 0x1000dc1f},
333 {0xe34, 0x10008c1f}, {0xe38, 0x02140102},
334 {0xe3c, 0x681604c2}, {0xe40, 0x01007c00},
335 {0xe44, 0x01004800}, {0xe48, 0xfb000000},
336 {0xe4c, 0x000028d1}, {0xe50, 0x1000dc1f},
337 {0xe54, 0x10008c1f}, {0xe58, 0x02140102},
338 {0xe5c, 0x28160d05}, {0xe60, 0x00000010},
339 {0xe68, 0x001b25a4}, {0xe6c, 0x63db25a4},
340 {0xe70, 0x63db25a4}, {0xe74, 0x0c1b25a4},
341 {0xe78, 0x0c1b25a4}, {0xe7c, 0x0c1b25a4},
342 {0xe80, 0x0c1b25a4}, {0xe84, 0x63db25a4},
343 {0xe88, 0x0c1b25a4}, {0xe8c, 0x63db25a4},
344 {0xed0, 0x63db25a4}, {0xed4, 0x63db25a4},
345 {0xed8, 0x63db25a4}, {0xedc, 0x001b25a4},
346 {0xee0, 0x001b25a4}, {0xeec, 0x6fdb25a4},
347 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
348 {0xf00, 0x00000300},
349 {0xffff, 0xffffffff},
350};
351
352static struct rtl8xxxu_reg32val rtl8188ru_phy_1t_highpa_table[] = {
353 {0x024, 0x0011800f}, {0x028, 0x00ffdb83},
354 {0x040, 0x000c0004}, {0x800, 0x80040000},
355 {0x804, 0x00000001}, {0x808, 0x0000fc00},
356 {0x80c, 0x0000000a}, {0x810, 0x10005388},
357 {0x814, 0x020c3d10}, {0x818, 0x02200385},
358 {0x81c, 0x00000000}, {0x820, 0x01000100},
359 {0x824, 0x00390204}, {0x828, 0x00000000},
360 {0x82c, 0x00000000}, {0x830, 0x00000000},
361 {0x834, 0x00000000}, {0x838, 0x00000000},
362 {0x83c, 0x00000000}, {0x840, 0x00010000},
363 {0x844, 0x00000000}, {0x848, 0x00000000},
364 {0x84c, 0x00000000}, {0x850, 0x00000000},
365 {0x854, 0x00000000}, {0x858, 0x569a569a},
366 {0x85c, 0x001b25a4}, {0x860, 0x66e60230},
367 {0x864, 0x061f0130}, {0x868, 0x00000000},
368 {0x86c, 0x20202000}, {0x870, 0x03000300},
369 {0x874, 0x22004000}, {0x878, 0x00000808},
370 {0x87c, 0x00ffc3f1}, {0x880, 0xc0083070},
371 {0x884, 0x000004d5}, {0x888, 0x00000000},
372 {0x88c, 0xccc000c0}, {0x890, 0x00000800},
373 {0x894, 0xfffffffe}, {0x898, 0x40302010},
374 {0x89c, 0x00706050}, {0x900, 0x00000000},
375 {0x904, 0x00000023}, {0x908, 0x00000000},
376 {0x90c, 0x81121111}, {0xa00, 0x00d047c8},
377 {0xa04, 0x80ff000c}, {0xa08, 0x8c838300},
378 {0xa0c, 0x2e68120f}, {0xa10, 0x9500bb78},
379 {0xa14, 0x11144028}, {0xa18, 0x00881117},
380 {0xa1c, 0x89140f00}, {0xa20, 0x15160000},
381 {0xa24, 0x070b0f12}, {0xa28, 0x00000104},
382 {0xa2c, 0x00d30000}, {0xa70, 0x101fbf00},
383 {0xa74, 0x00000007}, {0xc00, 0x48071d40},
384 {0xc04, 0x03a05611}, {0xc08, 0x000000e4},
385 {0xc0c, 0x6c6c6c6c}, {0xc10, 0x08800000},
386 {0xc14, 0x40000100}, {0xc18, 0x08800000},
387 {0xc1c, 0x40000100}, {0xc20, 0x00000000},
388 {0xc24, 0x00000000}, {0xc28, 0x00000000},
389 {0xc2c, 0x00000000}, {0xc30, 0x69e9ac44},
390 {0xc34, 0x469652cf}, {0xc38, 0x49795994},
391 {0xc3c, 0x0a97971c}, {0xc40, 0x1f7c403f},
392 {0xc44, 0x000100b7}, {0xc48, 0xec020107},
393 {0xc4c, 0x007f037f}, {0xc50, 0x6954342e},
394 {0xc54, 0x43bc0094}, {0xc58, 0x6954342f},
395 {0xc5c, 0x433c0094}, {0xc60, 0x00000000},
396 {0xc64, 0x5116848b}, {0xc68, 0x47c00bff},
397 {0xc6c, 0x00000036}, {0xc70, 0x2c46000d},
398 {0xc74, 0x018610db}, {0xc78, 0x0000001f},
399 {0xc7c, 0x00b91612}, {0xc80, 0x24000090},
400 {0xc84, 0x20f60000}, {0xc88, 0x24000090},
401 {0xc8c, 0x20200000}, {0xc90, 0x00121820},
402 {0xc94, 0x00000000}, {0xc98, 0x00121820},
403 {0xc9c, 0x00007f7f}, {0xca0, 0x00000000},
404 {0xca4, 0x00000080}, {0xca8, 0x00000000},
405 {0xcac, 0x00000000}, {0xcb0, 0x00000000},
406 {0xcb4, 0x00000000}, {0xcb8, 0x00000000},
407 {0xcbc, 0x28000000}, {0xcc0, 0x00000000},
408 {0xcc4, 0x00000000}, {0xcc8, 0x00000000},
409 {0xccc, 0x00000000}, {0xcd0, 0x00000000},
410 {0xcd4, 0x00000000}, {0xcd8, 0x64b22427},
411 {0xcdc, 0x00766932}, {0xce0, 0x00222222},
412 {0xce4, 0x00000000}, {0xce8, 0x37644302},
413 {0xcec, 0x2f97d40c}, {0xd00, 0x00080740},
414 {0xd04, 0x00020401}, {0xd08, 0x0000907f},
415 {0xd0c, 0x20010201}, {0xd10, 0xa0633333},
416 {0xd14, 0x3333bc43}, {0xd18, 0x7a8f5b6b},
417 {0xd2c, 0xcc979975}, {0xd30, 0x00000000},
418 {0xd34, 0x80608000}, {0xd38, 0x00000000},
419 {0xd3c, 0x00027293}, {0xd40, 0x00000000},
420 {0xd44, 0x00000000}, {0xd48, 0x00000000},
421 {0xd4c, 0x00000000}, {0xd50, 0x6437140a},
422 {0xd54, 0x00000000}, {0xd58, 0x00000000},
423 {0xd5c, 0x30032064}, {0xd60, 0x4653de68},
424 {0xd64, 0x04518a3c}, {0xd68, 0x00002101},
425 {0xd6c, 0x2a201c16}, {0xd70, 0x1812362e},
426 {0xd74, 0x322c2220}, {0xd78, 0x000e3c24},
427 {0xe00, 0x24242424}, {0xe04, 0x24242424},
428 {0xe08, 0x03902024}, {0xe10, 0x24242424},
429 {0xe14, 0x24242424}, {0xe18, 0x24242424},
430 {0xe1c, 0x24242424}, {0xe28, 0x00000000},
431 {0xe30, 0x1000dc1f}, {0xe34, 0x10008c1f},
432 {0xe38, 0x02140102}, {0xe3c, 0x681604c2},
433 {0xe40, 0x01007c00}, {0xe44, 0x01004800},
434 {0xe48, 0xfb000000}, {0xe4c, 0x000028d1},
435 {0xe50, 0x1000dc1f}, {0xe54, 0x10008c1f},
436 {0xe58, 0x02140102}, {0xe5c, 0x28160d05},
437 {0xe60, 0x00000008}, {0xe68, 0x001b25a4},
438 {0xe6c, 0x631b25a0}, {0xe70, 0x631b25a0},
439 {0xe74, 0x081b25a0}, {0xe78, 0x081b25a0},
440 {0xe7c, 0x081b25a0}, {0xe80, 0x081b25a0},
441 {0xe84, 0x631b25a0}, {0xe88, 0x081b25a0},
442 {0xe8c, 0x631b25a0}, {0xed0, 0x631b25a0},
443 {0xed4, 0x631b25a0}, {0xed8, 0x631b25a0},
444 {0xedc, 0x001b25a0}, {0xee0, 0x001b25a0},
445 {0xeec, 0x6b1b25a0}, {0xee8, 0x31555448},
446 {0xf14, 0x00000003}, {0xf4c, 0x00000000},
447 {0xf00, 0x00000300},
448 {0xffff, 0xffffffff},
449};
450
451static struct rtl8xxxu_reg32val rtl8xxx_agc_standard_table[] = {
452 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
453 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
454 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
455 {0xc78, 0x7a060001}, {0xc78, 0x79070001},
456 {0xc78, 0x78080001}, {0xc78, 0x77090001},
457 {0xc78, 0x760a0001}, {0xc78, 0x750b0001},
458 {0xc78, 0x740c0001}, {0xc78, 0x730d0001},
459 {0xc78, 0x720e0001}, {0xc78, 0x710f0001},
460 {0xc78, 0x70100001}, {0xc78, 0x6f110001},
461 {0xc78, 0x6e120001}, {0xc78, 0x6d130001},
462 {0xc78, 0x6c140001}, {0xc78, 0x6b150001},
463 {0xc78, 0x6a160001}, {0xc78, 0x69170001},
464 {0xc78, 0x68180001}, {0xc78, 0x67190001},
465 {0xc78, 0x661a0001}, {0xc78, 0x651b0001},
466 {0xc78, 0x641c0001}, {0xc78, 0x631d0001},
467 {0xc78, 0x621e0001}, {0xc78, 0x611f0001},
468 {0xc78, 0x60200001}, {0xc78, 0x49210001},
469 {0xc78, 0x48220001}, {0xc78, 0x47230001},
470 {0xc78, 0x46240001}, {0xc78, 0x45250001},
471 {0xc78, 0x44260001}, {0xc78, 0x43270001},
472 {0xc78, 0x42280001}, {0xc78, 0x41290001},
473 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
474 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
475 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
476 {0xc78, 0x21300001}, {0xc78, 0x20310001},
477 {0xc78, 0x06320001}, {0xc78, 0x05330001},
478 {0xc78, 0x04340001}, {0xc78, 0x03350001},
479 {0xc78, 0x02360001}, {0xc78, 0x01370001},
480 {0xc78, 0x00380001}, {0xc78, 0x00390001},
481 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
482 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
483 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
484 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
485 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
486 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
487 {0xc78, 0x7a460001}, {0xc78, 0x79470001},
488 {0xc78, 0x78480001}, {0xc78, 0x77490001},
489 {0xc78, 0x764a0001}, {0xc78, 0x754b0001},
490 {0xc78, 0x744c0001}, {0xc78, 0x734d0001},
491 {0xc78, 0x724e0001}, {0xc78, 0x714f0001},
492 {0xc78, 0x70500001}, {0xc78, 0x6f510001},
493 {0xc78, 0x6e520001}, {0xc78, 0x6d530001},
494 {0xc78, 0x6c540001}, {0xc78, 0x6b550001},
495 {0xc78, 0x6a560001}, {0xc78, 0x69570001},
496 {0xc78, 0x68580001}, {0xc78, 0x67590001},
497 {0xc78, 0x665a0001}, {0xc78, 0x655b0001},
498 {0xc78, 0x645c0001}, {0xc78, 0x635d0001},
499 {0xc78, 0x625e0001}, {0xc78, 0x615f0001},
500 {0xc78, 0x60600001}, {0xc78, 0x49610001},
501 {0xc78, 0x48620001}, {0xc78, 0x47630001},
502 {0xc78, 0x46640001}, {0xc78, 0x45650001},
503 {0xc78, 0x44660001}, {0xc78, 0x43670001},
504 {0xc78, 0x42680001}, {0xc78, 0x41690001},
505 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
506 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
507 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
508 {0xc78, 0x21700001}, {0xc78, 0x20710001},
509 {0xc78, 0x06720001}, {0xc78, 0x05730001},
510 {0xc78, 0x04740001}, {0xc78, 0x03750001},
511 {0xc78, 0x02760001}, {0xc78, 0x01770001},
512 {0xc78, 0x00780001}, {0xc78, 0x00790001},
513 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
514 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
515 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
516 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
517 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
518 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
519 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
520 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
521 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
522 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
523 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
524 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
525 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
526 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
527 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
528 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
529 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
530 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
531 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
532 {0xffff, 0xffffffff}
533};
534
535static struct rtl8xxxu_reg32val rtl8xxx_agc_highpa_table[] = {
536 {0xc78, 0x7b000001}, {0xc78, 0x7b010001},
537 {0xc78, 0x7b020001}, {0xc78, 0x7b030001},
538 {0xc78, 0x7b040001}, {0xc78, 0x7b050001},
539 {0xc78, 0x7b060001}, {0xc78, 0x7b070001},
540 {0xc78, 0x7b080001}, {0xc78, 0x7a090001},
541 {0xc78, 0x790a0001}, {0xc78, 0x780b0001},
542 {0xc78, 0x770c0001}, {0xc78, 0x760d0001},
543 {0xc78, 0x750e0001}, {0xc78, 0x740f0001},
544 {0xc78, 0x73100001}, {0xc78, 0x72110001},
545 {0xc78, 0x71120001}, {0xc78, 0x70130001},
546 {0xc78, 0x6f140001}, {0xc78, 0x6e150001},
547 {0xc78, 0x6d160001}, {0xc78, 0x6c170001},
548 {0xc78, 0x6b180001}, {0xc78, 0x6a190001},
549 {0xc78, 0x691a0001}, {0xc78, 0x681b0001},
550 {0xc78, 0x671c0001}, {0xc78, 0x661d0001},
551 {0xc78, 0x651e0001}, {0xc78, 0x641f0001},
552 {0xc78, 0x63200001}, {0xc78, 0x62210001},
553 {0xc78, 0x61220001}, {0xc78, 0x60230001},
554 {0xc78, 0x46240001}, {0xc78, 0x45250001},
555 {0xc78, 0x44260001}, {0xc78, 0x43270001},
556 {0xc78, 0x42280001}, {0xc78, 0x41290001},
557 {0xc78, 0x402a0001}, {0xc78, 0x262b0001},
558 {0xc78, 0x252c0001}, {0xc78, 0x242d0001},
559 {0xc78, 0x232e0001}, {0xc78, 0x222f0001},
560 {0xc78, 0x21300001}, {0xc78, 0x20310001},
561 {0xc78, 0x06320001}, {0xc78, 0x05330001},
562 {0xc78, 0x04340001}, {0xc78, 0x03350001},
563 {0xc78, 0x02360001}, {0xc78, 0x01370001},
564 {0xc78, 0x00380001}, {0xc78, 0x00390001},
565 {0xc78, 0x003a0001}, {0xc78, 0x003b0001},
566 {0xc78, 0x003c0001}, {0xc78, 0x003d0001},
567 {0xc78, 0x003e0001}, {0xc78, 0x003f0001},
568 {0xc78, 0x7b400001}, {0xc78, 0x7b410001},
569 {0xc78, 0x7b420001}, {0xc78, 0x7b430001},
570 {0xc78, 0x7b440001}, {0xc78, 0x7b450001},
571 {0xc78, 0x7b460001}, {0xc78, 0x7b470001},
572 {0xc78, 0x7b480001}, {0xc78, 0x7a490001},
573 {0xc78, 0x794a0001}, {0xc78, 0x784b0001},
574 {0xc78, 0x774c0001}, {0xc78, 0x764d0001},
575 {0xc78, 0x754e0001}, {0xc78, 0x744f0001},
576 {0xc78, 0x73500001}, {0xc78, 0x72510001},
577 {0xc78, 0x71520001}, {0xc78, 0x70530001},
578 {0xc78, 0x6f540001}, {0xc78, 0x6e550001},
579 {0xc78, 0x6d560001}, {0xc78, 0x6c570001},
580 {0xc78, 0x6b580001}, {0xc78, 0x6a590001},
581 {0xc78, 0x695a0001}, {0xc78, 0x685b0001},
582 {0xc78, 0x675c0001}, {0xc78, 0x665d0001},
583 {0xc78, 0x655e0001}, {0xc78, 0x645f0001},
584 {0xc78, 0x63600001}, {0xc78, 0x62610001},
585 {0xc78, 0x61620001}, {0xc78, 0x60630001},
586 {0xc78, 0x46640001}, {0xc78, 0x45650001},
587 {0xc78, 0x44660001}, {0xc78, 0x43670001},
588 {0xc78, 0x42680001}, {0xc78, 0x41690001},
589 {0xc78, 0x406a0001}, {0xc78, 0x266b0001},
590 {0xc78, 0x256c0001}, {0xc78, 0x246d0001},
591 {0xc78, 0x236e0001}, {0xc78, 0x226f0001},
592 {0xc78, 0x21700001}, {0xc78, 0x20710001},
593 {0xc78, 0x06720001}, {0xc78, 0x05730001},
594 {0xc78, 0x04740001}, {0xc78, 0x03750001},
595 {0xc78, 0x02760001}, {0xc78, 0x01770001},
596 {0xc78, 0x00780001}, {0xc78, 0x00790001},
597 {0xc78, 0x007a0001}, {0xc78, 0x007b0001},
598 {0xc78, 0x007c0001}, {0xc78, 0x007d0001},
599 {0xc78, 0x007e0001}, {0xc78, 0x007f0001},
600 {0xc78, 0x3800001e}, {0xc78, 0x3801001e},
601 {0xc78, 0x3802001e}, {0xc78, 0x3803001e},
602 {0xc78, 0x3804001e}, {0xc78, 0x3805001e},
603 {0xc78, 0x3806001e}, {0xc78, 0x3807001e},
604 {0xc78, 0x3808001e}, {0xc78, 0x3c09001e},
605 {0xc78, 0x3e0a001e}, {0xc78, 0x400b001e},
606 {0xc78, 0x440c001e}, {0xc78, 0x480d001e},
607 {0xc78, 0x4c0e001e}, {0xc78, 0x500f001e},
608 {0xc78, 0x5210001e}, {0xc78, 0x5611001e},
609 {0xc78, 0x5a12001e}, {0xc78, 0x5e13001e},
610 {0xc78, 0x6014001e}, {0xc78, 0x6015001e},
611 {0xc78, 0x6016001e}, {0xc78, 0x6217001e},
612 {0xc78, 0x6218001e}, {0xc78, 0x6219001e},
613 {0xc78, 0x621a001e}, {0xc78, 0x621b001e},
614 {0xc78, 0x621c001e}, {0xc78, 0x621d001e},
615 {0xc78, 0x621e001e}, {0xc78, 0x621f001e},
616 {0xffff, 0xffffffff}
617};
618
619static struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = {
620 {0x00, 0x00030159}, {0x01, 0x00031284},
621 {0x02, 0x00098000}, {0x03, 0x00039c63},
622 {0x04, 0x000210e7}, {0x09, 0x0002044f},
623 {0x0a, 0x0001a3f1}, {0x0b, 0x00014787},
624 {0x0c, 0x000896fe}, {0x0d, 0x0000e02c},
625 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
626 {0x19, 0x00000000}, {0x1a, 0x00030355},
627 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
628 {0x1d, 0x000a1250}, {0x1e, 0x0000024f},
629 {0x1f, 0x00000000}, {0x20, 0x0000b614},
630 {0x21, 0x0006c000}, {0x22, 0x00000000},
631 {0x23, 0x00001558}, {0x24, 0x00000060},
632 {0x25, 0x00000483}, {0x26, 0x0004f000},
633 {0x27, 0x000ec7d9}, {0x28, 0x00057730},
634 {0x29, 0x00004783}, {0x2a, 0x00000001},
635 {0x2b, 0x00021334}, {0x2a, 0x00000000},
636 {0x2b, 0x00000054}, {0x2a, 0x00000001},
637 {0x2b, 0x00000808}, {0x2b, 0x00053333},
638 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
639 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
640 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
641 {0x2b, 0x00000808}, {0x2b, 0x00063333},
642 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
643 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
644 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
645 {0x2b, 0x00000808}, {0x2b, 0x00073333},
646 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
647 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
648 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
649 {0x2b, 0x00000709}, {0x2b, 0x00063333},
650 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
651 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
652 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
653 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
654 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
655 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
656 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
657 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
658 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
659 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
660 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
661 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
662 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
663 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
664 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
665 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
666 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
667 {0x10, 0x0002000f}, {0x11, 0x000203f9},
668 {0x10, 0x0003000f}, {0x11, 0x000ff500},
669 {0x10, 0x00000000}, {0x11, 0x00000000},
670 {0x10, 0x0008000f}, {0x11, 0x0003f100},
671 {0x10, 0x0009000f}, {0x11, 0x00023100},
672 {0x12, 0x00032000}, {0x12, 0x00071000},
673 {0x12, 0x000b0000}, {0x12, 0x000fc000},
674 {0x13, 0x000287b3}, {0x13, 0x000244b7},
675 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
676 {0x13, 0x00018493}, {0x13, 0x0001429b},
677 {0x13, 0x00010299}, {0x13, 0x0000c29c},
678 {0x13, 0x000081a0}, {0x13, 0x000040ac},
679 {0x13, 0x00000020}, {0x14, 0x0001944c},
680 {0x14, 0x00059444}, {0x14, 0x0009944c},
681 {0x14, 0x000d9444}, {0x15, 0x0000f474},
682 {0x15, 0x0004f477}, {0x15, 0x0008f455},
683 {0x15, 0x000cf455}, {0x16, 0x00000339},
684 {0x16, 0x00040339}, {0x16, 0x00080339},
685 {0x16, 0x000c0366}, {0x00, 0x00010159},
686 {0x18, 0x0000f401}, {0xfe, 0x00000000},
687 {0xfe, 0x00000000}, {0x1f, 0x00000003},
688 {0xfe, 0x00000000}, {0xfe, 0x00000000},
689 {0x1e, 0x00000247}, {0x1f, 0x00000000},
690 {0x00, 0x00030159},
691 {0xff, 0xffffffff}
692};
693
694static struct rtl8xxxu_rfregval rtl8192cu_radioa_2t_init_table[] = {
695 {0x00, 0x00030159}, {0x01, 0x00031284},
696 {0x02, 0x00098000}, {0x03, 0x00018c63},
697 {0x04, 0x000210e7}, {0x09, 0x0002044f},
698 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
699 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
700 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
701 {0x19, 0x00000000}, {0x1a, 0x00010255},
702 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
703 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
704 {0x1f, 0x00080001}, {0x20, 0x0000b614},
705 {0x21, 0x0006c000}, {0x22, 0x00000000},
706 {0x23, 0x00001558}, {0x24, 0x00000060},
707 {0x25, 0x00000483}, {0x26, 0x0004f000},
708 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
709 {0x29, 0x00004783}, {0x2a, 0x00000001},
710 {0x2b, 0x00021334}, {0x2a, 0x00000000},
711 {0x2b, 0x00000054}, {0x2a, 0x00000001},
712 {0x2b, 0x00000808}, {0x2b, 0x00053333},
713 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
714 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
715 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
716 {0x2b, 0x00000808}, {0x2b, 0x00063333},
717 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
718 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
719 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
720 {0x2b, 0x00000808}, {0x2b, 0x00073333},
721 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
722 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
723 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
724 {0x2b, 0x00000709}, {0x2b, 0x00063333},
725 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
726 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
727 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
728 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
729 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
730 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
731 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
732 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
733 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
734 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
735 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
736 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
737 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
738 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
739 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
740 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
741 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
742 {0x10, 0x0002000f}, {0x11, 0x000203f9},
743 {0x10, 0x0003000f}, {0x11, 0x000ff500},
744 {0x10, 0x00000000}, {0x11, 0x00000000},
745 {0x10, 0x0008000f}, {0x11, 0x0003f100},
746 {0x10, 0x0009000f}, {0x11, 0x00023100},
747 {0x12, 0x00032000}, {0x12, 0x00071000},
748 {0x12, 0x000b0000}, {0x12, 0x000fc000},
749 {0x13, 0x000287b3}, {0x13, 0x000244b7},
750 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
751 {0x13, 0x00018493}, {0x13, 0x0001429b},
752 {0x13, 0x00010299}, {0x13, 0x0000c29c},
753 {0x13, 0x000081a0}, {0x13, 0x000040ac},
754 {0x13, 0x00000020}, {0x14, 0x0001944c},
755 {0x14, 0x00059444}, {0x14, 0x0009944c},
756 {0x14, 0x000d9444}, {0x15, 0x0000f424},
757 {0x15, 0x0004f424}, {0x15, 0x0008f424},
758 {0x15, 0x000cf424}, {0x16, 0x000e0330},
759 {0x16, 0x000a0330}, {0x16, 0x00060330},
760 {0x16, 0x00020330}, {0x00, 0x00010159},
761 {0x18, 0x0000f401}, {0xfe, 0x00000000},
762 {0xfe, 0x00000000}, {0x1f, 0x00080003},
763 {0xfe, 0x00000000}, {0xfe, 0x00000000},
764 {0x1e, 0x00044457}, {0x1f, 0x00080000},
765 {0x00, 0x00030159},
766 {0xff, 0xffffffff}
767};
768
769static struct rtl8xxxu_rfregval rtl8192cu_radiob_2t_init_table[] = {
770 {0x00, 0x00030159}, {0x01, 0x00031284},
771 {0x02, 0x00098000}, {0x03, 0x00018c63},
772 {0x04, 0x000210e7}, {0x09, 0x0002044f},
773 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
774 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
775 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
776 {0x12, 0x00032000}, {0x12, 0x00071000},
777 {0x12, 0x000b0000}, {0x12, 0x000fc000},
778 {0x13, 0x000287af}, {0x13, 0x000244b7},
779 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
780 {0x13, 0x00018493}, {0x13, 0x00014297},
781 {0x13, 0x00010295}, {0x13, 0x0000c298},
782 {0x13, 0x0000819c}, {0x13, 0x000040a8},
783 {0x13, 0x0000001c}, {0x14, 0x0001944c},
784 {0x14, 0x00059444}, {0x14, 0x0009944c},
785 {0x14, 0x000d9444}, {0x15, 0x0000f424},
786 {0x15, 0x0004f424}, {0x15, 0x0008f424},
787 {0x15, 0x000cf424}, {0x16, 0x000e0330},
788 {0x16, 0x000a0330}, {0x16, 0x00060330},
789 {0x16, 0x00020330},
790 {0xff, 0xffffffff}
791};
792
793static struct rtl8xxxu_rfregval rtl8192cu_radioa_1t_init_table[] = {
794 {0x00, 0x00030159}, {0x01, 0x00031284},
795 {0x02, 0x00098000}, {0x03, 0x00018c63},
796 {0x04, 0x000210e7}, {0x09, 0x0002044f},
797 {0x0a, 0x0001adb1}, {0x0b, 0x00054867},
798 {0x0c, 0x0008992e}, {0x0d, 0x0000e52c},
799 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
800 {0x19, 0x00000000}, {0x1a, 0x00010255},
801 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
802 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
803 {0x1f, 0x00080001}, {0x20, 0x0000b614},
804 {0x21, 0x0006c000}, {0x22, 0x00000000},
805 {0x23, 0x00001558}, {0x24, 0x00000060},
806 {0x25, 0x00000483}, {0x26, 0x0004f000},
807 {0x27, 0x000ec7d9}, {0x28, 0x000577c0},
808 {0x29, 0x00004783}, {0x2a, 0x00000001},
809 {0x2b, 0x00021334}, {0x2a, 0x00000000},
810 {0x2b, 0x00000054}, {0x2a, 0x00000001},
811 {0x2b, 0x00000808}, {0x2b, 0x00053333},
812 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
813 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
814 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
815 {0x2b, 0x00000808}, {0x2b, 0x00063333},
816 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
817 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
818 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
819 {0x2b, 0x00000808}, {0x2b, 0x00073333},
820 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
821 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
822 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
823 {0x2b, 0x00000709}, {0x2b, 0x00063333},
824 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
825 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
826 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
827 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
828 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
829 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
830 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
831 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
832 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
833 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
834 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
835 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
836 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
837 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
838 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
839 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
840 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
841 {0x10, 0x0002000f}, {0x11, 0x000203f9},
842 {0x10, 0x0003000f}, {0x11, 0x000ff500},
843 {0x10, 0x00000000}, {0x11, 0x00000000},
844 {0x10, 0x0008000f}, {0x11, 0x0003f100},
845 {0x10, 0x0009000f}, {0x11, 0x00023100},
846 {0x12, 0x00032000}, {0x12, 0x00071000},
847 {0x12, 0x000b0000}, {0x12, 0x000fc000},
848 {0x13, 0x000287b3}, {0x13, 0x000244b7},
849 {0x13, 0x000204ab}, {0x13, 0x0001c49f},
850 {0x13, 0x00018493}, {0x13, 0x0001429b},
851 {0x13, 0x00010299}, {0x13, 0x0000c29c},
852 {0x13, 0x000081a0}, {0x13, 0x000040ac},
853 {0x13, 0x00000020}, {0x14, 0x0001944c},
854 {0x14, 0x00059444}, {0x14, 0x0009944c},
855 {0x14, 0x000d9444}, {0x15, 0x0000f405},
856 {0x15, 0x0004f405}, {0x15, 0x0008f405},
857 {0x15, 0x000cf405}, {0x16, 0x000e0330},
858 {0x16, 0x000a0330}, {0x16, 0x00060330},
859 {0x16, 0x00020330}, {0x00, 0x00010159},
860 {0x18, 0x0000f401}, {0xfe, 0x00000000},
861 {0xfe, 0x00000000}, {0x1f, 0x00080003},
862 {0xfe, 0x00000000}, {0xfe, 0x00000000},
863 {0x1e, 0x00044457}, {0x1f, 0x00080000},
864 {0x00, 0x00030159},
865 {0xff, 0xffffffff}
866};
867
868static struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
869 {0x00, 0x00030159}, {0x01, 0x00031284},
870 {0x02, 0x00098000}, {0x03, 0x00018c63},
871 {0x04, 0x000210e7}, {0x09, 0x0002044f},
872 {0x0a, 0x0001adb0}, {0x0b, 0x00054867},
873 {0x0c, 0x0008992e}, {0x0d, 0x0000e529},
874 {0x0e, 0x00039ce7}, {0x0f, 0x00000451},
875 {0x19, 0x00000000}, {0x1a, 0x00000255},
876 {0x1b, 0x00060a00}, {0x1c, 0x000fc378},
877 {0x1d, 0x000a1250}, {0x1e, 0x0004445f},
878 {0x1f, 0x00080001}, {0x20, 0x0000b614},
879 {0x21, 0x0006c000}, {0x22, 0x0000083c},
880 {0x23, 0x00001558}, {0x24, 0x00000060},
881 {0x25, 0x00000483}, {0x26, 0x0004f000},
882 {0x27, 0x000ec7d9}, {0x28, 0x000977c0},
883 {0x29, 0x00004783}, {0x2a, 0x00000001},
884 {0x2b, 0x00021334}, {0x2a, 0x00000000},
885 {0x2b, 0x00000054}, {0x2a, 0x00000001},
886 {0x2b, 0x00000808}, {0x2b, 0x00053333},
887 {0x2c, 0x0000000c}, {0x2a, 0x00000002},
888 {0x2b, 0x00000808}, {0x2b, 0x0005b333},
889 {0x2c, 0x0000000d}, {0x2a, 0x00000003},
890 {0x2b, 0x00000808}, {0x2b, 0x00063333},
891 {0x2c, 0x0000000d}, {0x2a, 0x00000004},
892 {0x2b, 0x00000808}, {0x2b, 0x0006b333},
893 {0x2c, 0x0000000d}, {0x2a, 0x00000005},
894 {0x2b, 0x00000808}, {0x2b, 0x00073333},
895 {0x2c, 0x0000000d}, {0x2a, 0x00000006},
896 {0x2b, 0x00000709}, {0x2b, 0x0005b333},
897 {0x2c, 0x0000000d}, {0x2a, 0x00000007},
898 {0x2b, 0x00000709}, {0x2b, 0x00063333},
899 {0x2c, 0x0000000d}, {0x2a, 0x00000008},
900 {0x2b, 0x0000060a}, {0x2b, 0x0004b333},
901 {0x2c, 0x0000000d}, {0x2a, 0x00000009},
902 {0x2b, 0x0000060a}, {0x2b, 0x00053333},
903 {0x2c, 0x0000000d}, {0x2a, 0x0000000a},
904 {0x2b, 0x0000060a}, {0x2b, 0x0005b333},
905 {0x2c, 0x0000000d}, {0x2a, 0x0000000b},
906 {0x2b, 0x0000060a}, {0x2b, 0x00063333},
907 {0x2c, 0x0000000d}, {0x2a, 0x0000000c},
908 {0x2b, 0x0000060a}, {0x2b, 0x0006b333},
909 {0x2c, 0x0000000d}, {0x2a, 0x0000000d},
910 {0x2b, 0x0000060a}, {0x2b, 0x00073333},
911 {0x2c, 0x0000000d}, {0x2a, 0x0000000e},
912 {0x2b, 0x0000050b}, {0x2b, 0x00066666},
913 {0x2c, 0x0000001a}, {0x2a, 0x000e0000},
914 {0x10, 0x0004000f}, {0x11, 0x000e31fc},
915 {0x10, 0x0006000f}, {0x11, 0x000ff9f8},
916 {0x10, 0x0002000f}, {0x11, 0x000203f9},
917 {0x10, 0x0003000f}, {0x11, 0x000ff500},
918 {0x10, 0x00000000}, {0x11, 0x00000000},
919 {0x10, 0x0008000f}, {0x11, 0x0003f100},
920 {0x10, 0x0009000f}, {0x11, 0x00023100},
921 {0x12, 0x000d8000}, {0x12, 0x00090000},
922 {0x12, 0x00051000}, {0x12, 0x00012000},
923 {0x13, 0x00028fb4}, {0x13, 0x00024fa8},
924 {0x13, 0x000207a4}, {0x13, 0x0001c3b0},
925 {0x13, 0x000183a4}, {0x13, 0x00014398},
926 {0x13, 0x000101a4}, {0x13, 0x0000c198},
927 {0x13, 0x000080a4}, {0x13, 0x00004098},
928 {0x13, 0x00000000}, {0x14, 0x0001944c},
929 {0x14, 0x00059444}, {0x14, 0x0009944c},
930 {0x14, 0x000d9444}, {0x15, 0x0000f405},
931 {0x15, 0x0004f405}, {0x15, 0x0008f405},
932 {0x15, 0x000cf405}, {0x16, 0x000e0330},
933 {0x16, 0x000a0330}, {0x16, 0x00060330},
934 {0x16, 0x00020330}, {0x00, 0x00010159},
935 {0x18, 0x0000f401}, {0xfe, 0x00000000},
936 {0xfe, 0x00000000}, {0x1f, 0x00080003},
937 {0xfe, 0x00000000}, {0xfe, 0x00000000},
938 {0x1e, 0x00044457}, {0x1f, 0x00080000},
939 {0x00, 0x00030159},
940 {0xff, 0xffffffff}
941};
942
943static struct rtl8xxxu_rfregs rtl8xxxu_rfregs[] = {
944 { /* RF_A */
945 .hssiparm1 = REG_FPGA0_XA_HSSI_PARM1,
946 .hssiparm2 = REG_FPGA0_XA_HSSI_PARM2,
947 .lssiparm = REG_FPGA0_XA_LSSI_PARM,
948 .hspiread = REG_HSPI_XA_READBACK,
949 .lssiread = REG_FPGA0_XA_LSSI_READBACK,
950 .rf_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL,
951 },
952 { /* RF_B */
953 .hssiparm1 = REG_FPGA0_XB_HSSI_PARM1,
954 .hssiparm2 = REG_FPGA0_XB_HSSI_PARM2,
955 .lssiparm = REG_FPGA0_XB_LSSI_PARM,
956 .hspiread = REG_HSPI_XB_READBACK,
957 .lssiread = REG_FPGA0_XB_LSSI_READBACK,
958 .rf_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL,
959 },
960};
961
962static const u32 rtl8723au_iqk_phy_iq_bb_reg[RTL8XXXU_BB_REGS] = {
963 REG_OFDM0_XA_RX_IQ_IMBALANCE,
964 REG_OFDM0_XB_RX_IQ_IMBALANCE,
965 REG_OFDM0_ENERGY_CCA_THRES,
966 REG_OFDM0_AGCR_SSI_TABLE,
967 REG_OFDM0_XA_TX_IQ_IMBALANCE,
968 REG_OFDM0_XB_TX_IQ_IMBALANCE,
969 REG_OFDM0_XC_TX_AFE,
970 REG_OFDM0_XD_TX_AFE,
971 REG_OFDM0_RX_IQ_EXT_ANTA
972};
973
974static u8 rtl8xxxu_read8(struct rtl8xxxu_priv *priv, u16 addr)
975{
976 struct usb_device *udev = priv->udev;
977 int len;
978 u8 data;
979
980 mutex_lock(&priv->usb_buf_mutex);
981 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
982 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
983 addr, 0, &priv->usb_buf.val8, sizeof(u8),
984 RTW_USB_CONTROL_MSG_TIMEOUT);
985 data = priv->usb_buf.val8;
986 mutex_unlock(&priv->usb_buf_mutex);
987
988 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
989 dev_info(&udev->dev, "%s(%04x) = 0x%02x, len %i\n",
990 __func__, addr, data, len);
991 return data;
992}
993
994static u16 rtl8xxxu_read16(struct rtl8xxxu_priv *priv, u16 addr)
995{
996 struct usb_device *udev = priv->udev;
997 int len;
998 u16 data;
999
1000 mutex_lock(&priv->usb_buf_mutex);
1001 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1002 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1003 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1004 RTW_USB_CONTROL_MSG_TIMEOUT);
1005 data = le16_to_cpu(priv->usb_buf.val16);
1006 mutex_unlock(&priv->usb_buf_mutex);
1007
1008 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1009 dev_info(&udev->dev, "%s(%04x) = 0x%04x, len %i\n",
1010 __func__, addr, data, len);
1011 return data;
1012}
1013
1014static u32 rtl8xxxu_read32(struct rtl8xxxu_priv *priv, u16 addr)
1015{
1016 struct usb_device *udev = priv->udev;
1017 int len;
1018 u32 data;
1019
1020 mutex_lock(&priv->usb_buf_mutex);
1021 len = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1022 REALTEK_USB_CMD_REQ, REALTEK_USB_READ,
1023 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1024 RTW_USB_CONTROL_MSG_TIMEOUT);
1025 data = le32_to_cpu(priv->usb_buf.val32);
1026 mutex_unlock(&priv->usb_buf_mutex);
1027
1028 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_READ)
1029 dev_info(&udev->dev, "%s(%04x) = 0x%08x, len %i\n",
1030 __func__, addr, data, len);
1031 return data;
1032}
1033
1034static int rtl8xxxu_write8(struct rtl8xxxu_priv *priv, u16 addr, u8 val)
1035{
1036 struct usb_device *udev = priv->udev;
1037 int ret;
1038
1039 mutex_lock(&priv->usb_buf_mutex);
1040 priv->usb_buf.val8 = val;
1041 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1042 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1043 addr, 0, &priv->usb_buf.val8, sizeof(u8),
1044 RTW_USB_CONTROL_MSG_TIMEOUT);
1045
1046 mutex_unlock(&priv->usb_buf_mutex);
1047
1048 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1049 dev_info(&udev->dev, "%s(%04x) = 0x%02x\n",
1050 __func__, addr, val);
1051 return ret;
1052}
1053
1054static int rtl8xxxu_write16(struct rtl8xxxu_priv *priv, u16 addr, u16 val)
1055{
1056 struct usb_device *udev = priv->udev;
1057 int ret;
1058
1059 mutex_lock(&priv->usb_buf_mutex);
1060 priv->usb_buf.val16 = cpu_to_le16(val);
1061 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1062 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1063 addr, 0, &priv->usb_buf.val16, sizeof(u16),
1064 RTW_USB_CONTROL_MSG_TIMEOUT);
1065 mutex_unlock(&priv->usb_buf_mutex);
1066
1067 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1068 dev_info(&udev->dev, "%s(%04x) = 0x%04x\n",
1069 __func__, addr, val);
1070 return ret;
1071}
1072
1073static int rtl8xxxu_write32(struct rtl8xxxu_priv *priv, u16 addr, u32 val)
1074{
1075 struct usb_device *udev = priv->udev;
1076 int ret;
1077
1078 mutex_lock(&priv->usb_buf_mutex);
1079 priv->usb_buf.val32 = cpu_to_le32(val);
1080 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1081 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1082 addr, 0, &priv->usb_buf.val32, sizeof(u32),
1083 RTW_USB_CONTROL_MSG_TIMEOUT);
1084 mutex_unlock(&priv->usb_buf_mutex);
1085
1086 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_REG_WRITE)
1087 dev_info(&udev->dev, "%s(%04x) = 0x%08x\n",
1088 __func__, addr, val);
1089 return ret;
1090}
1091
1092static int
1093rtl8xxxu_writeN(struct rtl8xxxu_priv *priv, u16 addr, u8 *buf, u16 len)
1094{
1095 struct usb_device *udev = priv->udev;
1096 int blocksize = priv->fops->writeN_block_size;
1097 int ret, i, count, remainder;
1098
1099 count = len / blocksize;
1100 remainder = len % blocksize;
1101
1102 for (i = 0; i < count; i++) {
1103 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1104 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1105 addr, 0, buf, blocksize,
1106 RTW_USB_CONTROL_MSG_TIMEOUT);
1107 if (ret != blocksize)
1108 goto write_error;
1109
1110 addr += blocksize;
1111 buf += blocksize;
1112 }
1113
1114 if (remainder) {
1115 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1116 REALTEK_USB_CMD_REQ, REALTEK_USB_WRITE,
1117 addr, 0, buf, remainder,
1118 RTW_USB_CONTROL_MSG_TIMEOUT);
1119 if (ret != remainder)
1120 goto write_error;
1121 }
1122
1123 return len;
1124
1125write_error:
1126 dev_info(&udev->dev,
1127 "%s: Failed to write block at addr: %04x size: %04x\n",
1128 __func__, addr, blocksize);
1129 return -EAGAIN;
1130}
1131
1132static u32 rtl8xxxu_read_rfreg(struct rtl8xxxu_priv *priv,
1133 enum rtl8xxxu_rfpath path, u8 reg)
1134{
1135 u32 hssia, val32, retval;
1136
1137 hssia = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
1138 if (path != RF_A)
1139 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm2);
1140 else
1141 val32 = hssia;
1142
1143 val32 &= ~FPGA0_HSSI_PARM2_ADDR_MASK;
1144 val32 |= (reg << FPGA0_HSSI_PARM2_ADDR_SHIFT);
1145 val32 |= FPGA0_HSSI_PARM2_EDGE_READ;
1146 hssia &= ~FPGA0_HSSI_PARM2_EDGE_READ;
1147 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1148
1149 udelay(10);
1150
1151 rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].hssiparm2, val32);
1152 udelay(100);
1153
1154 hssia |= FPGA0_HSSI_PARM2_EDGE_READ;
1155 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM2, hssia);
1156 udelay(10);
1157
1158 val32 = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hssiparm1);
1159 if (val32 & FPGA0_HSSI_PARM1_PI)
1160 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].hspiread);
1161 else
1162 retval = rtl8xxxu_read32(priv, rtl8xxxu_rfregs[path].lssiread);
1163
1164 retval &= 0xfffff;
1165
1166 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_READ)
1167 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1168 __func__, reg, retval);
1169 return retval;
1170}
1171
1172static int rtl8xxxu_write_rfreg(struct rtl8xxxu_priv *priv,
1173 enum rtl8xxxu_rfpath path, u8 reg, u32 data)
1174{
1175 int ret, retval;
1176 u32 dataaddr;
1177
1178 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_RFREG_WRITE)
1179 dev_info(&priv->udev->dev, "%s(%02x) = 0x%06x\n",
1180 __func__, reg, data);
1181
1182 data &= FPGA0_LSSI_PARM_DATA_MASK;
1183 dataaddr = (reg << FPGA0_LSSI_PARM_ADDR_SHIFT) | data;
1184
1185 /* Use XB for path B */
1186 ret = rtl8xxxu_write32(priv, rtl8xxxu_rfregs[path].lssiparm, dataaddr);
1187 if (ret != sizeof(dataaddr))
1188 retval = -EIO;
1189 else
1190 retval = 0;
1191
1192 udelay(1);
1193
1194 return retval;
1195}
1196
1197static int rtl8723a_h2c_cmd(struct rtl8xxxu_priv *priv, struct h2c_cmd *h2c)
1198{
1199 struct device *dev = &priv->udev->dev;
1200 int mbox_nr, retry, retval = 0;
1201 int mbox_reg, mbox_ext_reg;
1202 u8 val8;
1203
1204 mutex_lock(&priv->h2c_mutex);
1205
1206 mbox_nr = priv->next_mbox;
1207 mbox_reg = REG_HMBOX_0 + (mbox_nr * 4);
1208 mbox_ext_reg = REG_HMBOX_EXT_0 + (mbox_nr * 2);
1209
1210 /*
1211 * MBOX ready?
1212 */
1213 retry = 100;
1214 do {
1215 val8 = rtl8xxxu_read8(priv, REG_HMTFR);
1216 if (!(val8 & BIT(mbox_nr)))
1217 break;
1218 } while (retry--);
1219
1220 if (!retry) {
1221 dev_dbg(dev, "%s: Mailbox busy\n", __func__);
1222 retval = -EBUSY;
1223 goto error;
1224 }
1225
1226 /*
1227 * Need to swap as it's being swapped again by rtl8xxxu_write16/32()
1228 */
1229 if (h2c->cmd.cmd & H2C_EXT) {
1230 rtl8xxxu_write16(priv, mbox_ext_reg,
1231 le16_to_cpu(h2c->raw.ext));
1232 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1233 dev_info(dev, "H2C_EXT %04x\n",
1234 le16_to_cpu(h2c->raw.ext));
1235 }
1236 rtl8xxxu_write32(priv, mbox_reg, le32_to_cpu(h2c->raw.data));
1237 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_H2C)
1238 dev_info(dev, "H2C %08x\n", le32_to_cpu(h2c->raw.data));
1239
1240 priv->next_mbox = (mbox_nr + 1) % H2C_MAX_MBOX;
1241
1242error:
1243 mutex_unlock(&priv->h2c_mutex);
1244 return retval;
1245}
1246
1247static void rtl8723a_enable_rf(struct rtl8xxxu_priv *priv)
1248{
1249 u8 val8;
1250 u32 val32;
1251
1252 val8 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1253 val8 |= BIT(0) | BIT(3);
1254 rtl8xxxu_write8(priv, REG_SPS0_CTRL, val8);
1255
1256 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1257 val32 &= ~(BIT(4) | BIT(5));
1258 val32 |= BIT(3);
1259 if (priv->rf_paths == 2) {
1260 val32 &= ~(BIT(20) | BIT(21));
1261 val32 |= BIT(19);
1262 }
1263 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1264
1265 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1266 val32 &= ~OFDM_RF_PATH_TX_MASK;
1267 if (priv->tx_paths == 2)
1268 val32 |= OFDM_RF_PATH_TX_A | OFDM_RF_PATH_TX_B;
1269 else if (priv->rtlchip == 0x8192c || priv->rtlchip == 0x8191c)
1270 val32 |= OFDM_RF_PATH_TX_B;
1271 else
1272 val32 |= OFDM_RF_PATH_TX_A;
1273 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1274
1275 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1276 val32 &= ~FPGA_RF_MODE_JAPAN;
1277 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1278
1279 if (priv->rf_paths == 2)
1280 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x63db25a0);
1281 else
1282 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x631b25a0);
1283
1284 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0x32d95);
1285 if (priv->rf_paths == 2)
1286 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0x32d95);
1287
1288 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
1289}
1290
1291static void rtl8723a_disable_rf(struct rtl8xxxu_priv *priv)
1292{
1293 u8 sps0;
1294 u32 val32;
1295
1296 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
1297
1298 sps0 = rtl8xxxu_read8(priv, REG_SPS0_CTRL);
1299
1300 /* RF RX code for preamble power saving */
1301 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_PARM);
1302 val32 &= ~(BIT(3) | BIT(4) | BIT(5));
1303 if (priv->rf_paths == 2)
1304 val32 &= ~(BIT(19) | BIT(20) | BIT(21));
1305 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_PARM, val32);
1306
1307 /* Disable TX for four paths */
1308 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
1309 val32 &= ~OFDM_RF_PATH_TX_MASK;
1310 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
1311
1312 /* Enable power saving */
1313 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1314 val32 |= FPGA_RF_MODE_JAPAN;
1315 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1316
1317 /* AFE control register to power down bits [30:22] */
1318 if (priv->rf_paths == 2)
1319 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x00db25a0);
1320 else
1321 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, 0x001b25a0);
1322
1323 /* Power down RF module */
1324 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0);
1325 if (priv->rf_paths == 2)
1326 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC, 0);
1327
1328 sps0 &= ~(BIT(0) | BIT(3));
1329 rtl8xxxu_write8(priv, REG_SPS0_CTRL, sps0);
1330}
1331
1332
1333static void rtl8723a_stop_tx_beacon(struct rtl8xxxu_priv *priv)
1334{
1335 u8 val8;
1336
1337 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL + 2);
1338 val8 &= ~BIT(6);
1339 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
1340
1341 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x64);
1342 val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
1343 val8 &= ~BIT(0);
1344 rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
1345}
1346
1347
1348/*
1349 * The rtl8723a has 3 channel groups for it's efuse settings. It only
1350 * supports the 2.4GHz band, so channels 1 - 14:
1351 * group 0: channels 1 - 3
1352 * group 1: channels 4 - 9
1353 * group 2: channels 10 - 14
1354 *
1355 * Note: We index from 0 in the code
1356 */
1357static int rtl8723a_channel_to_group(int channel)
1358{
1359 int group;
1360
1361 if (channel < 4)
1362 group = 0;
1363 else if (channel < 10)
1364 group = 1;
1365 else
1366 group = 2;
1367
1368 return group;
1369}
1370
1371static void rtl8723au_config_channel(struct ieee80211_hw *hw)
1372{
1373 struct rtl8xxxu_priv *priv = hw->priv;
1374 u32 val32, rsr;
1375 u8 val8, opmode;
1376 bool ht = true;
1377 int sec_ch_above, channel;
1378 int i;
1379
1380 opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE);
1381 rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
1382 channel = hw->conf.chandef.chan->hw_value;
1383
1384 switch (hw->conf.chandef.width) {
1385 case NL80211_CHAN_WIDTH_20_NOHT:
1386 ht = false;
1387 case NL80211_CHAN_WIDTH_20:
1388 opmode |= BW_OPMODE_20MHZ;
1389 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1390
1391 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1392 val32 &= ~FPGA_RF_MODE;
1393 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1394
1395 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1396 val32 &= ~FPGA_RF_MODE;
1397 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1398
1399 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1400 val32 |= FPGA0_ANALOG2_20MHZ;
1401 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1402 break;
1403 case NL80211_CHAN_WIDTH_40:
1404 if (hw->conf.chandef.center_freq1 >
1405 hw->conf.chandef.chan->center_freq) {
1406 sec_ch_above = 1;
1407 channel += 2;
1408 } else {
1409 sec_ch_above = 0;
1410 channel -= 2;
1411 }
1412
1413 opmode &= ~BW_OPMODE_20MHZ;
1414 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
1415 rsr &= ~RSR_RSC_BANDWIDTH_40M;
1416 if (sec_ch_above)
1417 rsr |= RSR_RSC_UPPER_SUB_CHANNEL;
1418 else
1419 rsr |= RSR_RSC_LOWER_SUB_CHANNEL;
1420 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr);
1421
1422 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
1423 val32 |= FPGA_RF_MODE;
1424 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
1425
1426 val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
1427 val32 |= FPGA_RF_MODE;
1428 rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
1429
1430 /*
1431 * Set Control channel to upper or lower. These settings
1432 * are required only for 40MHz
1433 */
1434 val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
1435 val32 &= ~CCK0_SIDEBAND;
1436 if (!sec_ch_above)
1437 val32 |= CCK0_SIDEBAND;
1438 rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
1439
1440 val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
1441 val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
1442 if (sec_ch_above)
1443 val32 |= OFDM_LSTF_PRIME_CH_LOW;
1444 else
1445 val32 |= OFDM_LSTF_PRIME_CH_HIGH;
1446 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
1447
1448 val32 = rtl8xxxu_read32(priv, REG_FPGA0_ANALOG2);
1449 val32 &= ~FPGA0_ANALOG2_20MHZ;
1450 rtl8xxxu_write32(priv, REG_FPGA0_ANALOG2, val32);
1451
1452 val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
1453 val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
1454 if (sec_ch_above)
1455 val32 |= FPGA0_PS_UPPER_CHANNEL;
1456 else
1457 val32 |= FPGA0_PS_LOWER_CHANNEL;
1458 rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
1459 break;
1460
1461 default:
1462 break;
1463 }
1464
1465 for (i = RF_A; i < priv->rf_paths; i++) {
1466 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1467 val32 &= ~MODE_AG_CHANNEL_MASK;
1468 val32 |= channel;
1469 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1470 }
1471
1472 if (ht)
1473 val8 = 0x0e;
1474 else
1475 val8 = 0x0a;
1476
1477 rtl8xxxu_write8(priv, REG_SIFS_CCK + 1, val8);
1478 rtl8xxxu_write8(priv, REG_SIFS_OFDM + 1, val8);
1479
1480 rtl8xxxu_write16(priv, REG_R2T_SIFS, 0x0808);
1481 rtl8xxxu_write16(priv, REG_T2T_SIFS, 0x0a0a);
1482
1483 for (i = RF_A; i < priv->rf_paths; i++) {
1484 val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
1485 if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40)
1486 val32 &= ~MODE_AG_CHANNEL_20MHZ;
1487 else
1488 val32 |= MODE_AG_CHANNEL_20MHZ;
1489 rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
1490 }
1491}
1492
1493static void
1494rtl8723a_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
1495{
1496 u8 cck[RTL8723A_MAX_RF_PATHS], ofdm[RTL8723A_MAX_RF_PATHS];
1497 u8 ofdmbase[RTL8723A_MAX_RF_PATHS], mcsbase[RTL8723A_MAX_RF_PATHS];
1498 u32 val32, ofdm_a, ofdm_b, mcs_a, mcs_b;
1499 u8 val8;
1500 int group, i;
1501
1502 group = rtl8723a_channel_to_group(channel);
1503
1504 cck[0] = priv->cck_tx_power_index_A[group];
1505 cck[1] = priv->cck_tx_power_index_B[group];
1506
1507 ofdm[0] = priv->ht40_1s_tx_power_index_A[group];
1508 ofdm[1] = priv->ht40_1s_tx_power_index_B[group];
1509
1510 ofdmbase[0] = ofdm[0] + priv->ofdm_tx_power_index_diff[group].a;
1511 ofdmbase[1] = ofdm[1] + priv->ofdm_tx_power_index_diff[group].b;
1512
1513 mcsbase[0] = ofdm[0];
1514 mcsbase[1] = ofdm[1];
1515 if (!ht40) {
1516 mcsbase[0] += priv->ht20_tx_power_index_diff[group].a;
1517 mcsbase[1] += priv->ht20_tx_power_index_diff[group].b;
1518 }
1519
1520 if (priv->tx_paths > 1) {
1521 if (ofdm[0] > priv->ht40_2s_tx_power_index_diff[group].a)
1522 ofdm[0] -= priv->ht40_2s_tx_power_index_diff[group].a;
1523 if (ofdm[1] > priv->ht40_2s_tx_power_index_diff[group].b)
1524 ofdm[1] -= priv->ht40_2s_tx_power_index_diff[group].b;
1525 }
1526
1527 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
1528 dev_info(&priv->udev->dev,
1529 "%s: Setting TX power CCK A: %02x, "
1530 "CCK B: %02x, OFDM A: %02x, OFDM B: %02x\n",
1531 __func__, cck[0], cck[1], ofdm[0], ofdm[1]);
1532
1533 for (i = 0; i < RTL8723A_MAX_RF_PATHS; i++) {
1534 if (cck[i] > RF6052_MAX_TX_PWR)
1535 cck[i] = RF6052_MAX_TX_PWR;
1536 if (ofdm[i] > RF6052_MAX_TX_PWR)
1537 ofdm[i] = RF6052_MAX_TX_PWR;
1538 }
1539
1540 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
1541 val32 &= 0xffff00ff;
1542 val32 |= (cck[0] << 8);
1543 rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
1544
1545 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
1546 val32 &= 0xff;
1547 val32 |= ((cck[0] << 8) | (cck[0] << 16) | (cck[0] << 24));
1548 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
1549
1550 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
1551 val32 &= 0xffffff00;
1552 val32 |= cck[1];
1553 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
1554
1555 val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32);
1556 val32 &= 0xff;
1557 val32 |= ((cck[1] << 8) | (cck[1] << 16) | (cck[1] << 24));
1558 rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32);
1559
1560 ofdm_a = ofdmbase[0] | ofdmbase[0] << 8 |
1561 ofdmbase[0] << 16 | ofdmbase[0] << 24;
1562 ofdm_b = ofdmbase[1] | ofdmbase[1] << 8 |
1563 ofdmbase[1] << 16 | ofdmbase[1] << 24;
1564 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm_a);
1565 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm_b);
1566
1567 rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm_a);
1568 rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm_b);
1569
1570 mcs_a = mcsbase[0] | mcsbase[0] << 8 |
1571 mcsbase[0] << 16 | mcsbase[0] << 24;
1572 mcs_b = mcsbase[1] | mcsbase[1] << 8 |
1573 mcsbase[1] << 16 | mcsbase[1] << 24;
1574
1575 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs_a);
1576 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs_b);
1577
1578 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs_a);
1579 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs_b);
1580
1581 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs_a);
1582 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs_b);
1583
1584 rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs_a);
1585 for (i = 0; i < 3; i++) {
1586 if (i != 2)
1587 val8 = (mcsbase[0] > 8) ? (mcsbase[0] - 8) : 0;
1588 else
1589 val8 = (mcsbase[0] > 6) ? (mcsbase[0] - 6) : 0;
1590 rtl8xxxu_write8(priv, REG_OFDM0_XC_TX_IQ_IMBALANCE + i, val8);
1591 }
1592 rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs_b);
1593 for (i = 0; i < 3; i++) {
1594 if (i != 2)
1595 val8 = (mcsbase[1] > 8) ? (mcsbase[1] - 8) : 0;
1596 else
1597 val8 = (mcsbase[1] > 6) ? (mcsbase[1] - 6) : 0;
1598 rtl8xxxu_write8(priv, REG_OFDM0_XD_TX_IQ_IMBALANCE + i, val8);
1599 }
1600}
1601
1602static void rtl8xxxu_set_linktype(struct rtl8xxxu_priv *priv,
1603 enum nl80211_iftype linktype)
1604{
Jes Sorensena26703f2016-02-03 13:39:56 -05001605 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001606
Jes Sorensena26703f2016-02-03 13:39:56 -05001607 val8 = rtl8xxxu_read8(priv, REG_MSR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001608 val8 &= ~MSR_LINKTYPE_MASK;
1609
1610 switch (linktype) {
1611 case NL80211_IFTYPE_UNSPECIFIED:
1612 val8 |= MSR_LINKTYPE_NONE;
1613 break;
1614 case NL80211_IFTYPE_ADHOC:
1615 val8 |= MSR_LINKTYPE_ADHOC;
1616 break;
1617 case NL80211_IFTYPE_STATION:
1618 val8 |= MSR_LINKTYPE_STATION;
1619 break;
1620 case NL80211_IFTYPE_AP:
1621 val8 |= MSR_LINKTYPE_AP;
1622 break;
1623 default:
1624 goto out;
1625 }
1626
1627 rtl8xxxu_write8(priv, REG_MSR, val8);
1628out:
1629 return;
1630}
1631
1632static void
1633rtl8xxxu_set_retry(struct rtl8xxxu_priv *priv, u16 short_retry, u16 long_retry)
1634{
1635 u16 val16;
1636
1637 val16 = ((short_retry << RETRY_LIMIT_SHORT_SHIFT) &
1638 RETRY_LIMIT_SHORT_MASK) |
1639 ((long_retry << RETRY_LIMIT_LONG_SHIFT) &
1640 RETRY_LIMIT_LONG_MASK);
1641
1642 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
1643}
1644
1645static void
1646rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm)
1647{
1648 u16 val16;
1649
1650 val16 = ((cck << SPEC_SIFS_CCK_SHIFT) & SPEC_SIFS_CCK_MASK) |
1651 ((ofdm << SPEC_SIFS_OFDM_SHIFT) & SPEC_SIFS_OFDM_MASK);
1652
1653 rtl8xxxu_write16(priv, REG_SPEC_SIFS, val16);
1654}
1655
1656static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv)
1657{
1658 struct device *dev = &priv->udev->dev;
1659 char *cut;
1660
1661 switch (priv->chip_cut) {
1662 case 0:
1663 cut = "A";
1664 break;
1665 case 1:
1666 cut = "B";
1667 break;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001668 case 2:
1669 cut = "C";
1670 break;
1671 case 3:
1672 cut = "D";
1673 break;
1674 case 4:
1675 cut = "E";
1676 break;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001677 default:
1678 cut = "unknown";
1679 }
1680
1681 dev_info(dev,
1682 "RTL%s rev %s (%s) %iT%iR, TX queues %i, WiFi=%i, BT=%i, GPS=%i, HI PA=%i\n",
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001683 priv->chip_name, cut, priv->chip_vendor, priv->tx_paths,
1684 priv->rx_paths, priv->ep_tx_count, priv->has_wifi,
1685 priv->has_bluetooth, priv->has_gps, priv->hi_pa);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001686
1687 dev_info(dev, "RTL%s MAC: %pM\n", priv->chip_name, priv->mac_addr);
1688}
1689
1690static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
1691{
1692 struct device *dev = &priv->udev->dev;
1693 u32 val32, bonding;
1694 u16 val16;
1695
1696 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
1697 priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >>
1698 SYS_CFG_CHIP_VERSION_SHIFT;
1699 if (val32 & SYS_CFG_TRP_VAUX_EN) {
1700 dev_info(dev, "Unsupported test chip\n");
1701 return -ENOTSUPP;
1702 }
1703
1704 if (val32 & SYS_CFG_BT_FUNC) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05001705 if (priv->chip_cut >= 3) {
1706 sprintf(priv->chip_name, "8723BU");
1707 priv->rtlchip = 0x8723b;
1708 } else {
1709 sprintf(priv->chip_name, "8723AU");
1710 priv->rtlchip = 0x8723a;
1711 }
1712
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001713 priv->rf_paths = 1;
1714 priv->rx_paths = 1;
1715 priv->tx_paths = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001716
1717 val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
1718 if (val32 & MULTI_WIFI_FUNC_EN)
1719 priv->has_wifi = 1;
1720 if (val32 & MULTI_BT_FUNC_EN)
1721 priv->has_bluetooth = 1;
1722 if (val32 & MULTI_GPS_FUNC_EN)
1723 priv->has_gps = 1;
Jakub Sitnicki38451992016-02-03 13:39:49 -05001724 priv->is_multi_func = 1;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001725 } else if (val32 & SYS_CFG_TYPE_ID) {
1726 bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
1727 bonding &= HPON_FSM_BONDING_MASK;
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001728 if (priv->chip_cut >= 3) {
1729 if (bonding == HPON_FSM_BONDING_1T2R) {
1730 sprintf(priv->chip_name, "8191EU");
1731 priv->rf_paths = 2;
1732 priv->rx_paths = 2;
1733 priv->tx_paths = 1;
1734 priv->rtlchip = 0x8191e;
1735 } else {
1736 sprintf(priv->chip_name, "8192EU");
1737 priv->rf_paths = 2;
1738 priv->rx_paths = 2;
1739 priv->tx_paths = 2;
1740 priv->rtlchip = 0x8192e;
1741 }
1742 } else if (bonding == HPON_FSM_BONDING_1T2R) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001743 sprintf(priv->chip_name, "8191CU");
1744 priv->rf_paths = 2;
1745 priv->rx_paths = 2;
1746 priv->tx_paths = 1;
1747 priv->rtlchip = 0x8191c;
1748 } else {
1749 sprintf(priv->chip_name, "8192CU");
1750 priv->rf_paths = 2;
1751 priv->rx_paths = 2;
1752 priv->tx_paths = 2;
1753 priv->rtlchip = 0x8192c;
1754 }
1755 priv->has_wifi = 1;
1756 } else {
1757 sprintf(priv->chip_name, "8188CU");
1758 priv->rf_paths = 1;
1759 priv->rx_paths = 1;
1760 priv->tx_paths = 1;
1761 priv->rtlchip = 0x8188c;
1762 priv->has_wifi = 1;
1763 }
1764
Jes Sorensen0e5d4352016-02-29 17:04:00 -05001765 switch (priv->rtlchip) {
1766 case 0x8188e:
1767 case 0x8192e:
1768 case 0x8723b:
1769 switch (val32 & SYS_CFG_VENDOR_EXT_MASK) {
1770 case SYS_CFG_VENDOR_ID_TSMC:
1771 sprintf(priv->chip_vendor, "TSMC");
1772 break;
1773 case SYS_CFG_VENDOR_ID_SMIC:
1774 sprintf(priv->chip_vendor, "SMIC");
1775 priv->vendor_smic = 1;
1776 break;
1777 case SYS_CFG_VENDOR_ID_UMC:
1778 sprintf(priv->chip_vendor, "UMC");
1779 priv->vendor_umc = 1;
1780 break;
1781 default:
1782 sprintf(priv->chip_vendor, "unknown");
1783 }
1784 break;
1785 default:
1786 if (val32 & SYS_CFG_VENDOR_ID) {
1787 sprintf(priv->chip_vendor, "UMC");
1788 priv->vendor_umc = 1;
1789 } else {
1790 sprintf(priv->chip_vendor, "TSMC");
1791 }
1792 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001793
1794 val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
1795 priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;
1796
1797 val16 = rtl8xxxu_read16(priv, REG_NORMAL_SIE_EP_TX);
1798 if (val16 & NORMAL_SIE_EP_TX_HIGH_MASK) {
1799 priv->ep_tx_high_queue = 1;
1800 priv->ep_tx_count++;
1801 }
1802
1803 if (val16 & NORMAL_SIE_EP_TX_NORMAL_MASK) {
1804 priv->ep_tx_normal_queue = 1;
1805 priv->ep_tx_count++;
1806 }
1807
1808 if (val16 & NORMAL_SIE_EP_TX_LOW_MASK) {
1809 priv->ep_tx_low_queue = 1;
1810 priv->ep_tx_count++;
1811 }
1812
1813 /*
1814 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
1815 */
1816 if (!priv->ep_tx_count) {
1817 switch (priv->nr_out_eps) {
Jes Sorensen35a741f2016-02-29 17:04:10 -05001818 case 4:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001819 case 3:
1820 priv->ep_tx_low_queue = 1;
1821 priv->ep_tx_count++;
1822 case 2:
1823 priv->ep_tx_normal_queue = 1;
1824 priv->ep_tx_count++;
1825 case 1:
1826 priv->ep_tx_high_queue = 1;
1827 priv->ep_tx_count++;
1828 break;
1829 default:
1830 dev_info(dev, "Unsupported USB TX end-points\n");
1831 return -ENOTSUPP;
1832 }
1833 }
1834
1835 return 0;
1836}
1837
1838static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
1839{
1840 if (priv->efuse_wifi.efuse8723.rtl_id != cpu_to_le16(0x8129))
1841 return -EINVAL;
1842
1843 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8723.mac_addr);
1844
1845 memcpy(priv->cck_tx_power_index_A,
1846 priv->efuse_wifi.efuse8723.cck_tx_power_index_A,
1847 sizeof(priv->cck_tx_power_index_A));
1848 memcpy(priv->cck_tx_power_index_B,
1849 priv->efuse_wifi.efuse8723.cck_tx_power_index_B,
1850 sizeof(priv->cck_tx_power_index_B));
1851
1852 memcpy(priv->ht40_1s_tx_power_index_A,
1853 priv->efuse_wifi.efuse8723.ht40_1s_tx_power_index_A,
1854 sizeof(priv->ht40_1s_tx_power_index_A));
1855 memcpy(priv->ht40_1s_tx_power_index_B,
1856 priv->efuse_wifi.efuse8723.ht40_1s_tx_power_index_B,
1857 sizeof(priv->ht40_1s_tx_power_index_B));
1858
1859 memcpy(priv->ht20_tx_power_index_diff,
1860 priv->efuse_wifi.efuse8723.ht20_tx_power_index_diff,
1861 sizeof(priv->ht20_tx_power_index_diff));
1862 memcpy(priv->ofdm_tx_power_index_diff,
1863 priv->efuse_wifi.efuse8723.ofdm_tx_power_index_diff,
1864 sizeof(priv->ofdm_tx_power_index_diff));
1865
1866 memcpy(priv->ht40_max_power_offset,
1867 priv->efuse_wifi.efuse8723.ht40_max_power_offset,
1868 sizeof(priv->ht40_max_power_offset));
1869 memcpy(priv->ht20_max_power_offset,
1870 priv->efuse_wifi.efuse8723.ht20_max_power_offset,
1871 sizeof(priv->ht20_max_power_offset));
1872
1873 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
1874 priv->efuse_wifi.efuse8723.vendor_name);
1875 dev_info(&priv->udev->dev, "Product: %.41s\n",
1876 priv->efuse_wifi.efuse8723.device_name);
1877 return 0;
1878}
1879
Jes Sorensen3c836d62016-02-29 17:04:11 -05001880static int rtl8723bu_parse_efuse(struct rtl8xxxu_priv *priv)
1881{
1882 if (priv->efuse_wifi.efuse8723bu.rtl_id != cpu_to_le16(0x8129))
1883 return -EINVAL;
1884
1885 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8723bu.mac_addr);
1886
1887 memcpy(priv->cck_tx_power_index_A,
1888 priv->efuse_wifi.efuse8723bu.cck_tx_power_index_A,
1889 sizeof(priv->cck_tx_power_index_A));
1890 memcpy(priv->cck_tx_power_index_B,
1891 priv->efuse_wifi.efuse8723bu.cck_tx_power_index_B,
1892 sizeof(priv->cck_tx_power_index_B));
1893
1894 memcpy(priv->ht40_1s_tx_power_index_A,
1895 priv->efuse_wifi.efuse8723bu.ht40_1s_tx_power_index_A,
1896 sizeof(priv->ht40_1s_tx_power_index_A));
1897 memcpy(priv->ht40_1s_tx_power_index_B,
1898 priv->efuse_wifi.efuse8723bu.ht40_1s_tx_power_index_B,
1899 sizeof(priv->ht40_1s_tx_power_index_B));
1900
1901 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
1902 priv->efuse_wifi.efuse8723bu.vendor_name);
1903 dev_info(&priv->udev->dev, "Product: %.41s\n",
1904 priv->efuse_wifi.efuse8723bu.device_name);
1905
1906 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
1907 int i;
1908 unsigned char *raw = priv->efuse_wifi.raw;
1909
1910 dev_info(&priv->udev->dev,
1911 "%s: dumping efuse (0x%02zx bytes):\n",
1912 __func__, sizeof(struct rtl8723bu_efuse));
1913 for (i = 0; i < sizeof(struct rtl8723bu_efuse); i += 8) {
1914 dev_info(&priv->udev->dev, "%02x: "
1915 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
1916 raw[i], raw[i + 1], raw[i + 2],
1917 raw[i + 3], raw[i + 4], raw[i + 5],
1918 raw[i + 6], raw[i + 7]);
1919 }
1920 }
1921
1922 return 0;
1923}
1924
Kalle Valoc0963772015-10-25 18:24:38 +02001925#ifdef CONFIG_RTL8XXXU_UNTESTED
1926
Jes Sorensen26f1fad2015-10-14 20:44:51 -04001927static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
1928{
1929 int i;
1930
1931 if (priv->efuse_wifi.efuse8192.rtl_id != cpu_to_le16(0x8129))
1932 return -EINVAL;
1933
1934 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8192.mac_addr);
1935
1936 memcpy(priv->cck_tx_power_index_A,
1937 priv->efuse_wifi.efuse8192.cck_tx_power_index_A,
1938 sizeof(priv->cck_tx_power_index_A));
1939 memcpy(priv->cck_tx_power_index_B,
1940 priv->efuse_wifi.efuse8192.cck_tx_power_index_B,
1941 sizeof(priv->cck_tx_power_index_B));
1942
1943 memcpy(priv->ht40_1s_tx_power_index_A,
1944 priv->efuse_wifi.efuse8192.ht40_1s_tx_power_index_A,
1945 sizeof(priv->ht40_1s_tx_power_index_A));
1946 memcpy(priv->ht40_1s_tx_power_index_B,
1947 priv->efuse_wifi.efuse8192.ht40_1s_tx_power_index_B,
1948 sizeof(priv->ht40_1s_tx_power_index_B));
1949 memcpy(priv->ht40_2s_tx_power_index_diff,
1950 priv->efuse_wifi.efuse8192.ht40_2s_tx_power_index_diff,
1951 sizeof(priv->ht40_2s_tx_power_index_diff));
1952
1953 memcpy(priv->ht20_tx_power_index_diff,
1954 priv->efuse_wifi.efuse8192.ht20_tx_power_index_diff,
1955 sizeof(priv->ht20_tx_power_index_diff));
1956 memcpy(priv->ofdm_tx_power_index_diff,
1957 priv->efuse_wifi.efuse8192.ofdm_tx_power_index_diff,
1958 sizeof(priv->ofdm_tx_power_index_diff));
1959
1960 memcpy(priv->ht40_max_power_offset,
1961 priv->efuse_wifi.efuse8192.ht40_max_power_offset,
1962 sizeof(priv->ht40_max_power_offset));
1963 memcpy(priv->ht20_max_power_offset,
1964 priv->efuse_wifi.efuse8192.ht20_max_power_offset,
1965 sizeof(priv->ht20_max_power_offset));
1966
1967 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
1968 priv->efuse_wifi.efuse8192.vendor_name);
1969 dev_info(&priv->udev->dev, "Product: %.20s\n",
1970 priv->efuse_wifi.efuse8192.device_name);
1971
1972 if (priv->efuse_wifi.efuse8192.rf_regulatory & 0x20) {
1973 sprintf(priv->chip_name, "8188RU");
1974 priv->hi_pa = 1;
1975 }
1976
1977 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
1978 unsigned char *raw = priv->efuse_wifi.raw;
1979
1980 dev_info(&priv->udev->dev,
1981 "%s: dumping efuse (0x%02zx bytes):\n",
1982 __func__, sizeof(struct rtl8192cu_efuse));
1983 for (i = 0; i < sizeof(struct rtl8192cu_efuse); i += 8) {
1984 dev_info(&priv->udev->dev, "%02x: "
1985 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
1986 raw[i], raw[i + 1], raw[i + 2],
1987 raw[i + 3], raw[i + 4], raw[i + 5],
1988 raw[i + 6], raw[i + 7]);
1989 }
1990 }
1991 return 0;
1992}
1993
Kalle Valoc0963772015-10-25 18:24:38 +02001994#endif
1995
Jes Sorensen3307d842016-02-29 17:03:59 -05001996static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
1997{
1998 int i;
1999
2000 if (priv->efuse_wifi.efuse8192eu.rtl_id != cpu_to_le16(0x8129))
2001 return -EINVAL;
2002
2003 ether_addr_copy(priv->mac_addr, priv->efuse_wifi.efuse8192eu.mac_addr);
2004
2005 memcpy(priv->cck_tx_power_index_A,
2006 priv->efuse_wifi.efuse8192eu.cck_tx_power_index_A,
2007 sizeof(priv->cck_tx_power_index_A));
2008 memcpy(priv->cck_tx_power_index_B,
2009 priv->efuse_wifi.efuse8192eu.cck_tx_power_index_B,
2010 sizeof(priv->cck_tx_power_index_B));
2011
2012 memcpy(priv->ht40_1s_tx_power_index_A,
2013 priv->efuse_wifi.efuse8192eu.ht40_1s_tx_power_index_A,
2014 sizeof(priv->ht40_1s_tx_power_index_A));
2015 memcpy(priv->ht40_1s_tx_power_index_B,
2016 priv->efuse_wifi.efuse8192eu.ht40_1s_tx_power_index_B,
2017 sizeof(priv->ht40_1s_tx_power_index_B));
2018
2019 dev_info(&priv->udev->dev, "Vendor: %.7s\n",
2020 priv->efuse_wifi.efuse8192eu.vendor_name);
2021 dev_info(&priv->udev->dev, "Product: %.11s\n",
2022 priv->efuse_wifi.efuse8192eu.device_name);
2023 dev_info(&priv->udev->dev, "Serial: %.11s\n",
2024 priv->efuse_wifi.efuse8192eu.serial);
2025
2026 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) {
2027 unsigned char *raw = priv->efuse_wifi.raw;
2028
2029 dev_info(&priv->udev->dev,
2030 "%s: dumping efuse (0x%02zx bytes):\n",
2031 __func__, sizeof(struct rtl8192eu_efuse));
2032 for (i = 0; i < sizeof(struct rtl8192eu_efuse); i += 8) {
2033 dev_info(&priv->udev->dev, "%02x: "
2034 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
2035 raw[i], raw[i + 1], raw[i + 2],
2036 raw[i + 3], raw[i + 4], raw[i + 5],
2037 raw[i + 6], raw[i + 7]);
2038 }
2039 }
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002040 return 0;
Jes Sorensen3307d842016-02-29 17:03:59 -05002041}
2042
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002043static int
2044rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data)
2045{
2046 int i;
2047 u8 val8;
2048 u32 val32;
2049
2050 /* Write Address */
2051 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 1, offset & 0xff);
2052 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 2);
2053 val8 &= 0xfc;
2054 val8 |= (offset >> 8) & 0x03;
2055 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 2, val8);
2056
2057 val8 = rtl8xxxu_read8(priv, REG_EFUSE_CTRL + 3);
2058 rtl8xxxu_write8(priv, REG_EFUSE_CTRL + 3, val8 & 0x7f);
2059
2060 /* Poll for data read */
2061 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2062 for (i = 0; i < RTL8XXXU_MAX_REG_POLL; i++) {
2063 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2064 if (val32 & BIT(31))
2065 break;
2066 }
2067
2068 if (i == RTL8XXXU_MAX_REG_POLL)
2069 return -EIO;
2070
2071 udelay(50);
2072 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
2073
2074 *data = val32 & 0xff;
2075 return 0;
2076}
2077
2078static int rtl8xxxu_read_efuse(struct rtl8xxxu_priv *priv)
2079{
2080 struct device *dev = &priv->udev->dev;
2081 int i, ret = 0;
2082 u8 val8, word_mask, header, extheader;
2083 u16 val16, efuse_addr, offset;
2084 u32 val32;
2085
2086 val16 = rtl8xxxu_read16(priv, REG_9346CR);
2087 if (val16 & EEPROM_ENABLE)
2088 priv->has_eeprom = 1;
2089 if (val16 & EEPROM_BOOT)
2090 priv->boot_eeprom = 1;
2091
Jakub Sitnicki38451992016-02-03 13:39:49 -05002092 if (priv->is_multi_func) {
2093 val32 = rtl8xxxu_read32(priv, REG_EFUSE_TEST);
2094 val32 = (val32 & ~EFUSE_SELECT_MASK) | EFUSE_WIFI_SELECT;
2095 rtl8xxxu_write32(priv, REG_EFUSE_TEST, val32);
2096 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002097
2098 dev_dbg(dev, "Booting from %s\n",
2099 priv->boot_eeprom ? "EEPROM" : "EFUSE");
2100
2101 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_ENABLE);
2102
2103 /* 1.2V Power: From VDDON with Power Cut(0x0000[15]), default valid */
2104 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
2105 if (!(val16 & SYS_ISO_PWC_EV12V)) {
2106 val16 |= SYS_ISO_PWC_EV12V;
2107 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
2108 }
2109 /* Reset: 0x0000[28], default valid */
2110 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2111 if (!(val16 & SYS_FUNC_ELDR)) {
2112 val16 |= SYS_FUNC_ELDR;
2113 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
2114 }
2115
2116 /*
2117 * Clock: Gated(0x0008[5]) 8M(0x0008[1]) clock from ANA, default valid
2118 */
2119 val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR);
2120 if (!(val16 & SYS_CLK_LOADER_ENABLE) || !(val16 & SYS_CLK_ANA8M)) {
2121 val16 |= (SYS_CLK_LOADER_ENABLE | SYS_CLK_ANA8M);
2122 rtl8xxxu_write16(priv, REG_SYS_CLKR, val16);
2123 }
2124
2125 /* Default value is 0xff */
Jes Sorensen3307d842016-02-29 17:03:59 -05002126 memset(priv->efuse_wifi.raw, 0xff, EFUSE_MAP_LEN);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002127
2128 efuse_addr = 0;
2129 while (efuse_addr < EFUSE_REAL_CONTENT_LEN_8723A) {
2130 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &header);
2131 if (ret || header == 0xff)
2132 goto exit;
2133
2134 if ((header & 0x1f) == 0x0f) { /* extended header */
2135 offset = (header & 0xe0) >> 5;
2136
2137 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++,
2138 &extheader);
2139 if (ret)
2140 goto exit;
2141 /* All words disabled */
2142 if ((extheader & 0x0f) == 0x0f)
2143 continue;
2144
2145 offset |= ((extheader & 0xf0) >> 1);
2146 word_mask = extheader & 0x0f;
2147 } else {
2148 offset = (header >> 4) & 0x0f;
2149 word_mask = header & 0x0f;
2150 }
2151
2152 if (offset < EFUSE_MAX_SECTION_8723A) {
2153 u16 map_addr;
2154 /* Get word enable value from PG header */
2155
2156 /* We have 8 bits to indicate validity */
2157 map_addr = offset * 8;
Jes Sorensen3307d842016-02-29 17:03:59 -05002158 if (map_addr >= EFUSE_MAP_LEN) {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002159 dev_warn(dev, "%s: Illegal map_addr (%04x), "
2160 "efuse corrupt!\n",
2161 __func__, map_addr);
2162 ret = -EINVAL;
2163 goto exit;
2164 }
2165 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
2166 /* Check word enable condition in the section */
2167 if (!(word_mask & BIT(i))) {
2168 ret = rtl8xxxu_read_efuse8(priv,
2169 efuse_addr++,
2170 &val8);
2171 if (ret)
2172 goto exit;
2173 priv->efuse_wifi.raw[map_addr++] = val8;
2174
2175 ret = rtl8xxxu_read_efuse8(priv,
2176 efuse_addr++,
2177 &val8);
2178 if (ret)
2179 goto exit;
2180 priv->efuse_wifi.raw[map_addr++] = val8;
2181 } else
2182 map_addr += 2;
2183 }
2184 } else {
2185 dev_warn(dev,
2186 "%s: Illegal offset (%04x), efuse corrupt!\n",
2187 __func__, offset);
2188 ret = -EINVAL;
2189 goto exit;
2190 }
2191 }
2192
2193exit:
2194 rtl8xxxu_write8(priv, REG_EFUSE_ACCESS, EFUSE_ACCESS_DISABLE);
2195
2196 return ret;
2197}
2198
Jes Sorensend48fe602016-02-03 13:39:44 -05002199static void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv)
2200{
2201 u8 val8;
2202 u16 sys_func;
2203
2204 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002205 val8 &= ~BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002206 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2207 sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2208 sys_func &= ~SYS_FUNC_CPU_ENABLE;
2209 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2210 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
Jes Sorensen53b381c2016-02-03 13:39:57 -05002211 val8 |= BIT(0);
Jes Sorensend48fe602016-02-03 13:39:44 -05002212 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
2213 sys_func |= SYS_FUNC_CPU_ENABLE;
2214 rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
2215}
2216
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002217static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv)
2218{
2219 struct device *dev = &priv->udev->dev;
2220 int ret = 0, i;
2221 u32 val32;
2222
2223 /* Poll checksum report */
2224 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2225 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2226 if (val32 & MCU_FW_DL_CSUM_REPORT)
2227 break;
2228 }
2229
2230 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2231 dev_warn(dev, "Firmware checksum poll timed out\n");
2232 ret = -EAGAIN;
2233 goto exit;
2234 }
2235
2236 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2237 val32 |= MCU_FW_DL_READY;
2238 val32 &= ~MCU_WINT_INIT_READY;
2239 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
2240
Jes Sorensend48fe602016-02-03 13:39:44 -05002241 /*
2242 * Reset the 8051 in order for the firmware to start running,
2243 * otherwise it won't come up on the 8192eu
2244 */
2245 rtl8xxxu_reset_8051(priv);
2246
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002247 /* Wait for firmware to become ready */
2248 for (i = 0; i < RTL8XXXU_FIRMWARE_POLL_MAX; i++) {
2249 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
2250 if (val32 & MCU_WINT_INIT_READY)
2251 break;
2252
2253 udelay(100);
2254 }
2255
2256 if (i == RTL8XXXU_FIRMWARE_POLL_MAX) {
2257 dev_warn(dev, "Firmware failed to start\n");
2258 ret = -EAGAIN;
2259 goto exit;
2260 }
2261
2262exit:
2263 return ret;
2264}
2265
2266static int rtl8xxxu_download_firmware(struct rtl8xxxu_priv *priv)
2267{
2268 int pages, remainder, i, ret;
Jes Sorensend48fe602016-02-03 13:39:44 -05002269 u8 val8;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002270 u16 val16;
2271 u32 val32;
2272 u8 *fwptr;
2273
2274 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC + 1);
2275 val8 |= 4;
2276 rtl8xxxu_write8(priv, REG_SYS_FUNC + 1, val8);
2277
2278 /* 8051 enable */
2279 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
Jes Sorensen43154f62016-02-03 13:39:35 -05002280 val16 |= SYS_FUNC_CPU_ENABLE;
2281 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002282
Jes Sorensen216202a2016-02-03 13:39:37 -05002283 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
2284 if (val8 & MCU_FW_RAM_SEL) {
2285 pr_info("do the RAM reset\n");
2286 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
Jes Sorensend48fe602016-02-03 13:39:44 -05002287 rtl8xxxu_reset_8051(priv);
Jes Sorensen216202a2016-02-03 13:39:37 -05002288 }
2289
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002290 /* MCU firmware download enable */
2291 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002292 val8 |= MCU_FW_DL_ENABLE;
2293 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002294
2295 /* 8051 reset */
2296 val32 = rtl8xxxu_read32(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002297 val32 &= ~BIT(19);
2298 rtl8xxxu_write32(priv, REG_MCU_FW_DL, val32);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002299
2300 /* Reset firmware download checksum */
2301 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002302 val8 |= MCU_FW_DL_CSUM_REPORT;
2303 rtl8xxxu_write8(priv, REG_MCU_FW_DL, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002304
2305 pages = priv->fw_size / RTL_FW_PAGE_SIZE;
2306 remainder = priv->fw_size % RTL_FW_PAGE_SIZE;
2307
2308 fwptr = priv->fw_data->data;
2309
2310 for (i = 0; i < pages; i++) {
2311 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002312 val8 |= i;
2313 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002314
2315 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2316 fwptr, RTL_FW_PAGE_SIZE);
2317 if (ret != RTL_FW_PAGE_SIZE) {
2318 ret = -EAGAIN;
2319 goto fw_abort;
2320 }
2321
2322 fwptr += RTL_FW_PAGE_SIZE;
2323 }
2324
2325 if (remainder) {
2326 val8 = rtl8xxxu_read8(priv, REG_MCU_FW_DL + 2) & 0xF8;
Jes Sorensenef1c0492016-02-03 13:39:36 -05002327 val8 |= i;
2328 rtl8xxxu_write8(priv, REG_MCU_FW_DL + 2, val8);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002329 ret = rtl8xxxu_writeN(priv, REG_FW_START_ADDRESS,
2330 fwptr, remainder);
2331 if (ret != remainder) {
2332 ret = -EAGAIN;
2333 goto fw_abort;
2334 }
2335 }
2336
2337 ret = 0;
2338fw_abort:
2339 /* MCU firmware download disable */
2340 val16 = rtl8xxxu_read16(priv, REG_MCU_FW_DL);
Jes Sorensenef1c0492016-02-03 13:39:36 -05002341 val16 &= ~MCU_FW_DL_ENABLE;
2342 rtl8xxxu_write16(priv, REG_MCU_FW_DL, val16);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002343
2344 return ret;
2345}
2346
2347static int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name)
2348{
2349 struct device *dev = &priv->udev->dev;
2350 const struct firmware *fw;
2351 int ret = 0;
2352 u16 signature;
2353
2354 dev_info(dev, "%s: Loading firmware %s\n", DRIVER_NAME, fw_name);
2355 if (request_firmware(&fw, fw_name, &priv->udev->dev)) {
2356 dev_warn(dev, "request_firmware(%s) failed\n", fw_name);
2357 ret = -EAGAIN;
2358 goto exit;
2359 }
2360 if (!fw) {
2361 dev_warn(dev, "Firmware data not available\n");
2362 ret = -EINVAL;
2363 goto exit;
2364 }
2365
2366 priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL);
Tobias Klauser98e27cb2016-02-03 13:39:43 -05002367 if (!priv->fw_data) {
2368 ret = -ENOMEM;
2369 goto exit;
2370 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002371 priv->fw_size = fw->size - sizeof(struct rtl8xxxu_firmware_header);
2372
2373 signature = le16_to_cpu(priv->fw_data->signature);
2374 switch (signature & 0xfff0) {
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002375 case 0x92e0:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002376 case 0x92c0:
2377 case 0x88c0:
Jes Sorensen35a741f2016-02-29 17:04:10 -05002378 case 0x5300:
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002379 case 0x2300:
2380 break;
2381 default:
2382 ret = -EINVAL;
2383 dev_warn(dev, "%s: Invalid firmware signature: 0x%04x\n",
2384 __func__, signature);
2385 }
2386
2387 dev_info(dev, "Firmware revision %i.%i (signature 0x%04x)\n",
2388 le16_to_cpu(priv->fw_data->major_version),
2389 priv->fw_data->minor_version, signature);
2390
2391exit:
2392 release_firmware(fw);
2393 return ret;
2394}
2395
2396static int rtl8723au_load_firmware(struct rtl8xxxu_priv *priv)
2397{
2398 char *fw_name;
2399 int ret;
2400
2401 switch (priv->chip_cut) {
2402 case 0:
2403 fw_name = "rtlwifi/rtl8723aufw_A.bin";
2404 break;
2405 case 1:
2406 if (priv->enable_bluetooth)
2407 fw_name = "rtlwifi/rtl8723aufw_B.bin";
2408 else
2409 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
2410
2411 break;
2412 default:
2413 return -EINVAL;
2414 }
2415
2416 ret = rtl8xxxu_load_firmware(priv, fw_name);
2417 return ret;
2418}
2419
Jes Sorensen35a741f2016-02-29 17:04:10 -05002420static int rtl8723bu_load_firmware(struct rtl8xxxu_priv *priv)
2421{
2422 char *fw_name;
2423 int ret;
2424
2425 if (priv->enable_bluetooth)
2426 fw_name = "rtlwifi/rtl8723bu_bt.bin";
2427 else
2428 fw_name = "rtlwifi/rtl8723bu_nic.bin";
2429
2430 ret = rtl8xxxu_load_firmware(priv, fw_name);
2431 return ret;
2432}
2433
Kalle Valoc0963772015-10-25 18:24:38 +02002434#ifdef CONFIG_RTL8XXXU_UNTESTED
2435
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002436static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
2437{
2438 char *fw_name;
2439 int ret;
2440
2441 if (!priv->vendor_umc)
2442 fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
2443 else if (priv->chip_cut || priv->rtlchip == 0x8192c)
2444 fw_name = "rtlwifi/rtl8192cufw_B.bin";
2445 else
2446 fw_name = "rtlwifi/rtl8192cufw_A.bin";
2447
2448 ret = rtl8xxxu_load_firmware(priv, fw_name);
2449
2450 return ret;
2451}
2452
Kalle Valoc0963772015-10-25 18:24:38 +02002453#endif
2454
Jes Sorensen3307d842016-02-29 17:03:59 -05002455static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
2456{
2457 char *fw_name;
2458 int ret;
2459
Jes Sorensen0e5d4352016-02-29 17:04:00 -05002460 fw_name = "rtlwifi/rtl8192eu_nic.bin";
Jes Sorensen3307d842016-02-29 17:03:59 -05002461
2462 ret = rtl8xxxu_load_firmware(priv, fw_name);
2463
2464 return ret;
2465}
2466
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002467static void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv)
2468{
2469 u16 val16;
2470 int i = 100;
2471
2472 /* Inform 8051 to perform reset */
2473 rtl8xxxu_write8(priv, REG_HMTFR + 3, 0x20);
2474
2475 for (i = 100; i > 0; i--) {
2476 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2477
2478 if (!(val16 & SYS_FUNC_CPU_ENABLE)) {
2479 dev_dbg(&priv->udev->dev,
2480 "%s: Firmware self reset success!\n", __func__);
2481 break;
2482 }
2483 udelay(50);
2484 }
2485
2486 if (!i) {
2487 /* Force firmware reset */
2488 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
2489 val16 &= ~SYS_FUNC_CPU_ENABLE;
2490 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
2491 }
2492}
2493
2494static int
2495rtl8xxxu_init_mac(struct rtl8xxxu_priv *priv, struct rtl8xxxu_reg8val *array)
2496{
2497 int i, ret;
2498 u16 reg;
2499 u8 val;
2500
2501 for (i = 0; ; i++) {
2502 reg = array[i].reg;
2503 val = array[i].val;
2504
2505 if (reg == 0xffff && val == 0xff)
2506 break;
2507
2508 ret = rtl8xxxu_write8(priv, reg, val);
2509 if (ret != 1) {
2510 dev_warn(&priv->udev->dev,
2511 "Failed to initialize MAC\n");
2512 return -EAGAIN;
2513 }
2514 }
2515
2516 rtl8xxxu_write8(priv, REG_MAX_AGGR_NUM, 0x0a);
2517
2518 return 0;
2519}
2520
2521static int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
2522 struct rtl8xxxu_reg32val *array)
2523{
2524 int i, ret;
2525 u16 reg;
2526 u32 val;
2527
2528 for (i = 0; ; i++) {
2529 reg = array[i].reg;
2530 val = array[i].val;
2531
2532 if (reg == 0xffff && val == 0xffffffff)
2533 break;
2534
2535 ret = rtl8xxxu_write32(priv, reg, val);
2536 if (ret != sizeof(val)) {
2537 dev_warn(&priv->udev->dev,
2538 "Failed to initialize PHY\n");
2539 return -EAGAIN;
2540 }
2541 udelay(1);
2542 }
2543
2544 return 0;
2545}
2546
2547/*
2548 * Most of this is black magic retrieved from the old rtl8723au driver
2549 */
2550static int rtl8xxxu_init_phy_bb(struct rtl8xxxu_priv *priv)
2551{
2552 u8 val8, ldoa15, ldov12d, lpldo, ldohci12;
2553 u32 val32;
2554
2555 /*
2556 * Todo: The vendor driver maintains a table of PHY register
2557 * addresses, which is initialized here. Do we need this?
2558 */
2559
2560 val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
2561 udelay(2);
2562 val8 |= AFE_PLL_320_ENABLE;
2563 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
2564 udelay(2);
2565
2566 rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL + 1, 0xff);
2567 udelay(2);
2568
2569 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
2570 val8 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB;
2571 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
2572
2573 /* AFE_XTAL_RF_GATE (bit 14) if addressing as 32 bit register */
2574 val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
2575 val32 &= ~AFE_XTAL_RF_GATE;
2576 if (priv->has_bluetooth)
2577 val32 &= ~AFE_XTAL_BT_GATE;
2578 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
2579
2580 /* 6. 0x1f[7:0] = 0x07 */
2581 val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
2582 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
2583
2584 if (priv->hi_pa)
2585 rtl8xxxu_init_phy_regs(priv, rtl8188ru_phy_1t_highpa_table);
2586 else if (priv->tx_paths == 2)
2587 rtl8xxxu_init_phy_regs(priv, rtl8192cu_phy_2t_init_table);
2588 else
2589 rtl8xxxu_init_phy_regs(priv, rtl8723a_phy_1t_init_table);
2590
2591
2592 if (priv->rtlchip == 0x8188c && priv->hi_pa &&
2593 priv->vendor_umc && priv->chip_cut == 1)
2594 rtl8xxxu_write8(priv, REG_OFDM0_AGC_PARM1 + 2, 0x50);
2595
2596 if (priv->tx_paths == 1 && priv->rx_paths == 2) {
2597 /*
2598 * For 1T2R boards, patch the registers.
2599 *
2600 * It looks like 8191/2 1T2R boards use path B for TX
2601 */
2602 val32 = rtl8xxxu_read32(priv, REG_FPGA0_TX_INFO);
2603 val32 &= ~(BIT(0) | BIT(1));
2604 val32 |= BIT(1);
2605 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, val32);
2606
2607 val32 = rtl8xxxu_read32(priv, REG_FPGA1_TX_INFO);
2608 val32 &= ~0x300033;
2609 val32 |= 0x200022;
2610 rtl8xxxu_write32(priv, REG_FPGA1_TX_INFO, val32);
2611
2612 val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
2613 val32 &= 0xff000000;
2614 val32 |= 0x45000000;
2615 rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
2616
2617 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
2618 val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK);
2619 val32 |= (OFDM_RF_PATH_RX_A | OFDM_RF_PATH_RX_B |
2620 OFDM_RF_PATH_TX_B);
2621 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
2622
2623 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGC_PARM1);
2624 val32 &= ~(BIT(4) | BIT(5));
2625 val32 |= BIT(4);
2626 rtl8xxxu_write32(priv, REG_OFDM0_AGC_PARM1, val32);
2627
2628 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_RFON);
2629 val32 &= ~(BIT(27) | BIT(26));
2630 val32 |= BIT(27);
2631 rtl8xxxu_write32(priv, REG_TX_CCK_RFON, val32);
2632
2633 val32 = rtl8xxxu_read32(priv, REG_TX_CCK_BBON);
2634 val32 &= ~(BIT(27) | BIT(26));
2635 val32 |= BIT(27);
2636 rtl8xxxu_write32(priv, REG_TX_CCK_BBON, val32);
2637
2638 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_RFON);
2639 val32 &= ~(BIT(27) | BIT(26));
2640 val32 |= BIT(27);
2641 rtl8xxxu_write32(priv, REG_TX_OFDM_RFON, val32);
2642
2643 val32 = rtl8xxxu_read32(priv, REG_TX_OFDM_BBON);
2644 val32 &= ~(BIT(27) | BIT(26));
2645 val32 |= BIT(27);
2646 rtl8xxxu_write32(priv, REG_TX_OFDM_BBON, val32);
2647
2648 val32 = rtl8xxxu_read32(priv, REG_TX_TO_TX);
2649 val32 &= ~(BIT(27) | BIT(26));
2650 val32 |= BIT(27);
2651 rtl8xxxu_write32(priv, REG_TX_TO_TX, val32);
2652 }
2653
2654 if (priv->hi_pa)
2655 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_highpa_table);
2656 else
2657 rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_standard_table);
2658
Jes Sorensen35a741f2016-02-29 17:04:10 -05002659 if ((priv->rtlchip == 0x8723a || priv->rtlchip == 0x8723b) &&
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002660 priv->efuse_wifi.efuse8723.version >= 0x01) {
2661 val32 = rtl8xxxu_read32(priv, REG_MAC_PHY_CTRL);
2662
2663 val8 = priv->efuse_wifi.efuse8723.xtal_k & 0x3f;
2664 val32 &= 0xff000fff;
2665 val32 |= ((val8 | (val8 << 6)) << 12);
2666
2667 rtl8xxxu_write32(priv, REG_MAC_PHY_CTRL, val32);
2668 }
2669
2670 ldoa15 = LDOA15_ENABLE | LDOA15_OBUF;
2671 ldov12d = LDOV12D_ENABLE | BIT(2) | (2 << LDOV12D_VADJ_SHIFT);
2672 ldohci12 = 0x57;
2673 lpldo = 1;
2674 val32 = (lpldo << 24) | (ldohci12 << 16) | (ldov12d << 8) | ldoa15;
2675
2676 rtl8xxxu_write32(priv, REG_LDOA15_CTRL, val32);
2677
2678 return 0;
2679}
2680
2681static int rtl8xxxu_init_rf_regs(struct rtl8xxxu_priv *priv,
2682 struct rtl8xxxu_rfregval *array,
2683 enum rtl8xxxu_rfpath path)
2684{
2685 int i, ret;
2686 u8 reg;
2687 u32 val;
2688
2689 for (i = 0; ; i++) {
2690 reg = array[i].reg;
2691 val = array[i].val;
2692
2693 if (reg == 0xff && val == 0xffffffff)
2694 break;
2695
2696 switch (reg) {
2697 case 0xfe:
2698 msleep(50);
2699 continue;
2700 case 0xfd:
2701 mdelay(5);
2702 continue;
2703 case 0xfc:
2704 mdelay(1);
2705 continue;
2706 case 0xfb:
2707 udelay(50);
2708 continue;
2709 case 0xfa:
2710 udelay(5);
2711 continue;
2712 case 0xf9:
2713 udelay(1);
2714 continue;
2715 }
2716
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002717 ret = rtl8xxxu_write_rfreg(priv, path, reg, val);
2718 if (ret) {
2719 dev_warn(&priv->udev->dev,
2720 "Failed to initialize RF\n");
2721 return -EAGAIN;
2722 }
2723 udelay(1);
2724 }
2725
2726 return 0;
2727}
2728
2729static int rtl8xxxu_init_phy_rf(struct rtl8xxxu_priv *priv,
2730 struct rtl8xxxu_rfregval *table,
2731 enum rtl8xxxu_rfpath path)
2732{
2733 u32 val32;
2734 u16 val16, rfsi_rfenv;
2735 u16 reg_sw_ctrl, reg_int_oe, reg_hssi_parm2;
2736
2737 switch (path) {
2738 case RF_A:
2739 reg_sw_ctrl = REG_FPGA0_XA_RF_SW_CTRL;
2740 reg_int_oe = REG_FPGA0_XA_RF_INT_OE;
2741 reg_hssi_parm2 = REG_FPGA0_XA_HSSI_PARM2;
2742 break;
2743 case RF_B:
2744 reg_sw_ctrl = REG_FPGA0_XB_RF_SW_CTRL;
2745 reg_int_oe = REG_FPGA0_XB_RF_INT_OE;
2746 reg_hssi_parm2 = REG_FPGA0_XB_HSSI_PARM2;
2747 break;
2748 default:
2749 dev_err(&priv->udev->dev, "%s:Unsupported RF path %c\n",
2750 __func__, path + 'A');
2751 return -EINVAL;
2752 }
2753 /* For path B, use XB */
2754 rfsi_rfenv = rtl8xxxu_read16(priv, reg_sw_ctrl);
2755 rfsi_rfenv &= FPGA0_RF_RFENV;
2756
2757 /*
2758 * These two we might be able to optimize into one
2759 */
2760 val32 = rtl8xxxu_read32(priv, reg_int_oe);
2761 val32 |= BIT(20); /* 0x10 << 16 */
2762 rtl8xxxu_write32(priv, reg_int_oe, val32);
2763 udelay(1);
2764
2765 val32 = rtl8xxxu_read32(priv, reg_int_oe);
2766 val32 |= BIT(4);
2767 rtl8xxxu_write32(priv, reg_int_oe, val32);
2768 udelay(1);
2769
2770 /*
2771 * These two we might be able to optimize into one
2772 */
2773 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
2774 val32 &= ~FPGA0_HSSI_3WIRE_ADDR_LEN;
2775 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
2776 udelay(1);
2777
2778 val32 = rtl8xxxu_read32(priv, reg_hssi_parm2);
2779 val32 &= ~FPGA0_HSSI_3WIRE_DATA_LEN;
2780 rtl8xxxu_write32(priv, reg_hssi_parm2, val32);
2781 udelay(1);
2782
2783 rtl8xxxu_init_rf_regs(priv, table, path);
2784
2785 /* For path B, use XB */
2786 val16 = rtl8xxxu_read16(priv, reg_sw_ctrl);
2787 val16 &= ~FPGA0_RF_RFENV;
2788 val16 |= rfsi_rfenv;
2789 rtl8xxxu_write16(priv, reg_sw_ctrl, val16);
2790
2791 return 0;
2792}
2793
2794static int rtl8xxxu_llt_write(struct rtl8xxxu_priv *priv, u8 address, u8 data)
2795{
2796 int ret = -EBUSY;
2797 int count = 0;
2798 u32 value;
2799
2800 value = LLT_OP_WRITE | address << 8 | data;
2801
2802 rtl8xxxu_write32(priv, REG_LLT_INIT, value);
2803
2804 do {
2805 value = rtl8xxxu_read32(priv, REG_LLT_INIT);
2806 if ((value & LLT_OP_MASK) == LLT_OP_INACTIVE) {
2807 ret = 0;
2808 break;
2809 }
2810 } while (count++ < 20);
2811
2812 return ret;
2813}
2814
2815static int rtl8xxxu_init_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
2816{
2817 int ret;
2818 int i;
2819
2820 for (i = 0; i < last_tx_page; i++) {
2821 ret = rtl8xxxu_llt_write(priv, i, i + 1);
2822 if (ret)
2823 goto exit;
2824 }
2825
2826 ret = rtl8xxxu_llt_write(priv, last_tx_page, 0xff);
2827 if (ret)
2828 goto exit;
2829
2830 /* Mark remaining pages as a ring buffer */
2831 for (i = last_tx_page + 1; i < 0xff; i++) {
2832 ret = rtl8xxxu_llt_write(priv, i, (i + 1));
2833 if (ret)
2834 goto exit;
2835 }
2836
2837 /* Let last entry point to the start entry of ring buffer */
2838 ret = rtl8xxxu_llt_write(priv, 0xff, last_tx_page + 1);
2839 if (ret)
2840 goto exit;
2841
2842exit:
2843 return ret;
2844}
2845
Jes Sorensen74b99be2016-02-29 17:04:04 -05002846static int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv, u8 last_tx_page)
2847{
2848 u32 val32;
2849 int ret = 0;
2850 int i;
2851
2852 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
Jes Sorensen74b99be2016-02-29 17:04:04 -05002853 val32 |= AUTO_LLT_INIT_LLT;
2854 rtl8xxxu_write32(priv, REG_AUTO_LLT, val32);
2855
2856 for (i = 500; i; i--) {
2857 val32 = rtl8xxxu_read32(priv, REG_AUTO_LLT);
2858 if (!(val32 & AUTO_LLT_INIT_LLT))
2859 break;
2860 usleep_range(2, 4);
2861 }
2862
Jes Sorensen4de24812016-02-29 17:04:07 -05002863 if (!i) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05002864 ret = -EBUSY;
2865 dev_warn(&priv->udev->dev, "LLT table init failed\n");
2866 }
Jes Sorensen74b99be2016-02-29 17:04:04 -05002867
2868 return ret;
2869}
2870
Jes Sorensen26f1fad2015-10-14 20:44:51 -04002871static int rtl8xxxu_init_queue_priority(struct rtl8xxxu_priv *priv)
2872{
2873 u16 val16, hi, lo;
2874 u16 hiq, mgq, bkq, beq, viq, voq;
2875 int hip, mgp, bkp, bep, vip, vop;
2876 int ret = 0;
2877
2878 switch (priv->ep_tx_count) {
2879 case 1:
2880 if (priv->ep_tx_high_queue) {
2881 hi = TRXDMA_QUEUE_HIGH;
2882 } else if (priv->ep_tx_low_queue) {
2883 hi = TRXDMA_QUEUE_LOW;
2884 } else if (priv->ep_tx_normal_queue) {
2885 hi = TRXDMA_QUEUE_NORMAL;
2886 } else {
2887 hi = 0;
2888 ret = -EINVAL;
2889 }
2890
2891 hiq = hi;
2892 mgq = hi;
2893 bkq = hi;
2894 beq = hi;
2895 viq = hi;
2896 voq = hi;
2897
2898 hip = 0;
2899 mgp = 0;
2900 bkp = 0;
2901 bep = 0;
2902 vip = 0;
2903 vop = 0;
2904 break;
2905 case 2:
2906 if (priv->ep_tx_high_queue && priv->ep_tx_low_queue) {
2907 hi = TRXDMA_QUEUE_HIGH;
2908 lo = TRXDMA_QUEUE_LOW;
2909 } else if (priv->ep_tx_normal_queue && priv->ep_tx_low_queue) {
2910 hi = TRXDMA_QUEUE_NORMAL;
2911 lo = TRXDMA_QUEUE_LOW;
2912 } else if (priv->ep_tx_high_queue && priv->ep_tx_normal_queue) {
2913 hi = TRXDMA_QUEUE_HIGH;
2914 lo = TRXDMA_QUEUE_NORMAL;
2915 } else {
2916 ret = -EINVAL;
2917 hi = 0;
2918 lo = 0;
2919 }
2920
2921 hiq = hi;
2922 mgq = hi;
2923 bkq = lo;
2924 beq = lo;
2925 viq = hi;
2926 voq = hi;
2927
2928 hip = 0;
2929 mgp = 0;
2930 bkp = 1;
2931 bep = 1;
2932 vip = 0;
2933 vop = 0;
2934 break;
2935 case 3:
2936 beq = TRXDMA_QUEUE_LOW;
2937 bkq = TRXDMA_QUEUE_LOW;
2938 viq = TRXDMA_QUEUE_NORMAL;
2939 voq = TRXDMA_QUEUE_HIGH;
2940 mgq = TRXDMA_QUEUE_HIGH;
2941 hiq = TRXDMA_QUEUE_HIGH;
2942
2943 hip = hiq ^ 3;
2944 mgp = mgq ^ 3;
2945 bkp = bkq ^ 3;
2946 bep = beq ^ 3;
2947 vip = viq ^ 3;
2948 vop = viq ^ 3;
2949 break;
2950 default:
2951 ret = -EINVAL;
2952 }
2953
2954 /*
2955 * None of the vendor drivers are configuring the beacon
2956 * queue here .... why?
2957 */
2958 if (!ret) {
2959 val16 = rtl8xxxu_read16(priv, REG_TRXDMA_CTRL);
2960 val16 &= 0x7;
2961 val16 |= (voq << TRXDMA_CTRL_VOQ_SHIFT) |
2962 (viq << TRXDMA_CTRL_VIQ_SHIFT) |
2963 (beq << TRXDMA_CTRL_BEQ_SHIFT) |
2964 (bkq << TRXDMA_CTRL_BKQ_SHIFT) |
2965 (mgq << TRXDMA_CTRL_MGQ_SHIFT) |
2966 (hiq << TRXDMA_CTRL_HIQ_SHIFT);
2967 rtl8xxxu_write16(priv, REG_TRXDMA_CTRL, val16);
2968
2969 priv->pipe_out[TXDESC_QUEUE_VO] =
2970 usb_sndbulkpipe(priv->udev, priv->out_ep[vop]);
2971 priv->pipe_out[TXDESC_QUEUE_VI] =
2972 usb_sndbulkpipe(priv->udev, priv->out_ep[vip]);
2973 priv->pipe_out[TXDESC_QUEUE_BE] =
2974 usb_sndbulkpipe(priv->udev, priv->out_ep[bep]);
2975 priv->pipe_out[TXDESC_QUEUE_BK] =
2976 usb_sndbulkpipe(priv->udev, priv->out_ep[bkp]);
2977 priv->pipe_out[TXDESC_QUEUE_BEACON] =
2978 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
2979 priv->pipe_out[TXDESC_QUEUE_MGNT] =
2980 usb_sndbulkpipe(priv->udev, priv->out_ep[mgp]);
2981 priv->pipe_out[TXDESC_QUEUE_HIGH] =
2982 usb_sndbulkpipe(priv->udev, priv->out_ep[hip]);
2983 priv->pipe_out[TXDESC_QUEUE_CMD] =
2984 usb_sndbulkpipe(priv->udev, priv->out_ep[0]);
2985 }
2986
2987 return ret;
2988}
2989
2990static void rtl8xxxu_fill_iqk_matrix_a(struct rtl8xxxu_priv *priv,
2991 bool iqk_ok, int result[][8],
2992 int candidate, bool tx_only)
2993{
2994 u32 oldval, x, tx0_a, reg;
2995 int y, tx0_c;
2996 u32 val32;
2997
2998 if (!iqk_ok)
2999 return;
3000
3001 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3002 oldval = val32 >> 22;
3003
3004 x = result[candidate][0];
3005 if ((x & 0x00000200) != 0)
3006 x = x | 0xfffffc00;
3007 tx0_a = (x * oldval) >> 8;
3008
3009 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3010 val32 &= ~0x3ff;
3011 val32 |= tx0_a;
3012 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3013
3014 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3015 val32 &= ~BIT(31);
3016 if ((x * oldval >> 7) & 0x1)
3017 val32 |= BIT(31);
3018 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3019
3020 y = result[candidate][1];
3021 if ((y & 0x00000200) != 0)
3022 y = y | 0xfffffc00;
3023 tx0_c = (y * oldval) >> 8;
3024
3025 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XC_TX_AFE);
3026 val32 &= ~0xf0000000;
3027 val32 |= (((tx0_c & 0x3c0) >> 6) << 28);
3028 rtl8xxxu_write32(priv, REG_OFDM0_XC_TX_AFE, val32);
3029
3030 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE);
3031 val32 &= ~0x003f0000;
3032 val32 |= ((tx0_c & 0x3f) << 16);
3033 rtl8xxxu_write32(priv, REG_OFDM0_XA_TX_IQ_IMBALANCE, val32);
3034
3035 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3036 val32 &= ~BIT(29);
3037 if ((y * oldval >> 7) & 0x1)
3038 val32 |= BIT(29);
3039 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3040
3041 if (tx_only) {
3042 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3043 return;
3044 }
3045
3046 reg = result[candidate][2];
3047
3048 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3049 val32 &= ~0x3ff;
3050 val32 |= (reg & 0x3ff);
3051 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3052
3053 reg = result[candidate][3] & 0x3F;
3054
3055 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE);
3056 val32 &= ~0xfc00;
3057 val32 |= ((reg << 10) & 0xfc00);
3058 rtl8xxxu_write32(priv, REG_OFDM0_XA_RX_IQ_IMBALANCE, val32);
3059
3060 reg = (result[candidate][3] >> 6) & 0xF;
3061
3062 val32 = rtl8xxxu_read32(priv, REG_OFDM0_RX_IQ_EXT_ANTA);
3063 val32 &= ~0xf0000000;
3064 val32 |= (reg << 28);
3065 rtl8xxxu_write32(priv, REG_OFDM0_RX_IQ_EXT_ANTA, val32);
3066}
3067
3068static void rtl8xxxu_fill_iqk_matrix_b(struct rtl8xxxu_priv *priv,
3069 bool iqk_ok, int result[][8],
3070 int candidate, bool tx_only)
3071{
3072 u32 oldval, x, tx1_a, reg;
3073 int y, tx1_c;
3074 u32 val32;
3075
3076 if (!iqk_ok)
3077 return;
3078
3079 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3080 oldval = val32 >> 22;
3081
3082 x = result[candidate][4];
3083 if ((x & 0x00000200) != 0)
3084 x = x | 0xfffffc00;
3085 tx1_a = (x * oldval) >> 8;
3086
3087 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3088 val32 &= ~0x3ff;
3089 val32 |= tx1_a;
3090 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3091
3092 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3093 val32 &= ~BIT(27);
3094 if ((x * oldval >> 7) & 0x1)
3095 val32 |= BIT(27);
3096 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3097
3098 y = result[candidate][5];
3099 if ((y & 0x00000200) != 0)
3100 y = y | 0xfffffc00;
3101 tx1_c = (y * oldval) >> 8;
3102
3103 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XD_TX_AFE);
3104 val32 &= ~0xf0000000;
3105 val32 |= (((tx1_c & 0x3c0) >> 6) << 28);
3106 rtl8xxxu_write32(priv, REG_OFDM0_XD_TX_AFE, val32);
3107
3108 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE);
3109 val32 &= ~0x003f0000;
3110 val32 |= ((tx1_c & 0x3f) << 16);
3111 rtl8xxxu_write32(priv, REG_OFDM0_XB_TX_IQ_IMBALANCE, val32);
3112
3113 val32 = rtl8xxxu_read32(priv, REG_OFDM0_ENERGY_CCA_THRES);
3114 val32 &= ~BIT(25);
3115 if ((y * oldval >> 7) & 0x1)
3116 val32 |= BIT(25);
3117 rtl8xxxu_write32(priv, REG_OFDM0_ENERGY_CCA_THRES, val32);
3118
3119 if (tx_only) {
3120 dev_dbg(&priv->udev->dev, "%s: only TX\n", __func__);
3121 return;
3122 }
3123
3124 reg = result[candidate][6];
3125
3126 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3127 val32 &= ~0x3ff;
3128 val32 |= (reg & 0x3ff);
3129 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3130
3131 reg = result[candidate][7] & 0x3f;
3132
3133 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE);
3134 val32 &= ~0xfc00;
3135 val32 |= ((reg << 10) & 0xfc00);
3136 rtl8xxxu_write32(priv, REG_OFDM0_XB_RX_IQ_IMBALANCE, val32);
3137
3138 reg = (result[candidate][7] >> 6) & 0xf;
3139
3140 val32 = rtl8xxxu_read32(priv, REG_OFDM0_AGCR_SSI_TABLE);
3141 val32 &= ~0x0000f000;
3142 val32 |= (reg << 12);
3143 rtl8xxxu_write32(priv, REG_OFDM0_AGCR_SSI_TABLE, val32);
3144}
3145
3146#define MAX_TOLERANCE 5
3147
3148static bool rtl8xxxu_simularity_compare(struct rtl8xxxu_priv *priv,
3149 int result[][8], int c1, int c2)
3150{
3151 u32 i, j, diff, simubitmap, bound = 0;
3152 int candidate[2] = {-1, -1}; /* for path A and path B */
3153 bool retval = true;
3154
3155 if (priv->tx_paths > 1)
3156 bound = 8;
3157 else
3158 bound = 4;
3159
3160 simubitmap = 0;
3161
3162 for (i = 0; i < bound; i++) {
3163 diff = (result[c1][i] > result[c2][i]) ?
3164 (result[c1][i] - result[c2][i]) :
3165 (result[c2][i] - result[c1][i]);
3166 if (diff > MAX_TOLERANCE) {
3167 if ((i == 2 || i == 6) && !simubitmap) {
3168 if (result[c1][i] + result[c1][i + 1] == 0)
3169 candidate[(i / 4)] = c2;
3170 else if (result[c2][i] + result[c2][i + 1] == 0)
3171 candidate[(i / 4)] = c1;
3172 else
3173 simubitmap = simubitmap | (1 << i);
3174 } else {
3175 simubitmap = simubitmap | (1 << i);
3176 }
3177 }
3178 }
3179
3180 if (simubitmap == 0) {
3181 for (i = 0; i < (bound / 4); i++) {
3182 if (candidate[i] >= 0) {
3183 for (j = i * 4; j < (i + 1) * 4 - 2; j++)
3184 result[3][j] = result[candidate[i]][j];
3185 retval = false;
3186 }
3187 }
3188 return retval;
3189 } else if (!(simubitmap & 0x0f)) {
3190 /* path A OK */
3191 for (i = 0; i < 4; i++)
3192 result[3][i] = result[c1][i];
3193 } else if (!(simubitmap & 0xf0) && priv->tx_paths > 1) {
3194 /* path B OK */
3195 for (i = 4; i < 8; i++)
3196 result[3][i] = result[c1][i];
3197 }
3198
3199 return false;
3200}
3201
3202static void
3203rtl8xxxu_save_mac_regs(struct rtl8xxxu_priv *priv, const u32 *reg, u32 *backup)
3204{
3205 int i;
3206
3207 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3208 backup[i] = rtl8xxxu_read8(priv, reg[i]);
3209
3210 backup[i] = rtl8xxxu_read32(priv, reg[i]);
3211}
3212
3213static void rtl8xxxu_restore_mac_regs(struct rtl8xxxu_priv *priv,
3214 const u32 *reg, u32 *backup)
3215{
3216 int i;
3217
3218 for (i = 0; i < (RTL8XXXU_MAC_REGS - 1); i++)
3219 rtl8xxxu_write8(priv, reg[i], backup[i]);
3220
3221 rtl8xxxu_write32(priv, reg[i], backup[i]);
3222}
3223
3224static void rtl8xxxu_save_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3225 u32 *backup, int count)
3226{
3227 int i;
3228
3229 for (i = 0; i < count; i++)
3230 backup[i] = rtl8xxxu_read32(priv, regs[i]);
3231}
3232
3233static void rtl8xxxu_restore_regs(struct rtl8xxxu_priv *priv, const u32 *regs,
3234 u32 *backup, int count)
3235{
3236 int i;
3237
3238 for (i = 0; i < count; i++)
3239 rtl8xxxu_write32(priv, regs[i], backup[i]);
3240}
3241
3242
3243static void rtl8xxxu_path_adda_on(struct rtl8xxxu_priv *priv, const u32 *regs,
3244 bool path_a_on)
3245{
3246 u32 path_on;
3247 int i;
3248
3249 path_on = path_a_on ? 0x04db25a4 : 0x0b1b25a4;
3250 if (priv->tx_paths == 1) {
3251 path_on = 0x0bdb25a0;
3252 rtl8xxxu_write32(priv, regs[0], 0x0b1b25a0);
3253 } else {
3254 rtl8xxxu_write32(priv, regs[0], path_on);
3255 }
3256
3257 for (i = 1 ; i < RTL8XXXU_ADDA_REGS ; i++)
3258 rtl8xxxu_write32(priv, regs[i], path_on);
3259}
3260
3261static void rtl8xxxu_mac_calibration(struct rtl8xxxu_priv *priv,
3262 const u32 *regs, u32 *backup)
3263{
3264 int i = 0;
3265
3266 rtl8xxxu_write8(priv, regs[i], 0x3f);
3267
3268 for (i = 1 ; i < (RTL8XXXU_MAC_REGS - 1); i++)
3269 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(3)));
3270
3271 rtl8xxxu_write8(priv, regs[i], (u8)(backup[i] & ~BIT(5)));
3272}
3273
3274static int rtl8xxxu_iqk_path_a(struct rtl8xxxu_priv *priv)
3275{
3276 u32 reg_eac, reg_e94, reg_e9c, reg_ea4, val32;
3277 int result = 0;
3278
3279 /* path-A IQK setting */
3280 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x10008c1f);
3281 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x10008c1f);
3282 rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0x82140102);
3283
3284 val32 = (priv->rf_paths > 1) ? 0x28160202 :
3285 /*IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202: */
3286 0x28160502;
3287 rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, val32);
3288
3289 /* path-B IQK setting */
3290 if (priv->rf_paths > 1) {
3291 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0x10008c22);
3292 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0x10008c22);
3293 rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0x82140102);
3294 rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0x28160202);
3295 }
3296
3297 /* LO calibration setting */
3298 rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0x001028d1);
3299
3300 /* One shot, path A LOK & IQK */
3301 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf9000000);
3302 rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0xf8000000);
3303
3304 mdelay(1);
3305
3306 /* Check failed */
3307 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
3308 reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
3309 reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
3310 reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
3311
3312 if (!(reg_eac & BIT(28)) &&
3313 ((reg_e94 & 0x03ff0000) != 0x01420000) &&
3314 ((reg_e9c & 0x03ff0000) != 0x00420000))
3315 result |= 0x01;
3316 else /* If TX not OK, ignore RX */
3317 goto out;
3318
3319 /* If TX is OK, check whether RX is OK */
3320 if (!(reg_eac & BIT(27)) &&
3321 ((reg_ea4 & 0x03ff0000) != 0x01320000) &&
3322 ((reg_eac & 0x03ff0000) != 0x00360000))
3323 result |= 0x02;
3324 else
3325 dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n",
3326 __func__);
3327out:
3328 return result;
3329}
3330
3331static int rtl8xxxu_iqk_path_b(struct rtl8xxxu_priv *priv)
3332{
3333 u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc;
3334 int result = 0;
3335
3336 /* One shot, path B LOK & IQK */
3337 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000002);
3338 rtl8xxxu_write32(priv, REG_IQK_AGC_CONT, 0x00000000);
3339
3340 mdelay(1);
3341
3342 /* Check failed */
3343 reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
3344 reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3345 reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3346 reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
3347 reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
3348
3349 if (!(reg_eac & BIT(31)) &&
3350 ((reg_eb4 & 0x03ff0000) != 0x01420000) &&
3351 ((reg_ebc & 0x03ff0000) != 0x00420000))
3352 result |= 0x01;
3353 else
3354 goto out;
3355
3356 if (!(reg_eac & BIT(30)) &&
3357 (((reg_ec4 & 0x03ff0000) >> 16) != 0x132) &&
3358 (((reg_ecc & 0x03ff0000) >> 16) != 0x36))
3359 result |= 0x02;
3360 else
3361 dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n",
3362 __func__);
3363out:
3364 return result;
3365}
3366
3367static void rtl8xxxu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
3368 int result[][8], int t)
3369{
3370 struct device *dev = &priv->udev->dev;
3371 u32 i, val32;
3372 int path_a_ok, path_b_ok;
3373 int retry = 2;
3374 const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
3375 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
3376 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
3377 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
3378 REG_TX_OFDM_BBON, REG_TX_TO_RX,
3379 REG_TX_TO_TX, REG_RX_CCK,
3380 REG_RX_OFDM, REG_RX_WAIT_RIFS,
3381 REG_RX_TO_RX, REG_STANDBY,
3382 REG_SLEEP, REG_PMPD_ANAEN
3383 };
3384 const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
3385 REG_TXPAUSE, REG_BEACON_CTRL,
3386 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
3387 };
3388 const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
3389 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
3390 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
3391 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
3392 REG_FPGA0_XB_RF_INT_OE, REG_FPGA0_RF_MODE
3393 };
3394
3395 /*
3396 * Note: IQ calibration must be performed after loading
3397 * PHY_REG.txt , and radio_a, radio_b.txt
3398 */
3399
3400 if (t == 0) {
3401 /* Save ADDA parameters, turn Path A ADDA on */
3402 rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
3403 RTL8XXXU_ADDA_REGS);
3404 rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
3405 rtl8xxxu_save_regs(priv, iqk_bb_regs,
3406 priv->bb_backup, RTL8XXXU_BB_REGS);
3407 }
3408
3409 rtl8xxxu_path_adda_on(priv, adda_regs, true);
3410
3411 if (t == 0) {
3412 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
3413 if (val32 & FPGA0_HSSI_PARM1_PI)
3414 priv->pi_enabled = 1;
3415 }
3416
3417 if (!priv->pi_enabled) {
3418 /* Switch BB to PI mode to do IQ Calibration. */
3419 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0x01000100);
3420 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0x01000100);
3421 }
3422
3423 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
3424 val32 &= ~FPGA_RF_MODE_CCK;
3425 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
3426
3427 rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0x03a05600);
3428 rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0x000800e4);
3429 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0x22204000);
3430
3431 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
3432 val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
3433 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
3434
3435 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
3436 val32 &= ~BIT(10);
3437 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
3438 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
3439 val32 &= ~BIT(10);
3440 rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
3441
3442 if (priv->tx_paths > 1) {
3443 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
3444 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM, 0x00010000);
3445 }
3446
3447 /* MAC settings */
3448 rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
3449
3450 /* Page B init */
3451 rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0x00080000);
3452
3453 if (priv->tx_paths > 1)
3454 rtl8xxxu_write32(priv, REG_CONFIG_ANT_B, 0x00080000);
3455
3456 /* IQ calibration setting */
3457 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
3458 rtl8xxxu_write32(priv, REG_TX_IQK, 0x01007c00);
3459 rtl8xxxu_write32(priv, REG_RX_IQK, 0x01004800);
3460
3461 for (i = 0; i < retry; i++) {
3462 path_a_ok = rtl8xxxu_iqk_path_a(priv);
3463 if (path_a_ok == 0x03) {
3464 val32 = rtl8xxxu_read32(priv,
3465 REG_TX_POWER_BEFORE_IQK_A);
3466 result[t][0] = (val32 >> 16) & 0x3ff;
3467 val32 = rtl8xxxu_read32(priv,
3468 REG_TX_POWER_AFTER_IQK_A);
3469 result[t][1] = (val32 >> 16) & 0x3ff;
3470 val32 = rtl8xxxu_read32(priv,
3471 REG_RX_POWER_BEFORE_IQK_A_2);
3472 result[t][2] = (val32 >> 16) & 0x3ff;
3473 val32 = rtl8xxxu_read32(priv,
3474 REG_RX_POWER_AFTER_IQK_A_2);
3475 result[t][3] = (val32 >> 16) & 0x3ff;
3476 break;
3477 } else if (i == (retry - 1) && path_a_ok == 0x01) {
3478 /* TX IQK OK */
3479 dev_dbg(dev, "%s: Path A IQK Only Tx Success!!\n",
3480 __func__);
3481
3482 val32 = rtl8xxxu_read32(priv,
3483 REG_TX_POWER_BEFORE_IQK_A);
3484 result[t][0] = (val32 >> 16) & 0x3ff;
3485 val32 = rtl8xxxu_read32(priv,
3486 REG_TX_POWER_AFTER_IQK_A);
3487 result[t][1] = (val32 >> 16) & 0x3ff;
3488 }
3489 }
3490
3491 if (!path_a_ok)
3492 dev_dbg(dev, "%s: Path A IQK failed!\n", __func__);
3493
3494 if (priv->tx_paths > 1) {
3495 /*
3496 * Path A into standby
3497 */
3498 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x0);
3499 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00010000);
3500 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0x80800000);
3501
3502 /* Turn Path B ADDA on */
3503 rtl8xxxu_path_adda_on(priv, adda_regs, false);
3504
3505 for (i = 0; i < retry; i++) {
3506 path_b_ok = rtl8xxxu_iqk_path_b(priv);
3507 if (path_b_ok == 0x03) {
3508 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3509 result[t][4] = (val32 >> 16) & 0x3ff;
3510 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3511 result[t][5] = (val32 >> 16) & 0x3ff;
3512 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
3513 result[t][6] = (val32 >> 16) & 0x3ff;
3514 val32 = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
3515 result[t][7] = (val32 >> 16) & 0x3ff;
3516 break;
3517 } else if (i == (retry - 1) && path_b_ok == 0x01) {
3518 /* TX IQK OK */
3519 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
3520 result[t][4] = (val32 >> 16) & 0x3ff;
3521 val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
3522 result[t][5] = (val32 >> 16) & 0x3ff;
3523 }
3524 }
3525
3526 if (!path_b_ok)
3527 dev_dbg(dev, "%s: Path B IQK failed!\n", __func__);
3528 }
3529
3530 /* Back to BB mode, load original value */
3531 rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0);
3532
3533 if (t) {
3534 if (!priv->pi_enabled) {
3535 /*
3536 * Switch back BB to SI mode after finishing
3537 * IQ Calibration
3538 */
3539 val32 = 0x01000000;
3540 rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, val32);
3541 rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, val32);
3542 }
3543
3544 /* Reload ADDA power saving parameters */
3545 rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
3546 RTL8XXXU_ADDA_REGS);
3547
3548 /* Reload MAC parameters */
3549 rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
3550
3551 /* Reload BB parameters */
3552 rtl8xxxu_restore_regs(priv, iqk_bb_regs,
3553 priv->bb_backup, RTL8XXXU_BB_REGS);
3554
3555 /* Restore RX initial gain */
3556 rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0x00032ed3);
3557
3558 if (priv->tx_paths > 1) {
3559 rtl8xxxu_write32(priv, REG_FPGA0_XB_LSSI_PARM,
3560 0x00032ed3);
3561 }
3562
3563 /* Load 0xe30 IQC default value */
3564 rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0x01008c00);
3565 rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0x01008c00);
3566 }
3567}
3568
3569static void rtl8723a_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
3570{
3571 struct device *dev = &priv->udev->dev;
3572 int result[4][8]; /* last is final result */
3573 int i, candidate;
3574 bool path_a_ok, path_b_ok;
3575 u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
3576 u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
3577 s32 reg_tmp = 0;
3578 bool simu;
3579
3580 memset(result, 0, sizeof(result));
3581 candidate = -1;
3582
3583 path_a_ok = false;
3584 path_b_ok = false;
3585
3586 rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
3587
3588 for (i = 0; i < 3; i++) {
3589 rtl8xxxu_phy_iqcalibrate(priv, result, i);
3590
3591 if (i == 1) {
3592 simu = rtl8xxxu_simularity_compare(priv, result, 0, 1);
3593 if (simu) {
3594 candidate = 0;
3595 break;
3596 }
3597 }
3598
3599 if (i == 2) {
3600 simu = rtl8xxxu_simularity_compare(priv, result, 0, 2);
3601 if (simu) {
3602 candidate = 0;
3603 break;
3604 }
3605
3606 simu = rtl8xxxu_simularity_compare(priv, result, 1, 2);
3607 if (simu) {
3608 candidate = 1;
3609 } else {
3610 for (i = 0; i < 8; i++)
3611 reg_tmp += result[3][i];
3612
3613 if (reg_tmp)
3614 candidate = 3;
3615 else
3616 candidate = -1;
3617 }
3618 }
3619 }
3620
3621 for (i = 0; i < 4; i++) {
3622 reg_e94 = result[i][0];
3623 reg_e9c = result[i][1];
3624 reg_ea4 = result[i][2];
3625 reg_eac = result[i][3];
3626 reg_eb4 = result[i][4];
3627 reg_ebc = result[i][5];
3628 reg_ec4 = result[i][6];
3629 reg_ecc = result[i][7];
3630 }
3631
3632 if (candidate >= 0) {
3633 reg_e94 = result[candidate][0];
3634 priv->rege94 = reg_e94;
3635 reg_e9c = result[candidate][1];
3636 priv->rege9c = reg_e9c;
3637 reg_ea4 = result[candidate][2];
3638 reg_eac = result[candidate][3];
3639 reg_eb4 = result[candidate][4];
3640 priv->regeb4 = reg_eb4;
3641 reg_ebc = result[candidate][5];
3642 priv->regebc = reg_ebc;
3643 reg_ec4 = result[candidate][6];
3644 reg_ecc = result[candidate][7];
3645 dev_dbg(dev, "%s: candidate is %x\n", __func__, candidate);
3646 dev_dbg(dev,
3647 "%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x "
3648 "ecc=%x\n ", __func__, reg_e94, reg_e9c,
3649 reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
3650 path_a_ok = true;
3651 path_b_ok = true;
3652 } else {
3653 reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0x100;
3654 reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0x0;
3655 }
3656
3657 if (reg_e94 && candidate >= 0)
3658 rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
3659 candidate, (reg_ea4 == 0));
3660
3661 if (priv->tx_paths > 1 && reg_eb4)
3662 rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
3663 candidate, (reg_ec4 == 0));
3664
3665 rtl8xxxu_save_regs(priv, rtl8723au_iqk_phy_iq_bb_reg,
3666 priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
3667}
3668
3669static void rtl8723a_phy_lc_calibrate(struct rtl8xxxu_priv *priv)
3670{
3671 u32 val32;
3672 u32 rf_amode, rf_bmode = 0, lstf;
3673
3674 /* Check continuous TX and Packet TX */
3675 lstf = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
3676
3677 if (lstf & OFDM_LSTF_MASK) {
3678 /* Disable all continuous TX */
3679 val32 = lstf & ~OFDM_LSTF_MASK;
3680 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
3681
3682 /* Read original RF mode Path A */
3683 rf_amode = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_AC);
3684
3685 /* Set RF mode to standby Path A */
3686 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC,
3687 (rf_amode & 0x8ffff) | 0x10000);
3688
3689 /* Path-B */
3690 if (priv->tx_paths > 1) {
3691 rf_bmode = rtl8xxxu_read_rfreg(priv, RF_B,
3692 RF6052_REG_AC);
3693
3694 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
3695 (rf_bmode & 0x8ffff) | 0x10000);
3696 }
3697 } else {
3698 /* Deal with Packet TX case */
3699 /* block all queues */
3700 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
3701 }
3702
3703 /* Start LC calibration */
3704 val32 = rtl8xxxu_read_rfreg(priv, RF_A, RF6052_REG_MODE_AG);
3705 val32 |= 0x08000;
3706 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_MODE_AG, val32);
3707
3708 msleep(100);
3709
3710 /* Restore original parameters */
3711 if (lstf & OFDM_LSTF_MASK) {
3712 /* Path-A */
3713 rtl8xxxu_write32(priv, REG_OFDM1_LSTF, lstf);
3714 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, rf_amode);
3715
3716 /* Path-B */
3717 if (priv->tx_paths > 1)
3718 rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_AC,
3719 rf_bmode);
3720 } else /* Deal with Packet TX case */
3721 rtl8xxxu_write8(priv, REG_TXPAUSE, 0x00);
3722}
3723
3724static int rtl8xxxu_set_mac(struct rtl8xxxu_priv *priv)
3725{
3726 int i;
3727 u16 reg;
3728
3729 reg = REG_MACID;
3730
3731 for (i = 0; i < ETH_ALEN; i++)
3732 rtl8xxxu_write8(priv, reg + i, priv->mac_addr[i]);
3733
3734 return 0;
3735}
3736
3737static int rtl8xxxu_set_bssid(struct rtl8xxxu_priv *priv, const u8 *bssid)
3738{
3739 int i;
3740 u16 reg;
3741
3742 dev_dbg(&priv->udev->dev, "%s: (%pM)\n", __func__, bssid);
3743
3744 reg = REG_BSSID;
3745
3746 for (i = 0; i < ETH_ALEN; i++)
3747 rtl8xxxu_write8(priv, reg + i, bssid[i]);
3748
3749 return 0;
3750}
3751
3752static void
3753rtl8xxxu_set_ampdu_factor(struct rtl8xxxu_priv *priv, u8 ampdu_factor)
3754{
3755 u8 vals[4] = { 0x41, 0xa8, 0x72, 0xb9 };
3756 u8 max_agg = 0xf;
3757 int i;
3758
3759 ampdu_factor = 1 << (ampdu_factor + 2);
3760 if (ampdu_factor > max_agg)
3761 ampdu_factor = max_agg;
3762
3763 for (i = 0; i < 4; i++) {
3764 if ((vals[i] & 0xf0) > (ampdu_factor << 4))
3765 vals[i] = (vals[i] & 0x0f) | (ampdu_factor << 4);
3766
3767 if ((vals[i] & 0x0f) > ampdu_factor)
3768 vals[i] = (vals[i] & 0xf0) | ampdu_factor;
3769
3770 rtl8xxxu_write8(priv, REG_AGGLEN_LMT + i, vals[i]);
3771 }
3772}
3773
3774static void rtl8xxxu_set_ampdu_min_space(struct rtl8xxxu_priv *priv, u8 density)
3775{
3776 u8 val8;
3777
3778 val8 = rtl8xxxu_read8(priv, REG_AMPDU_MIN_SPACE);
3779 val8 &= 0xf8;
3780 val8 |= density;
3781 rtl8xxxu_write8(priv, REG_AMPDU_MIN_SPACE, val8);
3782}
3783
3784static int rtl8xxxu_active_to_emu(struct rtl8xxxu_priv *priv)
3785{
3786 u8 val8;
3787 int count, ret;
3788
3789 /* Start of rtl8723AU_card_enable_flow */
3790 /* Act to Cardemu sequence*/
3791 /* Turn off RF */
3792 rtl8xxxu_write8(priv, REG_RF_CTRL, 0);
3793
3794 /* 0x004E[7] = 0, switch DPDT_SEL_P output from register 0x0065[2] */
3795 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
3796 val8 &= ~LEDCFG2_DPDT_SELECT;
3797 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
3798
3799 /* 0x0005[1] = 1 turn off MAC by HW state machine*/
3800 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3801 val8 |= BIT(1);
3802 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3803
3804 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
3805 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3806 if ((val8 & BIT(1)) == 0)
3807 break;
3808 udelay(10);
3809 }
3810
3811 if (!count) {
3812 dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n",
3813 __func__);
3814 ret = -EBUSY;
3815 goto exit;
3816 }
3817
3818 /* 0x0000[5] = 1 analog Ips to digital, 1:isolation */
3819 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
3820 val8 |= SYS_ISO_ANALOG_IPS;
3821 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
3822
3823 /* 0x0020[0] = 0 disable LDOA12 MACRO block*/
3824 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
3825 val8 &= ~LDOA15_ENABLE;
3826 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
3827
3828exit:
3829 return ret;
3830}
3831
3832static int rtl8xxxu_active_to_lps(struct rtl8xxxu_priv *priv)
3833{
3834 u8 val8;
3835 u8 val32;
3836 int count, ret;
3837
3838 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
3839
3840 /*
3841 * Poll - wait for RX packet to complete
3842 */
3843 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
3844 val32 = rtl8xxxu_read32(priv, 0x5f8);
3845 if (!val32)
3846 break;
3847 udelay(10);
3848 }
3849
3850 if (!count) {
3851 dev_warn(&priv->udev->dev,
3852 "%s: RX poll timed out (0x05f8)\n", __func__);
3853 ret = -EBUSY;
3854 goto exit;
3855 }
3856
3857 /* Disable CCK and OFDM, clock gated */
3858 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
3859 val8 &= ~SYS_FUNC_BBRSTB;
3860 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
3861
3862 udelay(2);
3863
3864 /* Reset baseband */
3865 val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
3866 val8 &= ~SYS_FUNC_BB_GLB_RSTN;
3867 rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
3868
3869 /* Reset MAC TRX */
3870 val8 = rtl8xxxu_read8(priv, REG_CR);
3871 val8 = CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE;
3872 rtl8xxxu_write8(priv, REG_CR, val8);
3873
3874 /* Reset MAC TRX */
3875 val8 = rtl8xxxu_read8(priv, REG_CR + 1);
3876 val8 &= ~BIT(1); /* CR_SECURITY_ENABLE */
3877 rtl8xxxu_write8(priv, REG_CR + 1, val8);
3878
3879 /* Respond TX OK to scheduler */
3880 val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
3881 val8 |= DUAL_TSF_TX_OK;
3882 rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
3883
3884exit:
3885 return ret;
3886}
3887
Jes Sorensenc05a9db2016-02-29 17:04:03 -05003888static void rtl8723a_disabled_to_emu(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003889{
3890 u8 val8;
3891
3892 /* Clear suspend enable and power down enable*/
3893 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3894 val8 &= ~(BIT(3) | BIT(7));
3895 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3896
3897 /* 0x48[16] = 0 to disable GPIO9 as EXT WAKEUP*/
3898 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
3899 val8 &= ~BIT(0);
3900 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
3901
3902 /* 0x04[12:11] = 11 enable WL suspend*/
3903 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3904 val8 &= ~(BIT(3) | BIT(4));
3905 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3906}
3907
Jes Sorensenc05a9db2016-02-29 17:04:03 -05003908static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv)
3909{
3910 u8 val8;
3911
3912 /* Clear suspend enable and power down enable*/
3913 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3914 val8 &= ~(BIT(3) | BIT(4));
3915 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3916}
3917
3918static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv)
3919{
3920 u8 val8;
3921 u32 val32;
3922 int count, ret = 0;
3923
3924 /* disable HWPDN 0x04[15]=0*/
3925 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3926 val8 &= ~BIT(7);
3927 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3928
3929 /* disable SW LPS 0x04[10]= 0 */
3930 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3931 val8 &= ~BIT(2);
3932 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3933
3934 /* disable WL suspend*/
3935 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
3936 val8 &= ~(BIT(3) | BIT(4));
3937 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
3938
3939 /* wait till 0x04[17] = 1 power ready*/
3940 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
3941 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
3942 if (val32 & BIT(17))
3943 break;
3944
3945 udelay(10);
3946 }
3947
3948 if (!count) {
3949 ret = -EBUSY;
3950 goto exit;
3951 }
3952
3953 /* We should be able to optimize the following three entries into one */
3954
3955 /* release WLON reset 0x04[16]= 1*/
3956 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
3957 val8 |= BIT(0);
3958 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
3959
3960 /* set, then poll until 0 */
3961 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
3962 val32 |= APS_FSMCO_MAC_ENABLE;
3963 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
3964
3965 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
3966 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
3967 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
3968 ret = 0;
3969 break;
3970 }
3971 udelay(10);
3972 }
3973
3974 if (!count) {
3975 ret = -EBUSY;
3976 goto exit;
3977 }
3978
3979exit:
3980 return ret;
3981}
3982
3983static int rtl8723a_emu_to_active(struct rtl8xxxu_priv *priv)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04003984{
3985 u8 val8;
3986 u32 val32;
3987 int count, ret = 0;
3988
3989 /* 0x20[0] = 1 enable LDOA12 MACRO block for all interface*/
3990 val8 = rtl8xxxu_read8(priv, REG_LDOA15_CTRL);
3991 val8 |= LDOA15_ENABLE;
3992 rtl8xxxu_write8(priv, REG_LDOA15_CTRL, val8);
3993
3994 /* 0x67[0] = 0 to disable BT_GPS_SEL pins*/
3995 val8 = rtl8xxxu_read8(priv, 0x0067);
3996 val8 &= ~BIT(4);
3997 rtl8xxxu_write8(priv, 0x0067, val8);
3998
3999 mdelay(1);
4000
4001 /* 0x00[5] = 0 release analog Ips to digital, 1:isolation */
4002 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4003 val8 &= ~SYS_ISO_ANALOG_IPS;
4004 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4005
4006 /* disable SW LPS 0x04[10]= 0 */
4007 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4008 val8 &= ~BIT(2);
4009 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4010
4011 /* wait till 0x04[17] = 1 power ready*/
4012 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4013 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4014 if (val32 & BIT(17))
4015 break;
4016
4017 udelay(10);
4018 }
4019
4020 if (!count) {
4021 ret = -EBUSY;
4022 goto exit;
4023 }
4024
4025 /* We should be able to optimize the following three entries into one */
4026
4027 /* release WLON reset 0x04[16]= 1*/
4028 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
4029 val8 |= BIT(0);
4030 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
4031
4032 /* disable HWPDN 0x04[15]= 0*/
4033 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4034 val8 &= ~BIT(7);
4035 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4036
4037 /* disable WL suspend*/
4038 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4039 val8 &= ~(BIT(3) | BIT(4));
4040 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4041
4042 /* set, then poll until 0 */
4043 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4044 val32 |= APS_FSMCO_MAC_ENABLE;
4045 rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
4046
4047 for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
4048 val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
4049 if ((val32 & APS_FSMCO_MAC_ENABLE) == 0) {
4050 ret = 0;
4051 break;
4052 }
4053 udelay(10);
4054 }
4055
4056 if (!count) {
4057 ret = -EBUSY;
4058 goto exit;
4059 }
4060
4061 /* 0x4C[23] = 0x4E[7] = 1, switch DPDT_SEL_P output from WL BB */
4062 /*
4063 * Note: Vendor driver actually clears this bit, despite the
4064 * documentation claims it's being set!
4065 */
4066 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
4067 val8 |= LEDCFG2_DPDT_SELECT;
4068 val8 &= ~LEDCFG2_DPDT_SELECT;
4069 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
4070
4071exit:
4072 return ret;
4073}
4074
4075static int rtl8xxxu_emu_to_disabled(struct rtl8xxxu_priv *priv)
4076{
4077 u8 val8;
4078
4079 /* 0x0007[7:0] = 0x20 SOP option to disable BG/MB */
4080 rtl8xxxu_write8(priv, REG_APS_FSMCO + 3, 0x20);
4081
4082 /* 0x04[12:11] = 01 enable WL suspend */
4083 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4084 val8 &= ~BIT(4);
4085 val8 |= BIT(3);
4086 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4087
4088 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1);
4089 val8 |= BIT(7);
4090 rtl8xxxu_write8(priv, REG_APS_FSMCO + 1, val8);
4091
4092 /* 0x48[16] = 1 to enable GPIO9 as EXT wakeup */
4093 val8 = rtl8xxxu_read8(priv, REG_GPIO_INTM + 2);
4094 val8 |= BIT(0);
4095 rtl8xxxu_write8(priv, REG_GPIO_INTM + 2, val8);
4096
4097 return 0;
4098}
4099
4100static int rtl8723au_power_on(struct rtl8xxxu_priv *priv)
4101{
4102 u8 val8;
4103 u16 val16;
4104 u32 val32;
4105 int ret;
4106
4107 /*
4108 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
4109 */
4110 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
4111
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004112 rtl8723a_disabled_to_emu(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004113
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004114 ret = rtl8723a_emu_to_active(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004115 if (ret)
4116 goto exit;
4117
4118 /*
4119 * 0x0004[19] = 1, reset 8051
4120 */
4121 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2);
4122 val8 |= BIT(3);
4123 rtl8xxxu_write8(priv, REG_APS_FSMCO + 2, val8);
4124
4125 /*
4126 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4127 * Set CR bit10 to enable 32k calibration.
4128 */
4129 val16 = rtl8xxxu_read16(priv, REG_CR);
4130 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4131 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
4132 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
4133 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
4134 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
4135 rtl8xxxu_write16(priv, REG_CR, val16);
4136
4137 /* For EFuse PG */
4138 val32 = rtl8xxxu_read32(priv, REG_EFUSE_CTRL);
4139 val32 &= ~(BIT(28) | BIT(29) | BIT(30));
4140 val32 |= (0x06 << 28);
4141 rtl8xxxu_write32(priv, REG_EFUSE_CTRL, val32);
4142exit:
4143 return ret;
4144}
4145
Kalle Valoc0963772015-10-25 18:24:38 +02004146#ifdef CONFIG_RTL8XXXU_UNTESTED
4147
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004148static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
4149{
4150 u8 val8;
4151 u16 val16;
4152 u32 val32;
4153 int i;
4154
4155 for (i = 100; i; i--) {
4156 val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO);
4157 if (val8 & APS_FSMCO_PFM_ALDN)
4158 break;
4159 }
4160
4161 if (!i) {
4162 pr_info("%s: Poll failed\n", __func__);
4163 return -ENODEV;
4164 }
4165
4166 /*
4167 * RSV_CTRL 0x001C[7:0] = 0x00, unlock ISO/CLK/Power control register
4168 */
4169 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0);
4170 rtl8xxxu_write8(priv, REG_SPS0_CTRL, 0x2b);
4171 udelay(100);
4172
4173 val8 = rtl8xxxu_read8(priv, REG_LDOV12D_CTRL);
4174 if (!(val8 & LDOV12D_ENABLE)) {
4175 pr_info("%s: Enabling LDOV12D (%02x)\n", __func__, val8);
4176 val8 |= LDOV12D_ENABLE;
4177 rtl8xxxu_write8(priv, REG_LDOV12D_CTRL, val8);
4178
4179 udelay(100);
4180
4181 val8 = rtl8xxxu_read8(priv, REG_SYS_ISO_CTRL);
4182 val8 &= ~SYS_ISO_MD2PP;
4183 rtl8xxxu_write8(priv, REG_SYS_ISO_CTRL, val8);
4184 }
4185
4186 /*
4187 * Auto enable WLAN
4188 */
4189 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4190 val16 |= APS_FSMCO_MAC_ENABLE;
4191 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4192
4193 for (i = 1000; i; i--) {
4194 val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
4195 if (!(val16 & APS_FSMCO_MAC_ENABLE))
4196 break;
4197 }
4198 if (!i) {
4199 pr_info("%s: FSMCO_MAC_ENABLE poll failed\n", __func__);
4200 return -EBUSY;
4201 }
4202
4203 /*
4204 * Enable radio, GPIO, LED
4205 */
4206 val16 = APS_FSMCO_HW_SUSPEND | APS_FSMCO_ENABLE_POWERDOWN |
4207 APS_FSMCO_PFM_ALDN;
4208 rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
4209
4210 /*
4211 * Release RF digital isolation
4212 */
4213 val16 = rtl8xxxu_read16(priv, REG_SYS_ISO_CTRL);
4214 val16 &= ~SYS_ISO_DIOR;
4215 rtl8xxxu_write16(priv, REG_SYS_ISO_CTRL, val16);
4216
4217 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
4218 val8 &= ~APSD_CTRL_OFF;
4219 rtl8xxxu_write8(priv, REG_APSD_CTRL, val8);
4220 for (i = 200; i; i--) {
4221 val8 = rtl8xxxu_read8(priv, REG_APSD_CTRL);
4222 if (!(val8 & APSD_CTRL_OFF_STATUS))
4223 break;
4224 }
4225
4226 if (!i) {
4227 pr_info("%s: APSD_CTRL poll failed\n", __func__);
4228 return -EBUSY;
4229 }
4230
4231 /*
4232 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4233 */
4234 val16 = rtl8xxxu_read16(priv, REG_CR);
4235 val16 |= CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4236 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE | CR_PROTOCOL_ENABLE |
4237 CR_SCHEDULE_ENABLE | CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE;
4238 rtl8xxxu_write16(priv, REG_CR, val16);
4239
4240 /*
4241 * Workaround for 8188RU LNA power leakage problem.
4242 */
4243 if (priv->rtlchip == 0x8188c && priv->hi_pa) {
4244 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
4245 val32 &= ~BIT(1);
4246 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
4247 }
4248 return 0;
4249}
4250
Kalle Valoc0963772015-10-25 18:24:38 +02004251#endif
4252
Jes Sorensenc05a9db2016-02-29 17:04:03 -05004253static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv)
4254{
4255 u16 val16;
4256 u32 val32;
4257 int ret;
4258
4259 ret = 0;
4260
4261 val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
4262 if (val32 & SYS_CFG_SPS_LDO_SEL) {
4263 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0xc3);
4264 } else {
4265 /*
4266 * Raise 1.2V voltage
4267 */
4268 val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL);
4269 val32 &= 0xff0fffff;
4270 val32 |= 0x00500000;
4271 rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32);
4272 rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0x83);
4273 }
4274
4275 rtl8192e_disabled_to_emu(priv);
4276
4277 ret = rtl8192e_emu_to_active(priv);
4278 if (ret)
4279 goto exit;
4280
4281 rtl8xxxu_write16(priv, REG_CR, 0x0000);
4282
4283 /*
4284 * Enable MAC DMA/WMAC/SCHEDULE/SEC block
4285 * Set CR bit10 to enable 32k calibration.
4286 */
4287 val16 = rtl8xxxu_read16(priv, REG_CR);
4288 val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
4289 CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
4290 CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
4291 CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
4292 CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
4293 rtl8xxxu_write16(priv, REG_CR, val16);
4294
4295exit:
4296 return ret;
4297}
4298
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004299static void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv)
4300{
4301 u8 val8;
4302 u16 val16;
4303 u32 val32;
4304
4305 /*
4306 * Workaround for 8188RU LNA power leakage problem.
4307 */
4308 if (priv->rtlchip == 0x8188c && priv->hi_pa) {
4309 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XCD_RF_PARM);
4310 val32 |= BIT(1);
4311 rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_PARM, val32);
4312 }
4313
4314 rtl8xxxu_active_to_lps(priv);
4315
4316 /* Turn off RF */
4317 rtl8xxxu_write8(priv, REG_RF_CTRL, 0x00);
4318
4319 /* Reset Firmware if running in RAM */
4320 if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
4321 rtl8xxxu_firmware_self_reset(priv);
4322
4323 /* Reset MCU */
4324 val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
4325 val16 &= ~SYS_FUNC_CPU_ENABLE;
4326 rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
4327
4328 /* Reset MCU ready status */
4329 rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0x00);
4330
4331 rtl8xxxu_active_to_emu(priv);
4332 rtl8xxxu_emu_to_disabled(priv);
4333
4334 /* Reset MCU IO Wrapper */
4335 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
4336 val8 &= ~BIT(0);
4337 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
4338
4339 val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1);
4340 val8 |= BIT(0);
4341 rtl8xxxu_write8(priv, REG_RSV_CTRL + 1, val8);
4342
4343 /* RSV_CTRL 0x1C[7:0] = 0x0e lock ISO/CLK/Power control register */
4344 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e);
4345}
4346
4347static void rtl8xxxu_init_bt(struct rtl8xxxu_priv *priv)
4348{
4349 if (!priv->has_bluetooth)
4350 return;
4351}
4352
4353static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
4354{
4355 struct rtl8xxxu_priv *priv = hw->priv;
4356 struct device *dev = &priv->udev->dev;
4357 struct rtl8xxxu_rfregval *rftable;
4358 bool macpower;
4359 int ret;
4360 u8 val8;
4361 u16 val16;
4362 u32 val32;
4363
4364 /* Check if MAC is already powered on */
4365 val8 = rtl8xxxu_read8(priv, REG_CR);
4366
4367 /*
4368 * Fix 92DU-VC S3 hang with the reason is that secondary mac is not
4369 * initialized. First MAC returns 0xea, second MAC returns 0x00
4370 */
4371 if (val8 == 0xea)
4372 macpower = false;
4373 else
4374 macpower = true;
4375
4376 ret = priv->fops->power_on(priv);
4377 if (ret < 0) {
4378 dev_warn(dev, "%s: Failed power on\n", __func__);
4379 goto exit;
4380 }
4381
4382 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
4383 if (!macpower) {
Jes Sorensen07bb46b2016-02-29 17:04:05 -05004384 if (priv->ep_tx_normal_queue)
4385 val8 = TX_PAGE_NUM_NORM_PQ;
4386 else
4387 val8 = 0;
4388
4389 rtl8xxxu_write8(priv, REG_RQPN_NPQ, val8);
4390
4391 val32 = (TX_PAGE_NUM_PUBQ << RQPN_NORM_PQ_SHIFT) | RQPN_LOAD;
4392
4393 if (priv->ep_tx_high_queue)
4394 val32 |= (TX_PAGE_NUM_HI_PQ << RQPN_HI_PQ_SHIFT);
4395 if (priv->ep_tx_low_queue)
4396 val32 |= (TX_PAGE_NUM_LO_PQ << RQPN_LO_PQ_SHIFT);
4397
4398 rtl8xxxu_write32(priv, REG_RQPN, val32);
4399
4400 /*
4401 * Set TX buffer boundary
4402 */
4403 val8 = TX_TOTAL_PAGE_NUM + 1;
4404 rtl8xxxu_write8(priv, REG_TXPKTBUF_BCNQ_BDNY, val8);
4405 rtl8xxxu_write8(priv, REG_TXPKTBUF_MGQ_BDNY, val8);
4406 rtl8xxxu_write8(priv, REG_TXPKTBUF_WMAC_LBK_BF_HD, val8);
4407 rtl8xxxu_write8(priv, REG_TRXFF_BNDY, val8);
4408 rtl8xxxu_write8(priv, REG_TDECTRL + 1, val8);
4409 }
4410
Jes Sorensena47b9d42016-02-29 17:04:06 -05004411 ret = rtl8xxxu_download_firmware(priv);
4412 dev_dbg(dev, "%s: download_fiwmare %i\n", __func__, ret);
4413 if (ret)
4414 goto exit;
4415 ret = rtl8xxxu_start_firmware(priv);
4416 dev_dbg(dev, "%s: start_fiwmare %i\n", __func__, ret);
4417 if (ret)
4418 goto exit;
4419
Jes Sorensen07bb46b2016-02-29 17:04:05 -05004420 ret = rtl8xxxu_init_queue_priority(priv);
4421 dev_dbg(dev, "%s: init_queue_priority %i\n", __func__, ret);
4422 if (ret)
4423 goto exit;
4424
4425 dev_dbg(dev, "%s: macpower %i\n", __func__, macpower);
4426 if (!macpower) {
Jes Sorensen74b99be2016-02-29 17:04:04 -05004427 ret = priv->fops->llt_init(priv, TX_TOTAL_PAGE_NUM);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004428 if (ret) {
4429 dev_warn(dev, "%s: LLT table init failed\n", __func__);
4430 goto exit;
4431 }
4432 }
4433
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05004434 if (priv->rtlchip == 0x8192e) {
4435 val32 = rtl8xxxu_read32(priv, REG_TXDMA_OFFSET_CHK);
4436 val32 |= TXDMA_OFFSET_DROP_DATA_EN;
4437 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, val32);
Jes Sorensen99ad16c2016-02-29 17:04:09 -05004438
4439 rtl8xxxu_write32(priv, REG_HIMR0, 0x00);
4440 rtl8xxxu_write32(priv, REG_HIMR1, 0x00);
Jes Sorensenb63d0aa2016-02-29 17:04:08 -05004441 }
4442
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004443 ret = rtl8xxxu_init_mac(priv, rtl8723a_mac_init_table);
4444 dev_dbg(dev, "%s: init_mac %i\n", __func__, ret);
4445 if (ret)
4446 goto exit;
4447
4448 ret = rtl8xxxu_init_phy_bb(priv);
4449 dev_dbg(dev, "%s: init_phy_bb %i\n", __func__, ret);
4450 if (ret)
4451 goto exit;
4452
4453 switch(priv->rtlchip) {
4454 case 0x8723a:
4455 rftable = rtl8723au_radioa_1t_init_table;
4456 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4457 break;
4458 case 0x8188c:
4459 if (priv->hi_pa)
4460 rftable = rtl8188ru_radioa_1t_highpa_table;
4461 else
4462 rftable = rtl8192cu_radioa_1t_init_table;
4463 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4464 break;
4465 case 0x8191c:
4466 rftable = rtl8192cu_radioa_1t_init_table;
4467 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4468 break;
4469 case 0x8192c:
4470 rftable = rtl8192cu_radioa_2t_init_table;
4471 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_A);
4472 if (ret)
4473 break;
4474 rftable = rtl8192cu_radiob_2t_init_table;
4475 ret = rtl8xxxu_init_phy_rf(priv, rftable, RF_B);
4476 break;
4477 default:
4478 ret = -EINVAL;
4479 }
4480
4481 if (ret)
4482 goto exit;
4483
4484 /* Reduce 80M spur */
4485 rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, 0x0381808d);
4486 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
4487 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff82);
4488 rtl8xxxu_write32(priv, REG_AFE_PLL_CTRL, 0xf0ffff83);
4489
4490 /* RFSW Control - clear bit 14 ?? */
4491 rtl8xxxu_write32(priv, REG_FPGA0_TX_INFO, 0x00000003);
4492 /* 0x07000760 */
4493 val32 = FPGA0_RF_TRSW | FPGA0_RF_TRSWB | FPGA0_RF_ANTSW |
4494 FPGA0_RF_ANTSWB | FPGA0_RF_PAPE |
4495 ((FPGA0_RF_ANTSW | FPGA0_RF_ANTSWB | FPGA0_RF_PAPE) <<
4496 FPGA0_RF_BD_CTRL_SHIFT);
4497 rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
4498 /* 0x860[6:5]= 00 - why? - this sets antenna B */
4499 rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, 0x66F60210);
4500
4501 priv->rf_mode_ag[0] = rtl8xxxu_read_rfreg(priv, RF_A,
4502 RF6052_REG_MODE_AG);
4503
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004504 /*
4505 * Set RX page boundary
4506 */
4507 rtl8xxxu_write16(priv, REG_TRXFF_BNDY + 2, 0x27ff);
4508 /*
4509 * Transfer page size is always 128
4510 */
4511 val8 = (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_RX_SHIFT) |
4512 (PBP_PAGE_SIZE_128 << PBP_PAGE_SIZE_TX_SHIFT);
4513 rtl8xxxu_write8(priv, REG_PBP, val8);
4514
4515 /*
4516 * Unit in 8 bytes, not obvious what it is used for
4517 */
4518 rtl8xxxu_write8(priv, REG_RX_DRVINFO_SZ, 4);
4519
4520 /*
4521 * Enable all interrupts - not obvious USB needs to do this
4522 */
4523 rtl8xxxu_write32(priv, REG_HISR, 0xffffffff);
4524 rtl8xxxu_write32(priv, REG_HIMR, 0xffffffff);
4525
4526 rtl8xxxu_set_mac(priv);
4527 rtl8xxxu_set_linktype(priv, NL80211_IFTYPE_STATION);
4528
4529 /*
4530 * Configure initial WMAC settings
4531 */
4532 val32 = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_MCAST | RCR_ACCEPT_BCAST |
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004533 RCR_ACCEPT_MGMT_FRAME | RCR_HTC_LOC_CTRL |
4534 RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC;
4535 rtl8xxxu_write32(priv, REG_RCR, val32);
4536
4537 /*
4538 * Accept all multicast
4539 */
4540 rtl8xxxu_write32(priv, REG_MAR, 0xffffffff);
4541 rtl8xxxu_write32(priv, REG_MAR + 4, 0xffffffff);
4542
4543 /*
4544 * Init adaptive controls
4545 */
4546 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
4547 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
4548 val32 |= RESPONSE_RATE_RRSR_CCK_ONLY_1M;
4549 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
4550
4551 /* CCK = 0x0a, OFDM = 0x10 */
4552 rtl8xxxu_set_spec_sifs(priv, 0x10, 0x10);
4553 rtl8xxxu_set_retry(priv, 0x30, 0x30);
4554 rtl8xxxu_set_spec_sifs(priv, 0x0a, 0x10);
4555
4556 /*
4557 * Init EDCA
4558 */
4559 rtl8xxxu_write16(priv, REG_MAC_SPEC_SIFS, 0x100a);
4560
4561 /* Set CCK SIFS */
4562 rtl8xxxu_write16(priv, REG_SIFS_CCK, 0x100a);
4563
4564 /* Set OFDM SIFS */
4565 rtl8xxxu_write16(priv, REG_SIFS_OFDM, 0x100a);
4566
4567 /* TXOP */
4568 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, 0x005ea42b);
4569 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, 0x0000a44f);
4570 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, 0x005ea324);
4571 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, 0x002fa226);
4572
4573 /* Set data auto rate fallback retry count */
4574 rtl8xxxu_write32(priv, REG_DARFRC, 0x00000000);
4575 rtl8xxxu_write32(priv, REG_DARFRC + 4, 0x10080404);
4576 rtl8xxxu_write32(priv, REG_RARFRC, 0x04030201);
4577 rtl8xxxu_write32(priv, REG_RARFRC + 4, 0x08070605);
4578
4579 val8 = rtl8xxxu_read8(priv, REG_FWHW_TXQ_CTRL);
4580 val8 |= FWHW_TXQ_CTRL_AMPDU_RETRY;
4581 rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, val8);
4582
4583 /* Set ACK timeout */
4584 rtl8xxxu_write8(priv, REG_ACKTO, 0x40);
4585
4586 /*
4587 * Initialize beacon parameters
4588 */
4589 val16 = BEACON_DISABLE_TSF_UPDATE | (BEACON_DISABLE_TSF_UPDATE << 8);
4590 rtl8xxxu_write16(priv, REG_BEACON_CTRL, val16);
4591 rtl8xxxu_write16(priv, REG_TBTT_PROHIBIT, 0x6404);
4592 rtl8xxxu_write8(priv, REG_DRIVER_EARLY_INT, DRIVER_EARLY_INT_TIME);
4593 rtl8xxxu_write8(priv, REG_BEACON_DMA_TIME, BEACON_DMA_ATIME_INT_TIME);
4594 rtl8xxxu_write16(priv, REG_BEACON_TCFG, 0x660F);
4595
4596 /*
4597 * Enable CCK and OFDM block
4598 */
4599 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
4600 val32 |= (FPGA_RF_MODE_CCK | FPGA_RF_MODE_OFDM);
4601 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
4602
4603 /*
4604 * Invalidate all CAM entries - bit 30 is undocumented
4605 */
4606 rtl8xxxu_write32(priv, REG_CAM_CMD, CAM_CMD_POLLING | BIT(30));
4607
4608 /*
4609 * Start out with default power levels for channel 6, 20MHz
4610 */
4611 rtl8723a_set_tx_power(priv, 1, false);
4612
4613 /* Let the 8051 take control of antenna setting */
4614 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
4615 val8 |= LEDCFG2_DPDT_SELECT;
4616 rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
4617
4618 rtl8xxxu_write8(priv, REG_HWSEQ_CTRL, 0xff);
4619
4620 /* Disable BAR - not sure if this has any effect on USB */
4621 rtl8xxxu_write32(priv, REG_BAR_MODE_CTRL, 0x0201ffff);
4622
4623 rtl8xxxu_write16(priv, REG_FAST_EDCA_CTRL, 0);
4624
Jes Sorensene5c447c2016-02-03 13:39:48 -05004625 rtl8723a_phy_iq_calibrate(priv);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004626
4627 /*
4628 * This should enable thermal meter
4629 */
4630 rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_T_METER, 0x60);
4631
4632 rtl8723a_phy_lc_calibrate(priv);
4633
4634 /* fix USB interface interference issue */
4635 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
4636 rtl8xxxu_write8(priv, 0xfe41, 0x8d);
4637 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4638 rtl8xxxu_write32(priv, REG_TXDMA_OFFSET_CHK, 0xfd0320);
4639
4640 /* Solve too many protocol error on USB bus */
4641 /* Can't do this for 8188/8192 UMC A cut parts */
4642 rtl8xxxu_write8(priv, 0xfe40, 0xe6);
4643 rtl8xxxu_write8(priv, 0xfe41, 0x94);
4644 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4645
4646 rtl8xxxu_write8(priv, 0xfe40, 0xe0);
4647 rtl8xxxu_write8(priv, 0xfe41, 0x19);
4648 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4649
4650 rtl8xxxu_write8(priv, 0xfe40, 0xe5);
4651 rtl8xxxu_write8(priv, 0xfe41, 0x91);
4652 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4653
4654 rtl8xxxu_write8(priv, 0xfe40, 0xe2);
4655 rtl8xxxu_write8(priv, 0xfe41, 0x81);
4656 rtl8xxxu_write8(priv, 0xfe42, 0x80);
4657
4658 /* Init BT hw config. */
4659 rtl8xxxu_init_bt(priv);
4660
4661 /*
4662 * Not sure if we really need to save these parameters, but the
4663 * vendor driver does
4664 */
4665 val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM2);
4666 if (val32 & FPGA0_HSSI_PARM2_CCK_HIGH_PWR)
4667 priv->path_a_hi_power = 1;
4668
4669 val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
4670 priv->path_a_rf_paths = val32 & OFDM_RF_PATH_RX_MASK;
4671
4672 val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1);
4673 priv->path_a_ig_value = val32 & OFDM0_X_AGC_CORE1_IGI_MASK;
4674
4675 /* Set NAV_UPPER to 30000us */
4676 val8 = ((30000 + NAV_UPPER_UNIT - 1) / NAV_UPPER_UNIT);
4677 rtl8xxxu_write8(priv, REG_NAV_UPPER, val8);
4678
Jes Sorensen4042e612016-02-03 13:40:01 -05004679 if (priv->rtlchip == 0x8723a) {
4680 /*
4681 * 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test,
4682 * but we need to find root cause.
4683 * This is 8723au only.
4684 */
4685 val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
4686 if ((val32 & 0xff000000) != 0x83000000) {
4687 val32 |= FPGA_RF_MODE_CCK;
4688 rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
4689 }
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004690 }
4691
4692 val32 = rtl8xxxu_read32(priv, REG_FWHW_TXQ_CTRL);
4693 val32 |= FWHW_TXQ_CTRL_XMIT_MGMT_ACK;
4694 /* ack for xmit mgmt frames. */
4695 rtl8xxxu_write32(priv, REG_FWHW_TXQ_CTRL, val32);
4696
4697exit:
4698 return ret;
4699}
4700
4701static void rtl8xxxu_disable_device(struct ieee80211_hw *hw)
4702{
4703 struct rtl8xxxu_priv *priv = hw->priv;
4704
4705 rtl8xxxu_power_off(priv);
4706}
4707
4708static void rtl8xxxu_cam_write(struct rtl8xxxu_priv *priv,
4709 struct ieee80211_key_conf *key, const u8 *mac)
4710{
4711 u32 cmd, val32, addr, ctrl;
4712 int j, i, tmp_debug;
4713
4714 tmp_debug = rtl8xxxu_debug;
4715 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_KEY)
4716 rtl8xxxu_debug |= RTL8XXXU_DEBUG_REG_WRITE;
4717
4718 /*
4719 * This is a bit of a hack - the lower bits of the cipher
4720 * suite selector happens to match the cipher index in the CAM
4721 */
4722 addr = key->keyidx << CAM_CMD_KEY_SHIFT;
4723 ctrl = (key->cipher & 0x0f) << 2 | key->keyidx | CAM_WRITE_VALID;
4724
4725 for (j = 5; j >= 0; j--) {
4726 switch (j) {
4727 case 0:
4728 val32 = ctrl | (mac[0] << 16) | (mac[1] << 24);
4729 break;
4730 case 1:
4731 val32 = mac[2] | (mac[3] << 8) |
4732 (mac[4] << 16) | (mac[5] << 24);
4733 break;
4734 default:
4735 i = (j - 2) << 2;
4736 val32 = key->key[i] | (key->key[i + 1] << 8) |
4737 key->key[i + 2] << 16 | key->key[i + 3] << 24;
4738 break;
4739 }
4740
4741 rtl8xxxu_write32(priv, REG_CAM_WRITE, val32);
4742 cmd = CAM_CMD_POLLING | CAM_CMD_WRITE | (addr + j);
4743 rtl8xxxu_write32(priv, REG_CAM_CMD, cmd);
4744 udelay(100);
4745 }
4746
4747 rtl8xxxu_debug = tmp_debug;
4748}
4749
4750static void rtl8xxxu_sw_scan_start(struct ieee80211_hw *hw,
Jes Sorensen56e43742016-02-03 13:39:50 -05004751 struct ieee80211_vif *vif, const u8 *mac)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004752{
4753 struct rtl8xxxu_priv *priv = hw->priv;
4754 u8 val8;
4755
4756 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
4757 val8 |= BEACON_DISABLE_TSF_UPDATE;
4758 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
4759}
4760
4761static void rtl8xxxu_sw_scan_complete(struct ieee80211_hw *hw,
4762 struct ieee80211_vif *vif)
4763{
4764 struct rtl8xxxu_priv *priv = hw->priv;
4765 u8 val8;
4766
4767 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
4768 val8 &= ~BEACON_DISABLE_TSF_UPDATE;
4769 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
4770}
4771
4772static void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
4773 u32 ramask, int sgi)
4774{
4775 struct h2c_cmd h2c;
4776
4777 h2c.ramask.cmd = H2C_SET_RATE_MASK;
4778 h2c.ramask.mask_lo = cpu_to_le16(ramask & 0xffff);
4779 h2c.ramask.mask_hi = cpu_to_le16(ramask >> 16);
4780
4781 h2c.ramask.arg = 0x80;
4782 if (sgi)
4783 h2c.ramask.arg |= 0x20;
4784
4785 dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x\n", __func__,
4786 ramask, h2c.ramask.arg);
4787 rtl8723a_h2c_cmd(priv, &h2c);
4788}
4789
4790static void rtl8xxxu_set_basic_rates(struct rtl8xxxu_priv *priv, u32 rate_cfg)
4791{
4792 u32 val32;
4793 u8 rate_idx = 0;
4794
4795 rate_cfg &= RESPONSE_RATE_BITMAP_ALL;
4796
4797 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
4798 val32 &= ~RESPONSE_RATE_BITMAP_ALL;
4799 val32 |= rate_cfg;
4800 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
4801
4802 dev_dbg(&priv->udev->dev, "%s: rates %08x\n", __func__, rate_cfg);
4803
4804 while (rate_cfg) {
4805 rate_cfg = (rate_cfg >> 1);
4806 rate_idx++;
4807 }
4808 rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx);
4809}
4810
4811static void
4812rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4813 struct ieee80211_bss_conf *bss_conf, u32 changed)
4814{
4815 struct rtl8xxxu_priv *priv = hw->priv;
4816 struct device *dev = &priv->udev->dev;
4817 struct ieee80211_sta *sta;
4818 u32 val32;
4819 u8 val8;
4820
4821 if (changed & BSS_CHANGED_ASSOC) {
4822 struct h2c_cmd h2c;
4823
4824 dev_dbg(dev, "Changed ASSOC: %i!\n", bss_conf->assoc);
4825
4826 memset(&h2c, 0, sizeof(struct h2c_cmd));
4827 rtl8xxxu_set_linktype(priv, vif->type);
4828
4829 if (bss_conf->assoc) {
4830 u32 ramask;
4831 int sgi = 0;
4832
4833 rcu_read_lock();
4834 sta = ieee80211_find_sta(vif, bss_conf->bssid);
4835 if (!sta) {
4836 dev_info(dev, "%s: ASSOC no sta found\n",
4837 __func__);
4838 rcu_read_unlock();
4839 goto error;
4840 }
4841
4842 if (sta->ht_cap.ht_supported)
4843 dev_info(dev, "%s: HT supported\n", __func__);
4844 if (sta->vht_cap.vht_supported)
4845 dev_info(dev, "%s: VHT supported\n", __func__);
4846
4847 /* TODO: Set bits 28-31 for rate adaptive id */
4848 ramask = (sta->supp_rates[0] & 0xfff) |
4849 sta->ht_cap.mcs.rx_mask[0] << 12 |
4850 sta->ht_cap.mcs.rx_mask[1] << 20;
4851 if (sta->ht_cap.cap &
4852 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
4853 sgi = 1;
4854 rcu_read_unlock();
4855
4856 rtl8xxxu_update_rate_mask(priv, ramask, sgi);
4857
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004858 rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
4859
4860 rtl8723a_stop_tx_beacon(priv);
4861
4862 /* joinbss sequence */
4863 rtl8xxxu_write16(priv, REG_BCN_PSR_RPT,
4864 0xc000 | bss_conf->aid);
4865
4866 h2c.joinbss.data = H2C_JOIN_BSS_CONNECT;
4867 } else {
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004868 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
4869 val8 |= BEACON_DISABLE_TSF_UPDATE;
4870 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
4871
Jes Sorensen26f1fad2015-10-14 20:44:51 -04004872 h2c.joinbss.data = H2C_JOIN_BSS_DISCONNECT;
4873 }
4874 h2c.joinbss.cmd = H2C_JOIN_BSS_REPORT;
4875 rtl8723a_h2c_cmd(priv, &h2c);
4876 }
4877
4878 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4879 dev_dbg(dev, "Changed ERP_PREAMBLE: Use short preamble %i\n",
4880 bss_conf->use_short_preamble);
4881 val32 = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
4882 if (bss_conf->use_short_preamble)
4883 val32 |= RSR_ACK_SHORT_PREAMBLE;
4884 else
4885 val32 &= ~RSR_ACK_SHORT_PREAMBLE;
4886 rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, val32);
4887 }
4888
4889 if (changed & BSS_CHANGED_ERP_SLOT) {
4890 dev_dbg(dev, "Changed ERP_SLOT: short_slot_time %i\n",
4891 bss_conf->use_short_slot);
4892
4893 if (bss_conf->use_short_slot)
4894 val8 = 9;
4895 else
4896 val8 = 20;
4897 rtl8xxxu_write8(priv, REG_SLOT, val8);
4898 }
4899
4900 if (changed & BSS_CHANGED_BSSID) {
4901 dev_dbg(dev, "Changed BSSID!\n");
4902 rtl8xxxu_set_bssid(priv, bss_conf->bssid);
4903 }
4904
4905 if (changed & BSS_CHANGED_BASIC_RATES) {
4906 dev_dbg(dev, "Changed BASIC_RATES!\n");
4907 rtl8xxxu_set_basic_rates(priv, bss_conf->basic_rates);
4908 }
4909error:
4910 return;
4911}
4912
4913static u32 rtl8xxxu_80211_to_rtl_queue(u32 queue)
4914{
4915 u32 rtlqueue;
4916
4917 switch (queue) {
4918 case IEEE80211_AC_VO:
4919 rtlqueue = TXDESC_QUEUE_VO;
4920 break;
4921 case IEEE80211_AC_VI:
4922 rtlqueue = TXDESC_QUEUE_VI;
4923 break;
4924 case IEEE80211_AC_BE:
4925 rtlqueue = TXDESC_QUEUE_BE;
4926 break;
4927 case IEEE80211_AC_BK:
4928 rtlqueue = TXDESC_QUEUE_BK;
4929 break;
4930 default:
4931 rtlqueue = TXDESC_QUEUE_BE;
4932 }
4933
4934 return rtlqueue;
4935}
4936
4937static u32 rtl8xxxu_queue_select(struct ieee80211_hw *hw, struct sk_buff *skb)
4938{
4939 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4940 u32 queue;
4941
4942 if (ieee80211_is_mgmt(hdr->frame_control))
4943 queue = TXDESC_QUEUE_MGNT;
4944 else
4945 queue = rtl8xxxu_80211_to_rtl_queue(skb_get_queue_mapping(skb));
4946
4947 return queue;
4948}
4949
4950static void rtl8xxxu_calc_tx_desc_csum(struct rtl8xxxu_tx_desc *tx_desc)
4951{
4952 __le16 *ptr = (__le16 *)tx_desc;
4953 u16 csum = 0;
4954 int i;
4955
4956 /*
4957 * Clear csum field before calculation, as the csum field is
4958 * in the middle of the struct.
4959 */
4960 tx_desc->csum = cpu_to_le16(0);
4961
4962 for (i = 0; i < (sizeof(struct rtl8xxxu_tx_desc) / sizeof(u16)); i++)
4963 csum = csum ^ le16_to_cpu(ptr[i]);
4964
4965 tx_desc->csum |= cpu_to_le16(csum);
4966}
4967
4968static void rtl8xxxu_free_tx_resources(struct rtl8xxxu_priv *priv)
4969{
4970 struct rtl8xxxu_tx_urb *tx_urb, *tmp;
4971 unsigned long flags;
4972
4973 spin_lock_irqsave(&priv->tx_urb_lock, flags);
4974 list_for_each_entry_safe(tx_urb, tmp, &priv->tx_urb_free_list, list) {
4975 list_del(&tx_urb->list);
4976 priv->tx_urb_free_count--;
4977 usb_free_urb(&tx_urb->urb);
4978 }
4979 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
4980}
4981
4982static struct rtl8xxxu_tx_urb *
4983rtl8xxxu_alloc_tx_urb(struct rtl8xxxu_priv *priv)
4984{
4985 struct rtl8xxxu_tx_urb *tx_urb;
4986 unsigned long flags;
4987
4988 spin_lock_irqsave(&priv->tx_urb_lock, flags);
4989 tx_urb = list_first_entry_or_null(&priv->tx_urb_free_list,
4990 struct rtl8xxxu_tx_urb, list);
4991 if (tx_urb) {
4992 list_del(&tx_urb->list);
4993 priv->tx_urb_free_count--;
4994 if (priv->tx_urb_free_count < RTL8XXXU_TX_URB_LOW_WATER &&
4995 !priv->tx_stopped) {
4996 priv->tx_stopped = true;
4997 ieee80211_stop_queues(priv->hw);
4998 }
4999 }
5000
5001 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
5002
5003 return tx_urb;
5004}
5005
5006static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv,
5007 struct rtl8xxxu_tx_urb *tx_urb)
5008{
5009 unsigned long flags;
5010
5011 INIT_LIST_HEAD(&tx_urb->list);
5012
5013 spin_lock_irqsave(&priv->tx_urb_lock, flags);
5014
5015 list_add(&tx_urb->list, &priv->tx_urb_free_list);
5016 priv->tx_urb_free_count++;
5017 if (priv->tx_urb_free_count > RTL8XXXU_TX_URB_HIGH_WATER &&
5018 priv->tx_stopped) {
5019 priv->tx_stopped = false;
5020 ieee80211_wake_queues(priv->hw);
5021 }
5022
5023 spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
5024}
5025
5026static void rtl8xxxu_tx_complete(struct urb *urb)
5027{
5028 struct sk_buff *skb = (struct sk_buff *)urb->context;
5029 struct ieee80211_tx_info *tx_info;
5030 struct ieee80211_hw *hw;
5031 struct rtl8xxxu_tx_urb *tx_urb =
5032 container_of(urb, struct rtl8xxxu_tx_urb, urb);
5033
5034 tx_info = IEEE80211_SKB_CB(skb);
5035 hw = tx_info->rate_driver_data[0];
5036
5037 skb_pull(skb, sizeof(struct rtl8xxxu_tx_desc));
5038
5039 ieee80211_tx_info_clear_status(tx_info);
5040 tx_info->status.rates[0].idx = -1;
5041 tx_info->status.rates[0].count = 0;
5042
5043 if (!urb->status)
5044 tx_info->flags |= IEEE80211_TX_STAT_ACK;
5045
5046 ieee80211_tx_status_irqsafe(hw, skb);
5047
5048 rtl8xxxu_free_tx_urb(hw->priv, tx_urb);
5049}
5050
5051static void rtl8xxxu_dump_action(struct device *dev,
5052 struct ieee80211_hdr *hdr)
5053{
5054 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
5055 u16 cap, timeout;
5056
5057 if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION))
5058 return;
5059
5060 switch (mgmt->u.action.u.addba_resp.action_code) {
5061 case WLAN_ACTION_ADDBA_RESP:
5062 cap = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
5063 timeout = le16_to_cpu(mgmt->u.action.u.addba_resp.timeout);
5064 dev_info(dev, "WLAN_ACTION_ADDBA_RESP: "
5065 "timeout %i, tid %02x, buf_size %02x, policy %02x, "
5066 "status %02x\n",
5067 timeout,
5068 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
5069 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
5070 (cap >> 1) & 0x1,
5071 le16_to_cpu(mgmt->u.action.u.addba_resp.status));
5072 break;
5073 case WLAN_ACTION_ADDBA_REQ:
5074 cap = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
5075 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
5076 dev_info(dev, "WLAN_ACTION_ADDBA_REQ: "
5077 "timeout %i, tid %02x, buf_size %02x, policy %02x\n",
5078 timeout,
5079 (cap & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2,
5080 (cap & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6,
5081 (cap >> 1) & 0x1);
5082 break;
5083 default:
5084 dev_info(dev, "action frame %02x\n",
5085 mgmt->u.action.u.addba_resp.action_code);
5086 break;
5087 }
5088}
5089
5090static void rtl8xxxu_tx(struct ieee80211_hw *hw,
5091 struct ieee80211_tx_control *control,
5092 struct sk_buff *skb)
5093{
5094 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5095 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
5096 struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
5097 struct rtl8xxxu_priv *priv = hw->priv;
5098 struct rtl8xxxu_tx_desc *tx_desc;
5099 struct rtl8xxxu_tx_urb *tx_urb;
5100 struct ieee80211_sta *sta = NULL;
5101 struct ieee80211_vif *vif = tx_info->control.vif;
5102 struct device *dev = &priv->udev->dev;
5103 u32 queue, rate;
5104 u16 pktlen = skb->len;
5105 u16 seq_number;
5106 u16 rate_flag = tx_info->control.rates[0].flags;
5107 int ret;
5108
5109 if (skb_headroom(skb) < sizeof(struct rtl8xxxu_tx_desc)) {
5110 dev_warn(dev,
5111 "%s: Not enough headroom (%i) for tx descriptor\n",
5112 __func__, skb_headroom(skb));
5113 goto error;
5114 }
5115
5116 if (unlikely(skb->len > (65535 - sizeof(struct rtl8xxxu_tx_desc)))) {
5117 dev_warn(dev, "%s: Trying to send over-sized skb (%i)\n",
5118 __func__, skb->len);
5119 goto error;
5120 }
5121
5122 tx_urb = rtl8xxxu_alloc_tx_urb(priv);
5123 if (!tx_urb) {
5124 dev_warn(dev, "%s: Unable to allocate tx urb\n", __func__);
5125 goto error;
5126 }
5127
5128 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
5129 dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n",
5130 __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen);
5131
5132 if (ieee80211_is_action(hdr->frame_control))
5133 rtl8xxxu_dump_action(dev, hdr);
5134
5135 tx_info->rate_driver_data[0] = hw;
5136
5137 if (control && control->sta)
5138 sta = control->sta;
5139
5140 tx_desc = (struct rtl8xxxu_tx_desc *)
5141 skb_push(skb, sizeof(struct rtl8xxxu_tx_desc));
5142
5143 memset(tx_desc, 0, sizeof(struct rtl8xxxu_tx_desc));
5144 tx_desc->pkt_size = cpu_to_le16(pktlen);
5145 tx_desc->pkt_offset = sizeof(struct rtl8xxxu_tx_desc);
5146
5147 tx_desc->txdw0 =
5148 TXDESC_OWN | TXDESC_FIRST_SEGMENT | TXDESC_LAST_SEGMENT;
5149 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
5150 is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
5151 tx_desc->txdw0 |= TXDESC_BROADMULTICAST;
5152
5153 queue = rtl8xxxu_queue_select(hw, skb);
5154 tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT);
5155
5156 if (tx_info->control.hw_key) {
5157 switch (tx_info->control.hw_key->cipher) {
5158 case WLAN_CIPHER_SUITE_WEP40:
5159 case WLAN_CIPHER_SUITE_WEP104:
5160 case WLAN_CIPHER_SUITE_TKIP:
5161 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_RC4);
5162 break;
5163 case WLAN_CIPHER_SUITE_CCMP:
5164 tx_desc->txdw1 |= cpu_to_le32(TXDESC_SEC_AES);
5165 break;
5166 default:
5167 break;
5168 }
5169 }
5170
5171 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
5172 tx_desc->txdw3 = cpu_to_le32((u32)seq_number << TXDESC_SEQ_SHIFT);
5173
5174 if (rate_flag & IEEE80211_TX_RC_MCS)
5175 rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
5176 else
5177 rate = tx_rate->hw_value;
5178 tx_desc->txdw5 = cpu_to_le32(rate);
5179
5180 if (ieee80211_is_data(hdr->frame_control))
5181 tx_desc->txdw5 |= cpu_to_le32(0x0001ff00);
5182
5183 /* (tx_info->flags & IEEE80211_TX_CTL_AMPDU) && */
5184 if (ieee80211_is_data_qos(hdr->frame_control) && sta) {
5185 if (sta->ht_cap.ht_supported) {
5186 u32 ampdu, val32;
5187
5188 ampdu = (u32)sta->ht_cap.ampdu_density;
5189 val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT;
5190 tx_desc->txdw2 |= cpu_to_le32(val32);
5191 tx_desc->txdw1 |= cpu_to_le32(TXDESC_AGG_ENABLE);
5192 } else
5193 tx_desc->txdw1 |= cpu_to_le32(TXDESC_BK);
5194 } else
5195 tx_desc->txdw1 |= cpu_to_le32(TXDESC_BK);
5196
5197 if (ieee80211_is_data_qos(hdr->frame_control))
5198 tx_desc->txdw4 |= cpu_to_le32(TXDESC_QOS);
5199 if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ||
5200 (sta && vif && vif->bss_conf.use_short_preamble))
5201 tx_desc->txdw4 |= cpu_to_le32(TXDESC_SHORT_PREAMBLE);
5202 if (rate_flag & IEEE80211_TX_RC_SHORT_GI ||
5203 (ieee80211_is_data_qos(hdr->frame_control) &&
5204 sta && sta->ht_cap.cap &
5205 (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))) {
5206 tx_desc->txdw5 |= cpu_to_le32(TXDESC_SHORT_GI);
5207 }
5208 if (ieee80211_is_mgmt(hdr->frame_control)) {
5209 tx_desc->txdw5 = cpu_to_le32(tx_rate->hw_value);
5210 tx_desc->txdw4 |= cpu_to_le32(TXDESC_USE_DRIVER_RATE);
5211 tx_desc->txdw5 |= cpu_to_le32(6 << TXDESC_RETRY_LIMIT_SHIFT);
5212 tx_desc->txdw5 |= cpu_to_le32(TXDESC_RETRY_LIMIT_ENABLE);
5213 }
5214
5215 if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
5216 /* Use RTS rate 24M - does the mac80211 tell us which to use? */
5217 tx_desc->txdw4 |= cpu_to_le32(DESC_RATE_24M);
5218 tx_desc->txdw4 |= cpu_to_le32(TXDESC_RTS_CTS_ENABLE);
5219 tx_desc->txdw4 |= cpu_to_le32(TXDESC_HW_RTS_ENABLE);
5220 }
5221
5222 rtl8xxxu_calc_tx_desc_csum(tx_desc);
5223
5224 usb_fill_bulk_urb(&tx_urb->urb, priv->udev, priv->pipe_out[queue],
5225 skb->data, skb->len, rtl8xxxu_tx_complete, skb);
5226
5227 usb_anchor_urb(&tx_urb->urb, &priv->tx_anchor);
5228 ret = usb_submit_urb(&tx_urb->urb, GFP_ATOMIC);
5229 if (ret) {
5230 usb_unanchor_urb(&tx_urb->urb);
5231 rtl8xxxu_free_tx_urb(priv, tx_urb);
5232 goto error;
5233 }
5234 return;
5235error:
5236 dev_kfree_skb(skb);
5237}
5238
5239static void rtl8xxxu_rx_parse_phystats(struct rtl8xxxu_priv *priv,
5240 struct ieee80211_rx_status *rx_status,
5241 struct rtl8xxxu_rx_desc *rx_desc,
5242 struct rtl8723au_phy_stats *phy_stats)
5243{
5244 if (phy_stats->sgi_en)
5245 rx_status->flag |= RX_FLAG_SHORT_GI;
5246
5247 if (rx_desc->rxmcs < DESC_RATE_6M) {
5248 /*
5249 * Handle PHY stats for CCK rates
5250 */
5251 u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
5252
5253 switch (cck_agc_rpt & 0xc0) {
5254 case 0xc0:
5255 rx_status->signal = -46 - (cck_agc_rpt & 0x3e);
5256 break;
5257 case 0x80:
5258 rx_status->signal = -26 - (cck_agc_rpt & 0x3e);
5259 break;
5260 case 0x40:
5261 rx_status->signal = -12 - (cck_agc_rpt & 0x3e);
5262 break;
5263 case 0x00:
5264 rx_status->signal = 16 - (cck_agc_rpt & 0x3e);
5265 break;
5266 }
5267 } else {
5268 rx_status->signal =
5269 (phy_stats->cck_sig_qual_ofdm_pwdb_all >> 1) - 110;
5270 }
5271}
5272
5273static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv)
5274{
5275 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
5276 unsigned long flags;
5277
5278 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5279
5280 list_for_each_entry_safe(rx_urb, tmp,
5281 &priv->rx_urb_pending_list, list) {
5282 list_del(&rx_urb->list);
5283 priv->rx_urb_pending_count--;
5284 usb_free_urb(&rx_urb->urb);
5285 }
5286
5287 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5288}
5289
5290static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,
5291 struct rtl8xxxu_rx_urb *rx_urb)
5292{
5293 struct sk_buff *skb;
5294 unsigned long flags;
5295 int pending = 0;
5296
5297 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5298
5299 if (!priv->shutdown) {
5300 list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list);
5301 priv->rx_urb_pending_count++;
5302 pending = priv->rx_urb_pending_count;
5303 } else {
5304 skb = (struct sk_buff *)rx_urb->urb.context;
5305 dev_kfree_skb(skb);
5306 usb_free_urb(&rx_urb->urb);
5307 }
5308
5309 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5310
5311 if (pending > RTL8XXXU_RX_URB_PENDING_WATER)
5312 schedule_work(&priv->rx_urb_wq);
5313}
5314
5315static void rtl8xxxu_rx_urb_work(struct work_struct *work)
5316{
5317 struct rtl8xxxu_priv *priv;
5318 struct rtl8xxxu_rx_urb *rx_urb, *tmp;
5319 struct list_head local;
5320 struct sk_buff *skb;
5321 unsigned long flags;
5322 int ret;
5323
5324 priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq);
5325 INIT_LIST_HEAD(&local);
5326
5327 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5328
5329 list_splice_init(&priv->rx_urb_pending_list, &local);
5330 priv->rx_urb_pending_count = 0;
5331
5332 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5333
5334 list_for_each_entry_safe(rx_urb, tmp, &local, list) {
5335 list_del_init(&rx_urb->list);
5336 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
5337 /*
5338 * If out of memory or temporary error, put it back on the
5339 * queue and try again. Otherwise the device is dead/gone
5340 * and we should drop it.
5341 */
5342 switch (ret) {
5343 case 0:
5344 break;
5345 case -ENOMEM:
5346 case -EAGAIN:
5347 rtl8xxxu_queue_rx_urb(priv, rx_urb);
5348 break;
5349 default:
5350 pr_info("failed to requeue urb %i\n", ret);
5351 skb = (struct sk_buff *)rx_urb->urb.context;
5352 dev_kfree_skb(skb);
5353 usb_free_urb(&rx_urb->urb);
5354 }
5355 }
5356}
5357
5358static void rtl8xxxu_rx_complete(struct urb *urb)
5359{
5360 struct rtl8xxxu_rx_urb *rx_urb =
5361 container_of(urb, struct rtl8xxxu_rx_urb, urb);
5362 struct ieee80211_hw *hw = rx_urb->hw;
5363 struct rtl8xxxu_priv *priv = hw->priv;
5364 struct sk_buff *skb = (struct sk_buff *)urb->context;
5365 struct rtl8xxxu_rx_desc *rx_desc = (struct rtl8xxxu_rx_desc *)skb->data;
5366 struct rtl8723au_phy_stats *phy_stats;
5367 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005368 struct device *dev = &priv->udev->dev;
5369 __le32 *_rx_desc_le = (__le32 *)skb->data;
5370 u32 *_rx_desc = (u32 *)skb->data;
Jes Sorensena9ffa612016-02-03 13:39:59 -05005371 int drvinfo_sz, desc_shift, i;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005372
5373 for (i = 0; i < (sizeof(struct rtl8xxxu_rx_desc) / sizeof(u32)); i++)
5374 _rx_desc[i] = le32_to_cpu(_rx_desc_le[i]);
5375
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005376 drvinfo_sz = rx_desc->drvinfo_sz * 8;
5377 desc_shift = rx_desc->shift;
5378 skb_put(skb, urb->actual_length);
5379
5380 if (urb->status == 0) {
5381 skb_pull(skb, sizeof(struct rtl8xxxu_rx_desc));
5382 phy_stats = (struct rtl8723au_phy_stats *)skb->data;
5383
5384 skb_pull(skb, drvinfo_sz + desc_shift);
5385
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005386 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
5387
5388 if (rx_desc->phy_stats)
5389 rtl8xxxu_rx_parse_phystats(priv, rx_status,
5390 rx_desc, phy_stats);
5391
5392 rx_status->freq = hw->conf.chandef.chan->center_freq;
5393 rx_status->band = hw->conf.chandef.chan->band;
5394
5395 rx_status->mactime = le32_to_cpu(rx_desc->tsfl);
5396 rx_status->flag |= RX_FLAG_MACTIME_START;
5397
5398 if (!rx_desc->swdec)
5399 rx_status->flag |= RX_FLAG_DECRYPTED;
5400 if (rx_desc->crc32)
5401 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
5402 if (rx_desc->bw)
5403 rx_status->flag |= RX_FLAG_40MHZ;
5404
5405 if (rx_desc->rxht) {
5406 rx_status->flag |= RX_FLAG_HT;
5407 rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0;
5408 } else {
5409 rx_status->rate_idx = rx_desc->rxmcs;
5410 }
5411
5412 ieee80211_rx_irqsafe(hw, skb);
5413 skb = NULL;
5414 rx_urb->urb.context = NULL;
5415 rtl8xxxu_queue_rx_urb(priv, rx_urb);
5416 } else {
5417 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
5418 goto cleanup;
5419 }
5420 return;
5421
5422cleanup:
5423 usb_free_urb(urb);
5424 dev_kfree_skb(skb);
5425 return;
5426}
5427
5428static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv,
5429 struct rtl8xxxu_rx_urb *rx_urb)
5430{
5431 struct sk_buff *skb;
5432 int skb_size;
5433 int ret;
5434
5435 skb_size = sizeof(struct rtl8xxxu_rx_desc) + RTL_RX_BUFFER_SIZE;
5436 skb = __netdev_alloc_skb(NULL, skb_size, GFP_KERNEL);
5437 if (!skb)
5438 return -ENOMEM;
5439
5440 memset(skb->data, 0, sizeof(struct rtl8xxxu_rx_desc));
5441 usb_fill_bulk_urb(&rx_urb->urb, priv->udev, priv->pipe_in, skb->data,
5442 skb_size, rtl8xxxu_rx_complete, skb);
5443 usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor);
5444 ret = usb_submit_urb(&rx_urb->urb, GFP_ATOMIC);
5445 if (ret)
5446 usb_unanchor_urb(&rx_urb->urb);
5447 return ret;
5448}
5449
5450static void rtl8xxxu_int_complete(struct urb *urb)
5451{
5452 struct rtl8xxxu_priv *priv = (struct rtl8xxxu_priv *)urb->context;
5453 struct device *dev = &priv->udev->dev;
5454 int ret;
5455
5456 dev_dbg(dev, "%s: status %i\n", __func__, urb->status);
5457 if (urb->status == 0) {
5458 usb_anchor_urb(urb, &priv->int_anchor);
5459 ret = usb_submit_urb(urb, GFP_ATOMIC);
5460 if (ret)
5461 usb_unanchor_urb(urb);
5462 } else {
5463 dev_info(dev, "%s: Error %i\n", __func__, urb->status);
5464 }
5465}
5466
5467
5468static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
5469{
5470 struct rtl8xxxu_priv *priv = hw->priv;
5471 struct urb *urb;
5472 u32 val32;
5473 int ret;
5474
5475 urb = usb_alloc_urb(0, GFP_KERNEL);
5476 if (!urb)
5477 return -ENOMEM;
5478
5479 usb_fill_int_urb(urb, priv->udev, priv->pipe_interrupt,
5480 priv->int_buf, USB_INTR_CONTENT_LENGTH,
5481 rtl8xxxu_int_complete, priv, 1);
5482 usb_anchor_urb(urb, &priv->int_anchor);
5483 ret = usb_submit_urb(urb, GFP_KERNEL);
5484 if (ret) {
5485 usb_unanchor_urb(urb);
5486 goto error;
5487 }
5488
5489 val32 = rtl8xxxu_read32(priv, REG_USB_HIMR);
5490 val32 |= USB_HIMR_CPWM;
5491 rtl8xxxu_write32(priv, REG_USB_HIMR, val32);
5492
5493error:
5494 return ret;
5495}
5496
5497static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
5498 struct ieee80211_vif *vif)
5499{
5500 struct rtl8xxxu_priv *priv = hw->priv;
5501 int ret;
5502 u8 val8;
5503
5504 switch (vif->type) {
5505 case NL80211_IFTYPE_STATION:
5506 rtl8723a_stop_tx_beacon(priv);
5507
5508 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
5509 val8 |= BEACON_ATIM | BEACON_FUNCTION_ENABLE |
5510 BEACON_DISABLE_TSF_UPDATE;
5511 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
5512 ret = 0;
5513 break;
5514 default:
5515 ret = -EOPNOTSUPP;
5516 }
5517
5518 rtl8xxxu_set_linktype(priv, vif->type);
5519
5520 return ret;
5521}
5522
5523static void rtl8xxxu_remove_interface(struct ieee80211_hw *hw,
5524 struct ieee80211_vif *vif)
5525{
5526 struct rtl8xxxu_priv *priv = hw->priv;
5527
5528 dev_dbg(&priv->udev->dev, "%s\n", __func__);
5529}
5530
5531static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
5532{
5533 struct rtl8xxxu_priv *priv = hw->priv;
5534 struct device *dev = &priv->udev->dev;
5535 u16 val16;
5536 int ret = 0, channel;
5537 bool ht40;
5538
5539 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_CHANNEL)
5540 dev_info(dev,
5541 "%s: channel: %i (changed %08x chandef.width %02x)\n",
5542 __func__, hw->conf.chandef.chan->hw_value,
5543 changed, hw->conf.chandef.width);
5544
5545 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
5546 val16 = ((hw->conf.long_frame_max_tx_count <<
5547 RETRY_LIMIT_LONG_SHIFT) & RETRY_LIMIT_LONG_MASK) |
5548 ((hw->conf.short_frame_max_tx_count <<
5549 RETRY_LIMIT_SHORT_SHIFT) & RETRY_LIMIT_SHORT_MASK);
5550 rtl8xxxu_write16(priv, REG_RETRY_LIMIT, val16);
5551 }
5552
5553 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
5554 switch (hw->conf.chandef.width) {
5555 case NL80211_CHAN_WIDTH_20_NOHT:
5556 case NL80211_CHAN_WIDTH_20:
5557 ht40 = false;
5558 break;
5559 case NL80211_CHAN_WIDTH_40:
5560 ht40 = true;
5561 break;
5562 default:
5563 ret = -ENOTSUPP;
5564 goto exit;
5565 }
5566
5567 channel = hw->conf.chandef.chan->hw_value;
5568
5569 rtl8723a_set_tx_power(priv, channel, ht40);
5570
5571 rtl8723au_config_channel(hw);
5572 }
5573
5574exit:
5575 return ret;
5576}
5577
5578static int rtl8xxxu_conf_tx(struct ieee80211_hw *hw,
5579 struct ieee80211_vif *vif, u16 queue,
5580 const struct ieee80211_tx_queue_params *param)
5581{
5582 struct rtl8xxxu_priv *priv = hw->priv;
5583 struct device *dev = &priv->udev->dev;
5584 u32 val32;
5585 u8 aifs, acm_ctrl, acm_bit;
5586
5587 aifs = param->aifs;
5588
5589 val32 = aifs |
5590 fls(param->cw_min) << EDCA_PARAM_ECW_MIN_SHIFT |
5591 fls(param->cw_max) << EDCA_PARAM_ECW_MAX_SHIFT |
5592 (u32)param->txop << EDCA_PARAM_TXOP_SHIFT;
5593
5594 acm_ctrl = rtl8xxxu_read8(priv, REG_ACM_HW_CTRL);
5595 dev_dbg(dev,
5596 "%s: IEEE80211 queue %02x val %08x, acm %i, acm_ctrl %02x\n",
5597 __func__, queue, val32, param->acm, acm_ctrl);
5598
5599 switch (queue) {
5600 case IEEE80211_AC_VO:
5601 acm_bit = ACM_HW_CTRL_VO;
5602 rtl8xxxu_write32(priv, REG_EDCA_VO_PARAM, val32);
5603 break;
5604 case IEEE80211_AC_VI:
5605 acm_bit = ACM_HW_CTRL_VI;
5606 rtl8xxxu_write32(priv, REG_EDCA_VI_PARAM, val32);
5607 break;
5608 case IEEE80211_AC_BE:
5609 acm_bit = ACM_HW_CTRL_BE;
5610 rtl8xxxu_write32(priv, REG_EDCA_BE_PARAM, val32);
5611 break;
5612 case IEEE80211_AC_BK:
5613 acm_bit = ACM_HW_CTRL_BK;
5614 rtl8xxxu_write32(priv, REG_EDCA_BK_PARAM, val32);
5615 break;
5616 default:
5617 acm_bit = 0;
5618 break;
5619 }
5620
5621 if (param->acm)
5622 acm_ctrl |= acm_bit;
5623 else
5624 acm_ctrl &= ~acm_bit;
5625 rtl8xxxu_write8(priv, REG_ACM_HW_CTRL, acm_ctrl);
5626
5627 return 0;
5628}
5629
5630static void rtl8xxxu_configure_filter(struct ieee80211_hw *hw,
5631 unsigned int changed_flags,
5632 unsigned int *total_flags, u64 multicast)
5633{
5634 struct rtl8xxxu_priv *priv = hw->priv;
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05005635 u32 rcr = rtl8xxxu_read32(priv, REG_RCR);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005636
5637 dev_dbg(&priv->udev->dev, "%s: changed_flags %08x, total_flags %08x\n",
5638 __func__, changed_flags, *total_flags);
5639
Bruno Randolf3bed4bf2016-02-03 13:39:51 -05005640 /*
5641 * FIF_ALLMULTI ignored as all multicast frames are accepted (REG_MAR)
5642 */
5643
5644 if (*total_flags & FIF_FCSFAIL)
5645 rcr |= RCR_ACCEPT_CRC32;
5646 else
5647 rcr &= ~RCR_ACCEPT_CRC32;
5648
5649 /*
5650 * FIF_PLCPFAIL not supported?
5651 */
5652
5653 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
5654 rcr &= ~RCR_CHECK_BSSID_BEACON;
5655 else
5656 rcr |= RCR_CHECK_BSSID_BEACON;
5657
5658 if (*total_flags & FIF_CONTROL)
5659 rcr |= RCR_ACCEPT_CTRL_FRAME;
5660 else
5661 rcr &= ~RCR_ACCEPT_CTRL_FRAME;
5662
5663 if (*total_flags & FIF_OTHER_BSS) {
5664 rcr |= RCR_ACCEPT_AP;
5665 rcr &= ~RCR_CHECK_BSSID_MATCH;
5666 } else {
5667 rcr &= ~RCR_ACCEPT_AP;
5668 rcr |= RCR_CHECK_BSSID_MATCH;
5669 }
5670
5671 if (*total_flags & FIF_PSPOLL)
5672 rcr |= RCR_ACCEPT_PM;
5673 else
5674 rcr &= ~RCR_ACCEPT_PM;
5675
5676 /*
5677 * FIF_PROBE_REQ ignored as probe requests always seem to be accepted
5678 */
5679
5680 rtl8xxxu_write32(priv, REG_RCR, rcr);
5681
Jes Sorensen755bda12016-02-03 13:39:54 -05005682 *total_flags &= (FIF_ALLMULTI | FIF_FCSFAIL | FIF_BCN_PRBRESP_PROMISC |
5683 FIF_CONTROL | FIF_OTHER_BSS | FIF_PSPOLL |
5684 FIF_PROBE_REQ);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005685}
5686
5687static int rtl8xxxu_set_rts_threshold(struct ieee80211_hw *hw, u32 rts)
5688{
5689 if (rts > 2347)
5690 return -EINVAL;
5691
5692 return 0;
5693}
5694
5695static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5696 struct ieee80211_vif *vif,
5697 struct ieee80211_sta *sta,
5698 struct ieee80211_key_conf *key)
5699{
5700 struct rtl8xxxu_priv *priv = hw->priv;
5701 struct device *dev = &priv->udev->dev;
5702 u8 mac_addr[ETH_ALEN];
5703 u8 val8;
5704 u16 val16;
5705 u32 val32;
5706 int retval = -EOPNOTSUPP;
5707
5708 dev_dbg(dev, "%s: cmd %02x, cipher %08x, index %i\n",
5709 __func__, cmd, key->cipher, key->keyidx);
5710
5711 if (vif->type != NL80211_IFTYPE_STATION)
5712 return -EOPNOTSUPP;
5713
5714 if (key->keyidx > 3)
5715 return -EOPNOTSUPP;
5716
5717 switch (key->cipher) {
5718 case WLAN_CIPHER_SUITE_WEP40:
5719 case WLAN_CIPHER_SUITE_WEP104:
5720
5721 break;
5722 case WLAN_CIPHER_SUITE_CCMP:
5723 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
5724 break;
5725 case WLAN_CIPHER_SUITE_TKIP:
5726 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
5727 default:
5728 return -EOPNOTSUPP;
5729 }
5730
5731 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
5732 dev_dbg(dev, "%s: pairwise key\n", __func__);
5733 ether_addr_copy(mac_addr, sta->addr);
5734 } else {
5735 dev_dbg(dev, "%s: group key\n", __func__);
5736 eth_broadcast_addr(mac_addr);
5737 }
5738
5739 val16 = rtl8xxxu_read16(priv, REG_CR);
5740 val16 |= CR_SECURITY_ENABLE;
5741 rtl8xxxu_write16(priv, REG_CR, val16);
5742
5743 val8 = SEC_CFG_TX_SEC_ENABLE | SEC_CFG_TXBC_USE_DEFKEY |
5744 SEC_CFG_RX_SEC_ENABLE | SEC_CFG_RXBC_USE_DEFKEY;
5745 val8 |= SEC_CFG_TX_USE_DEFKEY | SEC_CFG_RX_USE_DEFKEY;
5746 rtl8xxxu_write8(priv, REG_SECURITY_CFG, val8);
5747
5748 switch (cmd) {
5749 case SET_KEY:
5750 key->hw_key_idx = key->keyidx;
5751 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
5752 rtl8xxxu_cam_write(priv, key, mac_addr);
5753 retval = 0;
5754 break;
5755 case DISABLE_KEY:
5756 rtl8xxxu_write32(priv, REG_CAM_WRITE, 0x00000000);
5757 val32 = CAM_CMD_POLLING | CAM_CMD_WRITE |
5758 key->keyidx << CAM_CMD_KEY_SHIFT;
5759 rtl8xxxu_write32(priv, REG_CAM_CMD, val32);
5760 retval = 0;
5761 break;
5762 default:
5763 dev_warn(dev, "%s: Unsupported command %02x\n", __func__, cmd);
5764 }
5765
5766 return retval;
5767}
5768
5769static int
5770rtl8xxxu_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +02005771 struct ieee80211_ampdu_params *params)
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005772{
5773 struct rtl8xxxu_priv *priv = hw->priv;
5774 struct device *dev = &priv->udev->dev;
5775 u8 ampdu_factor, ampdu_density;
Sara Sharon50ea05e2015-12-30 16:06:04 +02005776 struct ieee80211_sta *sta = params->sta;
5777 enum ieee80211_ampdu_mlme_action action = params->action;
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005778
5779 switch (action) {
5780 case IEEE80211_AMPDU_TX_START:
5781 dev_info(dev, "%s: IEEE80211_AMPDU_TX_START\n", __func__);
5782 ampdu_factor = sta->ht_cap.ampdu_factor;
5783 ampdu_density = sta->ht_cap.ampdu_density;
5784 rtl8xxxu_set_ampdu_factor(priv, ampdu_factor);
5785 rtl8xxxu_set_ampdu_min_space(priv, ampdu_density);
5786 dev_dbg(dev,
5787 "Changed HT: ampdu_factor %02x, ampdu_density %02x\n",
5788 ampdu_factor, ampdu_density);
5789 break;
5790 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5791 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__);
5792 rtl8xxxu_set_ampdu_factor(priv, 0);
5793 rtl8xxxu_set_ampdu_min_space(priv, 0);
5794 break;
5795 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5796 dev_info(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n",
5797 __func__);
5798 rtl8xxxu_set_ampdu_factor(priv, 0);
5799 rtl8xxxu_set_ampdu_min_space(priv, 0);
5800 break;
5801 case IEEE80211_AMPDU_RX_START:
5802 dev_info(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__);
5803 break;
5804 case IEEE80211_AMPDU_RX_STOP:
5805 dev_info(dev, "%s: IEEE80211_AMPDU_RX_STOP\n", __func__);
5806 break;
5807 default:
5808 break;
5809 }
5810 return 0;
5811}
5812
5813static int rtl8xxxu_start(struct ieee80211_hw *hw)
5814{
5815 struct rtl8xxxu_priv *priv = hw->priv;
5816 struct rtl8xxxu_rx_urb *rx_urb;
5817 struct rtl8xxxu_tx_urb *tx_urb;
5818 unsigned long flags;
5819 int ret, i;
5820
5821 ret = 0;
5822
5823 init_usb_anchor(&priv->rx_anchor);
5824 init_usb_anchor(&priv->tx_anchor);
5825 init_usb_anchor(&priv->int_anchor);
5826
5827 rtl8723a_enable_rf(priv);
5828 ret = rtl8xxxu_submit_int_urb(hw);
5829 if (ret)
5830 goto exit;
5831
5832 for (i = 0; i < RTL8XXXU_TX_URBS; i++) {
5833 tx_urb = kmalloc(sizeof(struct rtl8xxxu_tx_urb), GFP_KERNEL);
5834 if (!tx_urb) {
5835 if (!i)
5836 ret = -ENOMEM;
5837
5838 goto error_out;
5839 }
5840 usb_init_urb(&tx_urb->urb);
5841 INIT_LIST_HEAD(&tx_urb->list);
5842 tx_urb->hw = hw;
5843 list_add(&tx_urb->list, &priv->tx_urb_free_list);
5844 priv->tx_urb_free_count++;
5845 }
5846
5847 priv->tx_stopped = false;
5848
5849 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5850 priv->shutdown = false;
5851 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5852
5853 for (i = 0; i < RTL8XXXU_RX_URBS; i++) {
5854 rx_urb = kmalloc(sizeof(struct rtl8xxxu_rx_urb), GFP_KERNEL);
5855 if (!rx_urb) {
5856 if (!i)
5857 ret = -ENOMEM;
5858
5859 goto error_out;
5860 }
5861 usb_init_urb(&rx_urb->urb);
5862 INIT_LIST_HEAD(&rx_urb->list);
5863 rx_urb->hw = hw;
5864
5865 ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
5866 }
5867exit:
5868 /*
Bruno Randolfc85ea112016-02-03 13:39:55 -05005869 * Accept all data and mgmt frames
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005870 */
Bruno Randolfc85ea112016-02-03 13:39:55 -05005871 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff);
Jes Sorensen26f1fad2015-10-14 20:44:51 -04005872 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0xffff);
5873
5874 rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, 0x6954341e);
5875
5876 return ret;
5877
5878error_out:
5879 rtl8xxxu_free_tx_resources(priv);
5880 /*
5881 * Disable all data and mgmt frames
5882 */
5883 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
5884 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
5885
5886 return ret;
5887}
5888
5889static void rtl8xxxu_stop(struct ieee80211_hw *hw)
5890{
5891 struct rtl8xxxu_priv *priv = hw->priv;
5892 unsigned long flags;
5893
5894 rtl8xxxu_write8(priv, REG_TXPAUSE, 0xff);
5895
5896 rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000);
5897 rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000);
5898
5899 spin_lock_irqsave(&priv->rx_urb_lock, flags);
5900 priv->shutdown = true;
5901 spin_unlock_irqrestore(&priv->rx_urb_lock, flags);
5902
5903 usb_kill_anchored_urbs(&priv->rx_anchor);
5904 usb_kill_anchored_urbs(&priv->tx_anchor);
5905 usb_kill_anchored_urbs(&priv->int_anchor);
5906
5907 rtl8723a_disable_rf(priv);
5908
5909 /*
5910 * Disable interrupts
5911 */
5912 rtl8xxxu_write32(priv, REG_USB_HIMR, 0);
5913
5914 rtl8xxxu_free_rx_resources(priv);
5915 rtl8xxxu_free_tx_resources(priv);
5916}
5917
5918static const struct ieee80211_ops rtl8xxxu_ops = {
5919 .tx = rtl8xxxu_tx,
5920 .add_interface = rtl8xxxu_add_interface,
5921 .remove_interface = rtl8xxxu_remove_interface,
5922 .config = rtl8xxxu_config,
5923 .conf_tx = rtl8xxxu_conf_tx,
5924 .bss_info_changed = rtl8xxxu_bss_info_changed,
5925 .configure_filter = rtl8xxxu_configure_filter,
5926 .set_rts_threshold = rtl8xxxu_set_rts_threshold,
5927 .start = rtl8xxxu_start,
5928 .stop = rtl8xxxu_stop,
5929 .sw_scan_start = rtl8xxxu_sw_scan_start,
5930 .sw_scan_complete = rtl8xxxu_sw_scan_complete,
5931 .set_key = rtl8xxxu_set_key,
5932 .ampdu_action = rtl8xxxu_ampdu_action,
5933};
5934
5935static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,
5936 struct usb_interface *interface)
5937{
5938 struct usb_interface_descriptor *interface_desc;
5939 struct usb_host_interface *host_interface;
5940 struct usb_endpoint_descriptor *endpoint;
5941 struct device *dev = &priv->udev->dev;
5942 int i, j = 0, endpoints;
5943 u8 dir, xtype, num;
5944 int ret = 0;
5945
5946 host_interface = &interface->altsetting[0];
5947 interface_desc = &host_interface->desc;
5948 endpoints = interface_desc->bNumEndpoints;
5949
5950 for (i = 0; i < endpoints; i++) {
5951 endpoint = &host_interface->endpoint[i].desc;
5952
5953 dir = endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
5954 num = usb_endpoint_num(endpoint);
5955 xtype = usb_endpoint_type(endpoint);
5956 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
5957 dev_dbg(dev,
5958 "%s: endpoint: dir %02x, # %02x, type %02x\n",
5959 __func__, dir, num, xtype);
5960 if (usb_endpoint_dir_in(endpoint) &&
5961 usb_endpoint_xfer_bulk(endpoint)) {
5962 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
5963 dev_dbg(dev, "%s: in endpoint num %i\n",
5964 __func__, num);
5965
5966 if (priv->pipe_in) {
5967 dev_warn(dev,
5968 "%s: Too many IN pipes\n", __func__);
5969 ret = -EINVAL;
5970 goto exit;
5971 }
5972
5973 priv->pipe_in = usb_rcvbulkpipe(priv->udev, num);
5974 }
5975
5976 if (usb_endpoint_dir_in(endpoint) &&
5977 usb_endpoint_xfer_int(endpoint)) {
5978 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
5979 dev_dbg(dev, "%s: interrupt endpoint num %i\n",
5980 __func__, num);
5981
5982 if (priv->pipe_interrupt) {
5983 dev_warn(dev, "%s: Too many INTERRUPT pipes\n",
5984 __func__);
5985 ret = -EINVAL;
5986 goto exit;
5987 }
5988
5989 priv->pipe_interrupt = usb_rcvintpipe(priv->udev, num);
5990 }
5991
5992 if (usb_endpoint_dir_out(endpoint) &&
5993 usb_endpoint_xfer_bulk(endpoint)) {
5994 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_USB)
5995 dev_dbg(dev, "%s: out endpoint num %i\n",
5996 __func__, num);
5997 if (j >= RTL8XXXU_OUT_ENDPOINTS) {
5998 dev_warn(dev,
5999 "%s: Too many OUT pipes\n", __func__);
6000 ret = -EINVAL;
6001 goto exit;
6002 }
6003 priv->out_ep[j++] = num;
6004 }
6005 }
6006exit:
6007 priv->nr_out_eps = j;
6008 return ret;
6009}
6010
6011static int rtl8xxxu_probe(struct usb_interface *interface,
6012 const struct usb_device_id *id)
6013{
6014 struct rtl8xxxu_priv *priv;
6015 struct ieee80211_hw *hw;
6016 struct usb_device *udev;
6017 struct ieee80211_supported_band *sband;
6018 int ret = 0;
6019 int untested = 1;
6020
6021 udev = usb_get_dev(interface_to_usbdev(interface));
6022
6023 switch (id->idVendor) {
6024 case USB_VENDOR_ID_REALTEK:
6025 switch(id->idProduct) {
6026 case 0x1724:
6027 case 0x8176:
6028 case 0x8178:
6029 case 0x817f:
6030 untested = 0;
6031 break;
6032 }
6033 break;
6034 case 0x7392:
6035 if (id->idProduct == 0x7811)
6036 untested = 0;
6037 break;
6038 default:
6039 break;
6040 }
6041
6042 if (untested) {
6043 rtl8xxxu_debug = RTL8XXXU_DEBUG_EFUSE;
6044 dev_info(&udev->dev,
6045 "This Realtek USB WiFi dongle (0x%04x:0x%04x) is untested!\n",
6046 id->idVendor, id->idProduct);
6047 dev_info(&udev->dev,
6048 "Please report results to Jes.Sorensen@gmail.com\n");
6049 }
6050
6051 hw = ieee80211_alloc_hw(sizeof(struct rtl8xxxu_priv), &rtl8xxxu_ops);
6052 if (!hw) {
6053 ret = -ENOMEM;
6054 goto exit;
6055 }
6056
6057 priv = hw->priv;
6058 priv->hw = hw;
6059 priv->udev = udev;
6060 priv->fops = (struct rtl8xxxu_fileops *)id->driver_info;
6061 mutex_init(&priv->usb_buf_mutex);
6062 mutex_init(&priv->h2c_mutex);
6063 INIT_LIST_HEAD(&priv->tx_urb_free_list);
6064 spin_lock_init(&priv->tx_urb_lock);
6065 INIT_LIST_HEAD(&priv->rx_urb_pending_list);
6066 spin_lock_init(&priv->rx_urb_lock);
6067 INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);
6068
6069 usb_set_intfdata(interface, hw);
6070
6071 ret = rtl8xxxu_parse_usb(priv, interface);
6072 if (ret)
6073 goto exit;
6074
6075 ret = rtl8xxxu_identify_chip(priv);
6076 if (ret) {
6077 dev_err(&udev->dev, "Fatal - failed to identify chip\n");
6078 goto exit;
6079 }
6080
6081 ret = rtl8xxxu_read_efuse(priv);
6082 if (ret) {
6083 dev_err(&udev->dev, "Fatal - failed to read EFuse\n");
6084 goto exit;
6085 }
6086
6087 ret = priv->fops->parse_efuse(priv);
6088 if (ret) {
6089 dev_err(&udev->dev, "Fatal - failed to parse EFuse\n");
6090 goto exit;
6091 }
6092
6093 rtl8xxxu_print_chipinfo(priv);
6094
6095 ret = priv->fops->load_firmware(priv);
6096 if (ret) {
6097 dev_err(&udev->dev, "Fatal - failed to load firmware\n");
6098 goto exit;
6099 }
6100
6101 ret = rtl8xxxu_init_device(hw);
6102
6103 hw->wiphy->max_scan_ssids = 1;
6104 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
6105 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
6106 hw->queues = 4;
6107
6108 sband = &rtl8xxxu_supported_band;
6109 sband->ht_cap.ht_supported = true;
6110 sband->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6111 sband->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
6112 sband->ht_cap.cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40;
6113 memset(&sband->ht_cap.mcs, 0, sizeof(sband->ht_cap.mcs));
6114 sband->ht_cap.mcs.rx_mask[0] = 0xff;
6115 sband->ht_cap.mcs.rx_mask[4] = 0x01;
6116 if (priv->rf_paths > 1) {
6117 sband->ht_cap.mcs.rx_mask[1] = 0xff;
6118 sband->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6119 }
6120 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
6121 /*
6122 * Some APs will negotiate HT20_40 in a noisy environment leading
6123 * to miserable performance. Rather than defaulting to this, only
6124 * enable it if explicitly requested at module load time.
6125 */
6126 if (rtl8xxxu_ht40_2g) {
6127 dev_info(&udev->dev, "Enabling HT_20_40 on the 2.4GHz band\n");
6128 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6129 }
6130 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
6131
6132 hw->wiphy->rts_threshold = 2347;
6133
6134 SET_IEEE80211_DEV(priv->hw, &interface->dev);
6135 SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr);
6136
6137 hw->extra_tx_headroom = sizeof(struct rtl8xxxu_tx_desc);
6138 ieee80211_hw_set(hw, SIGNAL_DBM);
6139 /*
6140 * The firmware handles rate control
6141 */
6142 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
6143 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
6144
6145 ret = ieee80211_register_hw(priv->hw);
6146 if (ret) {
6147 dev_err(&udev->dev, "%s: Failed to register: %i\n",
6148 __func__, ret);
6149 goto exit;
6150 }
6151
6152exit:
6153 if (ret < 0)
6154 usb_put_dev(udev);
6155 return ret;
6156}
6157
6158static void rtl8xxxu_disconnect(struct usb_interface *interface)
6159{
6160 struct rtl8xxxu_priv *priv;
6161 struct ieee80211_hw *hw;
6162
6163 hw = usb_get_intfdata(interface);
6164 priv = hw->priv;
6165
6166 rtl8xxxu_disable_device(hw);
6167 usb_set_intfdata(interface, NULL);
6168
6169 dev_info(&priv->udev->dev, "disconnecting\n");
6170
6171 ieee80211_unregister_hw(hw);
6172
6173 kfree(priv->fw_data);
6174 mutex_destroy(&priv->usb_buf_mutex);
6175 mutex_destroy(&priv->h2c_mutex);
6176
6177 usb_put_dev(priv->udev);
6178 ieee80211_free_hw(hw);
6179}
6180
6181static struct rtl8xxxu_fileops rtl8723au_fops = {
6182 .parse_efuse = rtl8723au_parse_efuse,
6183 .load_firmware = rtl8723au_load_firmware,
6184 .power_on = rtl8723au_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006185 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006186 .writeN_block_size = 1024,
6187};
6188
Jes Sorensen35a741f2016-02-29 17:04:10 -05006189static struct rtl8xxxu_fileops rtl8723bu_fops = {
Jes Sorensen3c836d62016-02-29 17:04:11 -05006190 .parse_efuse = rtl8723bu_parse_efuse,
Jes Sorensen35a741f2016-02-29 17:04:10 -05006191 .load_firmware = rtl8723bu_load_firmware,
6192 .power_on = rtl8723au_power_on,
6193 .llt_init = rtl8xxxu_auto_llt_table,
6194 .writeN_block_size = 128,
6195};
6196
Kalle Valoc0963772015-10-25 18:24:38 +02006197#ifdef CONFIG_RTL8XXXU_UNTESTED
6198
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006199static struct rtl8xxxu_fileops rtl8192cu_fops = {
6200 .parse_efuse = rtl8192cu_parse_efuse,
6201 .load_firmware = rtl8192cu_load_firmware,
6202 .power_on = rtl8192cu_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006203 .llt_init = rtl8xxxu_init_llt_table,
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006204 .writeN_block_size = 128,
6205};
6206
Kalle Valoc0963772015-10-25 18:24:38 +02006207#endif
6208
Jes Sorensen3307d842016-02-29 17:03:59 -05006209static struct rtl8xxxu_fileops rtl8192eu_fops = {
6210 .parse_efuse = rtl8192eu_parse_efuse,
6211 .load_firmware = rtl8192eu_load_firmware,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006212 .power_on = rtl8192eu_power_on,
Jes Sorensen74b99be2016-02-29 17:04:04 -05006213 .llt_init = rtl8xxxu_auto_llt_table,
Jes Sorensenc05a9db2016-02-29 17:04:03 -05006214 .writeN_block_size = 128,
Jes Sorensen3307d842016-02-29 17:03:59 -05006215};
6216
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006217static struct usb_device_id dev_table[] = {
6218{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8724, 0xff, 0xff, 0xff),
6219 .driver_info = (unsigned long)&rtl8723au_fops},
6220{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1724, 0xff, 0xff, 0xff),
6221 .driver_info = (unsigned long)&rtl8723au_fops},
6222{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x0724, 0xff, 0xff, 0xff),
6223 .driver_info = (unsigned long)&rtl8723au_fops},
Jes Sorensen3307d842016-02-29 17:03:59 -05006224{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818b, 0xff, 0xff, 0xff),
6225 .driver_info = (unsigned long)&rtl8192eu_fops},
Jes Sorensen35a741f2016-02-29 17:04:10 -05006226{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff),
6227 .driver_info = (unsigned long)&rtl8723bu_fops},
Kalle Valo033695b2015-10-23 20:27:58 +03006228#ifdef CONFIG_RTL8XXXU_UNTESTED
6229/* Still supported by rtlwifi */
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006230{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff),
6231 .driver_info = (unsigned long)&rtl8192cu_fops},
6232{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8178, 0xff, 0xff, 0xff),
6233 .driver_info = (unsigned long)&rtl8192cu_fops},
6234{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817f, 0xff, 0xff, 0xff),
6235 .driver_info = (unsigned long)&rtl8192cu_fops},
6236/* Tested by Larry Finger */
6237{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7811, 0xff, 0xff, 0xff),
6238 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006239/* Currently untested 8188 series devices */
6240{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff),
6241 .driver_info = (unsigned long)&rtl8192cu_fops},
6242{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff),
6243 .driver_info = (unsigned long)&rtl8192cu_fops},
6244{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8177, 0xff, 0xff, 0xff),
6245 .driver_info = (unsigned long)&rtl8192cu_fops},
6246{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817a, 0xff, 0xff, 0xff),
6247 .driver_info = (unsigned long)&rtl8192cu_fops},
6248{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817b, 0xff, 0xff, 0xff),
6249 .driver_info = (unsigned long)&rtl8192cu_fops},
6250{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817d, 0xff, 0xff, 0xff),
6251 .driver_info = (unsigned long)&rtl8192cu_fops},
6252{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x817e, 0xff, 0xff, 0xff),
6253 .driver_info = (unsigned long)&rtl8192cu_fops},
6254{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x818a, 0xff, 0xff, 0xff),
6255 .driver_info = (unsigned long)&rtl8192cu_fops},
6256{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x317f, 0xff, 0xff, 0xff),
6257 .driver_info = (unsigned long)&rtl8192cu_fops},
6258{USB_DEVICE_AND_INTERFACE_INFO(0x1058, 0x0631, 0xff, 0xff, 0xff),
6259 .driver_info = (unsigned long)&rtl8192cu_fops},
6260{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x094c, 0xff, 0xff, 0xff),
6261 .driver_info = (unsigned long)&rtl8192cu_fops},
6262{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1102, 0xff, 0xff, 0xff),
6263 .driver_info = (unsigned long)&rtl8192cu_fops},
6264{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe033, 0xff, 0xff, 0xff),
6265 .driver_info = (unsigned long)&rtl8192cu_fops},
6266{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8189, 0xff, 0xff, 0xff),
6267 .driver_info = (unsigned long)&rtl8192cu_fops},
6268{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9041, 0xff, 0xff, 0xff),
6269 .driver_info = (unsigned long)&rtl8192cu_fops},
6270{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ba, 0xff, 0xff, 0xff),
6271 .driver_info = (unsigned long)&rtl8192cu_fops},
6272{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x1e1e, 0xff, 0xff, 0xff),
6273 .driver_info = (unsigned long)&rtl8192cu_fops},
6274{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x5088, 0xff, 0xff, 0xff),
6275 .driver_info = (unsigned long)&rtl8192cu_fops},
6276{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0052, 0xff, 0xff, 0xff),
6277 .driver_info = (unsigned long)&rtl8192cu_fops},
6278{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x005c, 0xff, 0xff, 0xff),
6279 .driver_info = (unsigned long)&rtl8192cu_fops},
6280{USB_DEVICE_AND_INTERFACE_INFO(0x0eb0, 0x9071, 0xff, 0xff, 0xff),
6281 .driver_info = (unsigned long)&rtl8192cu_fops},
6282{USB_DEVICE_AND_INTERFACE_INFO(0x103c, 0x1629, 0xff, 0xff, 0xff),
6283 .driver_info = (unsigned long)&rtl8192cu_fops},
6284{USB_DEVICE_AND_INTERFACE_INFO(0x13d3, 0x3357, 0xff, 0xff, 0xff),
6285 .driver_info = (unsigned long)&rtl8192cu_fops},
6286{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff),
6287 .driver_info = (unsigned long)&rtl8192cu_fops},
6288{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330b, 0xff, 0xff, 0xff),
6289 .driver_info = (unsigned long)&rtl8192cu_fops},
6290{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x4902, 0xff, 0xff, 0xff),
6291 .driver_info = (unsigned long)&rtl8192cu_fops},
6292{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2a, 0xff, 0xff, 0xff),
6293 .driver_info = (unsigned long)&rtl8192cu_fops},
6294{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2e, 0xff, 0xff, 0xff),
6295 .driver_info = (unsigned long)&rtl8192cu_fops},
6296{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xed17, 0xff, 0xff, 0xff),
6297 .driver_info = (unsigned long)&rtl8192cu_fops},
6298{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x648b, 0xff, 0xff, 0xff),
6299 .driver_info = (unsigned long)&rtl8192cu_fops},
6300{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0090, 0xff, 0xff, 0xff),
6301 .driver_info = (unsigned long)&rtl8192cu_fops},
6302{USB_DEVICE_AND_INTERFACE_INFO(0x4856, 0x0091, 0xff, 0xff, 0xff),
6303 .driver_info = (unsigned long)&rtl8192cu_fops},
6304{USB_DEVICE_AND_INTERFACE_INFO(0xcdab, 0x8010, 0xff, 0xff, 0xff),
6305 .driver_info = (unsigned long)&rtl8192cu_fops},
Jes Sorensen26f1fad2015-10-14 20:44:51 -04006306{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff7, 0xff, 0xff, 0xff),
6307 .driver_info = (unsigned long)&rtl8192cu_fops},
6308{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff9, 0xff, 0xff, 0xff),
6309 .driver_info = (unsigned long)&rtl8192cu_fops},
6310{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffa, 0xff, 0xff, 0xff),
6311 .driver_info = (unsigned long)&rtl8192cu_fops},
6312{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaff8, 0xff, 0xff, 0xff),
6313 .driver_info = (unsigned long)&rtl8192cu_fops},
6314{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffb, 0xff, 0xff, 0xff),
6315 .driver_info = (unsigned long)&rtl8192cu_fops},
6316{USB_DEVICE_AND_INTERFACE_INFO(0x04f2, 0xaffc, 0xff, 0xff, 0xff),
6317 .driver_info = (unsigned long)&rtl8192cu_fops},
6318{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0x1201, 0xff, 0xff, 0xff),
6319 .driver_info = (unsigned long)&rtl8192cu_fops},
6320/* Currently untested 8192 series devices */
6321{USB_DEVICE_AND_INTERFACE_INFO(0x04bb, 0x0950, 0xff, 0xff, 0xff),
6322 .driver_info = (unsigned long)&rtl8192cu_fops},
6323{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x1004, 0xff, 0xff, 0xff),
6324 .driver_info = (unsigned long)&rtl8192cu_fops},
6325{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2102, 0xff, 0xff, 0xff),
6326 .driver_info = (unsigned long)&rtl8192cu_fops},
6327{USB_DEVICE_AND_INTERFACE_INFO(0x050d, 0x2103, 0xff, 0xff, 0xff),
6328 .driver_info = (unsigned long)&rtl8192cu_fops},
6329{USB_DEVICE_AND_INTERFACE_INFO(0x0586, 0x341f, 0xff, 0xff, 0xff),
6330 .driver_info = (unsigned long)&rtl8192cu_fops},
6331{USB_DEVICE_AND_INTERFACE_INFO(0x06f8, 0xe035, 0xff, 0xff, 0xff),
6332 .driver_info = (unsigned long)&rtl8192cu_fops},
6333{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x17ab, 0xff, 0xff, 0xff),
6334 .driver_info = (unsigned long)&rtl8192cu_fops},
6335{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0061, 0xff, 0xff, 0xff),
6336 .driver_info = (unsigned long)&rtl8192cu_fops},
6337{USB_DEVICE_AND_INTERFACE_INFO(0x0df6, 0x0070, 0xff, 0xff, 0xff),
6338 .driver_info = (unsigned long)&rtl8192cu_fops},
6339{USB_DEVICE_AND_INTERFACE_INFO(0x0789, 0x016d, 0xff, 0xff, 0xff),
6340 .driver_info = (unsigned long)&rtl8192cu_fops},
6341{USB_DEVICE_AND_INTERFACE_INFO(0x07aa, 0x0056, 0xff, 0xff, 0xff),
6342 .driver_info = (unsigned long)&rtl8192cu_fops},
6343{USB_DEVICE_AND_INTERFACE_INFO(0x07b8, 0x8178, 0xff, 0xff, 0xff),
6344 .driver_info = (unsigned long)&rtl8192cu_fops},
6345{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9021, 0xff, 0xff, 0xff),
6346 .driver_info = (unsigned long)&rtl8192cu_fops},
6347{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0xf001, 0xff, 0xff, 0xff),
6348 .driver_info = (unsigned long)&rtl8192cu_fops},
6349{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x2e2e, 0xff, 0xff, 0xff),
6350 .driver_info = (unsigned long)&rtl8192cu_fops},
6351{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0019, 0xff, 0xff, 0xff),
6352 .driver_info = (unsigned long)&rtl8192cu_fops},
6353{USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0020, 0xff, 0xff, 0xff),
6354 .driver_info = (unsigned long)&rtl8192cu_fops},
6355{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3307, 0xff, 0xff, 0xff),
6356 .driver_info = (unsigned long)&rtl8192cu_fops},
6357{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3309, 0xff, 0xff, 0xff),
6358 .driver_info = (unsigned long)&rtl8192cu_fops},
6359{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x330a, 0xff, 0xff, 0xff),
6360 .driver_info = (unsigned long)&rtl8192cu_fops},
6361{USB_DEVICE_AND_INTERFACE_INFO(0x2019, 0xab2b, 0xff, 0xff, 0xff),
6362 .driver_info = (unsigned long)&rtl8192cu_fops},
6363{USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x624d, 0xff, 0xff, 0xff),
6364 .driver_info = (unsigned long)&rtl8192cu_fops},
6365{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0100, 0xff, 0xff, 0xff),
6366 .driver_info = (unsigned long)&rtl8192cu_fops},
6367{USB_DEVICE_AND_INTERFACE_INFO(0x4855, 0x0091, 0xff, 0xff, 0xff),
6368 .driver_info = (unsigned long)&rtl8192cu_fops},
6369{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0x7822, 0xff, 0xff, 0xff),
6370 .driver_info = (unsigned long)&rtl8192cu_fops},
6371#endif
6372{ }
6373};
6374
6375static struct usb_driver rtl8xxxu_driver = {
6376 .name = DRIVER_NAME,
6377 .probe = rtl8xxxu_probe,
6378 .disconnect = rtl8xxxu_disconnect,
6379 .id_table = dev_table,
6380 .disable_hub_initiated_lpm = 1,
6381};
6382
6383static int __init rtl8xxxu_module_init(void)
6384{
6385 int res;
6386
6387 res = usb_register(&rtl8xxxu_driver);
6388 if (res < 0)
6389 pr_err(DRIVER_NAME ": usb_register() failed (%i)\n", res);
6390
6391 return res;
6392}
6393
6394static void __exit rtl8xxxu_module_exit(void)
6395{
6396 usb_deregister(&rtl8xxxu_driver);
6397}
6398
6399
6400MODULE_DEVICE_TABLE(usb, dev_table);
6401
6402module_init(rtl8xxxu_module_init);
6403module_exit(rtl8xxxu_module_exit);