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