// SPDX-License-Identifier: GPL-2.0-only
/*
* RTL8XXXU mac80211 USB driver - 8188e specific subdriver
*
* Copyright (c) 2014 - 2016 Jes Sorensen <Jes.Sorensen@gmail.com>
*
* Portions, notably calibration code:
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This driver was written as a replacement for the vendor provided
* rtl8723au driver. As the Realtek 8xxx chips are very similar in
* their programming interface, I have started adding support for
* additional 8xxx chips like the 8192cu, 8188cus, etc.
*/
#include "regs.h"
#include "rtl8xxxu.h"
static const struct rtl8xxxu_reg8val rtl8188e_mac_init_table[] = {
{0 x026, 0 x41}, {0 x027, 0 x35}, {0 x040, 0 x00}, {0 x421, 0 x0f},
{0 x428, 0 x0a}, {0 x429, 0 x10}, {0 x430, 0 x00}, {0 x431, 0 x01},
{0 x432, 0 x02}, {0 x433, 0 x04}, {0 x434, 0 x05}, {0 x435, 0 x06},
{0 x436, 0 x07}, {0 x437, 0 x08}, {0 x438, 0 x00}, {0 x439, 0 x00},
{0 x43a, 0 x01}, {0 x43b, 0 x02}, {0 x43c, 0 x04}, {0 x43d, 0 x05},
{0 x43e, 0 x06}, {0 x43f, 0 x07}, {0 x440, 0 x5d}, {0 x441, 0 x01},
{0 x442, 0 x00}, {0 x444, 0 x15}, {0 x445, 0 xf0}, {0 x446, 0 x0f},
{0 x447, 0 x00}, {0 x458, 0 x41}, {0 x459, 0 xa8}, {0 x45a, 0 x72},
{0 x45b, 0 xb9}, {0 x460, 0 x66}, {0 x461, 0 x66}, {0 x480, 0 x08},
{0 x4c8, 0 xff}, {0 x4c9, 0 x08}, {0 x4cc, 0 xff}, {0 x4cd, 0 xff},
{0 x4ce, 0 x01}, {0 x4d3, 0 x01}, {0 x500, 0 x26}, {0 x501, 0 xa2},
{0 x502, 0 x2f}, {0 x503, 0 x00}, {0 x504, 0 x28}, {0 x505, 0 xa3},
{0 x506, 0 x5e}, {0 x507, 0 x00}, {0 x508, 0 x2b}, {0 x509, 0 xa4},
{0 x50a, 0 x5e}, {0 x50b, 0 x00}, {0 x50c, 0 x4f}, {0 x50d, 0 xa4},
{0 x50e, 0 x00}, {0 x50f, 0 x00}, {0 x512, 0 x1c}, {0 x514, 0 x0a},
{0 x516, 0 x0a}, {0 x525, 0 x4f}, {0 x550, 0 x10}, {0 x551, 0 x10},
{0 x559, 0 x02}, {0 x55d, 0 xff}, {0 x605, 0 x30}, {0 x608, 0 x0e},
{0 x609, 0 x2a}, {0 x620, 0 xff}, {0 x621, 0 xff}, {0 x622, 0 xff},
{0 x623, 0 xff}, {0 x624, 0 xff}, {0 x625, 0 xff}, {0 x626, 0 xff},
{0 x627, 0 xff}, {0 x63c, 0 x08}, {0 x63d, 0 x08}, {0 x63e, 0 x0c},
{0 x63f, 0 x0c}, {0 x640, 0 x40}, {0 x652, 0 x20}, {0 x66e, 0 x05},
{0 x700, 0 x21}, {0 x701, 0 x43}, {0 x702, 0 x65}, {0 x703, 0 x87},
{0 x708, 0 x21}, {0 x709, 0 x43}, {0 x70a, 0 x65}, {0 x70b, 0 x87},
{0 xffff, 0 xff},
};
static const struct rtl8xxxu_reg32val rtl8188eu_phy_init_table[] = {
{0 x800, 0 x80040000}, {0 x804, 0 x00000003},
{0 x808, 0 x0000fc00}, {0 x80c, 0 x0000000a},
{0 x810, 0 x10001331}, {0 x814, 0 x020c3d10},
{0 x818, 0 x02200385}, {0 x81c, 0 x00000000},
{0 x820, 0 x01000100}, {0 x824, 0 x00390204},
{0 x828, 0 x00000000}, {0 x82c, 0 x00000000},
{0 x830, 0 x00000000}, {0 x834, 0 x00000000},
{0 x838, 0 x00000000}, {0 x83c, 0 x00000000},
{0 x840, 0 x00010000}, {0 x844, 0 x00000000},
{0 x848, 0 x00000000}, {0 x84c, 0 x00000000},
{0 x850, 0 x00000000}, {0 x854, 0 x00000000},
{0 x858, 0 x569a11a9}, {0 x85c, 0 x01000014},
{0 x860, 0 x66f60110}, {0 x864, 0 x061f0649},
{0 x868, 0 x00000000}, {0 x86c, 0 x27272700},
{0 x870, 0 x07000760}, {0 x874, 0 x25004000},
{0 x878, 0 x00000808}, {0 x87c, 0 x00000000},
{0 x880, 0 xb0000c1c}, {0 x884, 0 x00000001},
{0 x888, 0 x00000000}, {0 x88c, 0 xccc000c0},
{0 x890, 0 x00000800}, {0 x894, 0 xfffffffe},
{0 x898, 0 x40302010}, {0 x89c, 0 x00706050},
{0 x900, 0 x00000000}, {0 x904, 0 x00000023},
{0 x908, 0 x00000000}, {0 x90c, 0 x81121111},
{0 x910, 0 x00000002}, {0 x914, 0 x00000201},
{0 xa00, 0 x00d047c8}, {0 xa04, 0 x80ff800c},
{0 xa08, 0 x8c838300}, {0 xa0c, 0 x2e7f120f},
{0 xa10, 0 x9500bb7e}, {0 xa14, 0 x1114d028},
{0 xa18, 0 x00881117}, {0 xa1c, 0 x89140f00},
{0 xa20, 0 x1a1b0000}, {0 xa24, 0 x090e1317},
{0 xa28, 0 x00000204}, {0 xa2c, 0 x00d30000},
{0 xa70, 0 x101fbf00}, {0 xa74, 0 x00000007},
{0 xa78, 0 x00000900}, {0 xa7c, 0 x225b0606},
{0 xa80, 0 x218075b1}, {0 xb2c, 0 x80000000},
{0 xc00, 0 x48071d40}, {0 xc04, 0 x03a05611},
{0 xc08, 0 x000000e4}, {0 xc0c, 0 x6c6c6c6c},
{0 xc10, 0 x08800000}, {0 xc14, 0 x40000100},
{0 xc18, 0 x08800000}, {0 xc1c, 0 x40000100},
{0 xc20, 0 x00000000}, {0 xc24, 0 x00000000},
{0 xc28, 0 x00000000}, {0 xc2c, 0 x00000000},
{0 xc30, 0 x69e9ac47}, {0 xc34, 0 x469652af},
{0 xc38, 0 x49795994}, {0 xc3c, 0 x0a97971c},
{0 xc40, 0 x1f7c403f}, {0 xc44, 0 x000100b7},
{0 xc48, 0 xec020107}, {0 xc4c, 0 x007f037f},
{0 xc50, 0 x69553420}, {0 xc54, 0 x43bc0094},
{0 xc58, 0 x00013169}, {0 xc5c, 0 x00250492},
{0 xc60, 0 x00000000}, {0 xc64, 0 x7112848b},
{0 xc68, 0 x47c00bff}, {0 xc6c, 0 x00000036},
{0 xc70, 0 x2c7f000d}, {0 xc74, 0 x020610db},
{0 xc78, 0 x0000001f}, {0 xc7c, 0 x00b91612},
{0 xc80, 0 x390000e4}, {0 xc84, 0 x21f60000},
{0 xc88, 0 x40000100}, {0 xc8c, 0 x20200000},
{0 xc90, 0 x00091521}, {0 xc94, 0 x00000000},
{0 xc98, 0 x00121820}, {0 xc9c, 0 x00007f7f},
{0 xca0, 0 x00000000}, {0 xca4, 0 x000300a0},
{0 xca8, 0 x00000000}, {0 xcac, 0 x00000000},
{0 xcb0, 0 x00000000}, {0 xcb4, 0 x00000000},
{0 xcb8, 0 x00000000}, {0 xcbc, 0 x28000000},
{0 xcc0, 0 x00000000}, {0 xcc4, 0 x00000000},
{0 xcc8, 0 x00000000}, {0 xccc, 0 x00000000},
{0 xcd0, 0 x00000000}, {0 xcd4, 0 x00000000},
{0 xcd8, 0 x64b22427}, {0 xcdc, 0 x00766932},
{0 xce0, 0 x00222222}, {0 xce4, 0 x00000000},
{0 xce8, 0 x37644302}, {0 xcec, 0 x2f97d40c},
{0 xd00, 0 x00000740}, {0 xd04, 0 x00020401},
{0 xd08, 0 x0000907f}, {0 xd0c, 0 x20010201},
{0 xd10, 0 xa0633333}, {0 xd14, 0 x3333bc43},
{0 xd18, 0 x7a8f5b6f}, {0 xd2c, 0 xcc979975},
{0 xd30, 0 x00000000}, {0 xd34, 0 x80608000},
{0 xd38, 0 x00000000}, {0 xd3c, 0 x00127353},
{0 xd40, 0 x00000000}, {0 xd44, 0 x00000000},
{0 xd48, 0 x00000000}, {0 xd4c, 0 x00000000},
{0 xd50, 0 x6437140a}, {0 xd54, 0 x00000000},
{0 xd58, 0 x00000282}, {0 xd5c, 0 x30032064},
{0 xd60, 0 x4653de68}, {0 xd64, 0 x04518a3c},
{0 xd68, 0 x00002101}, {0 xd6c, 0 x2a201c16},
{0 xd70, 0 x1812362e}, {0 xd74, 0 x322c2220},
{0 xd78, 0 x000e3c24}, {0 xe00, 0 x2d2d2d2d},
{0 xe04, 0 x2d2d2d2d}, {0 xe08, 0 x0390272d},
{0 xe10, 0 x2d2d2d2d}, {0 xe14, 0 x2d2d2d2d},
{0 xe18, 0 x2d2d2d2d}, {0 xe1c, 0 x2d2d2d2d},
{0 xe28, 0 x00000000}, {0 xe30, 0 x1000dc1f},
{0 xe34, 0 x10008c1f}, {0 xe38, 0 x02140102},
{0 xe3c, 0 x681604c2}, {0 xe40, 0 x01007c00},
{0 xe44, 0 x01004800}, {0 xe48, 0 xfb000000},
{0 xe4c, 0 x000028d1}, {0 xe50, 0 x1000dc1f},
{0 xe54, 0 x10008c1f}, {0 xe58, 0 x02140102},
{0 xe5c, 0 x28160d05}, {0 xe60, 0 x00000048},
{0 xe68, 0 x001b25a4}, {0 xe6c, 0 x00c00014},
{0 xe70, 0 x00c00014}, {0 xe74, 0 x01000014},
{0 xe78, 0 x01000014}, {0 xe7c, 0 x01000014},
{0 xe80, 0 x01000014}, {0 xe84, 0 x00c00014},
{0 xe88, 0 x01000014}, {0 xe8c, 0 x00c00014},
{0 xed0, 0 x00c00014}, {0 xed4, 0 x00c00014},
{0 xed8, 0 x00c00014}, {0 xedc, 0 x00000014},
{0 xee0, 0 x00000014}, {0 xee8, 0 x21555448},
{0 xeec, 0 x01c00014}, {0 xf14, 0 x00000003},
{0 xf4c, 0 x00000000}, {0 xf00, 0 x00000300},
{0 xffff, 0 xffffffff},
};
static const struct rtl8xxxu_reg32val rtl8188e_agc_table[] = {
{0 xc78, 0 xfb000001}, {0 xc78, 0 xfb010001},
{0 xc78, 0 xfb020001}, {0 xc78, 0 xfb030001},
{0 xc78, 0 xfb040001}, {0 xc78, 0 xfb050001},
{0 xc78, 0 xfa060001}, {0 xc78, 0 xf9070001},
{0 xc78, 0 xf8080001}, {0 xc78, 0 xf7090001},
{0 xc78, 0 xf60a0001}, {0 xc78, 0 xf50b0001},
{0 xc78, 0 xf40c0001}, {0 xc78, 0 xf30d0001},
{0 xc78, 0 xf20e0001}, {0 xc78, 0 xf10f0001},
{0 xc78, 0 xf0100001}, {0 xc78, 0 xef110001},
{0 xc78, 0 xee120001}, {0 xc78, 0 xed130001},
{0 xc78, 0 xec140001}, {0 xc78, 0 xeb150001},
{0 xc78, 0 xea160001}, {0 xc78, 0 xe9170001},
{0 xc78, 0 xe8180001}, {0 xc78, 0 xe7190001},
{0 xc78, 0 xe61a0001}, {0 xc78, 0 xe51b0001},
{0 xc78, 0 xe41c0001}, {0 xc78, 0 xe31d0001},
{0 xc78, 0 xe21e0001}, {0 xc78, 0 xe11f0001},
{0 xc78, 0 x8a200001}, {0 xc78, 0 x89210001},
{0 xc78, 0 x88220001}, {0 xc78, 0 x87230001},
{0 xc78, 0 x86240001}, {0 xc78, 0 x85250001},
{0 xc78, 0 x84260001}, {0 xc78, 0 x83270001},
{0 xc78, 0 x82280001}, {0 xc78, 0 x6b290001},
{0 xc78, 0 x6a2a0001}, {0 xc78, 0 x692b0001},
{0 xc78, 0 x682c0001}, {0 xc78, 0 x672d0001},
{0 xc78, 0 x662e0001}, {0 xc78, 0 x652f0001},
{0 xc78, 0 x64300001}, {0 xc78, 0 x63310001},
{0 xc78, 0 x62320001}, {0 xc78, 0 x61330001},
{0 xc78, 0 x46340001}, {0 xc78, 0 x45350001},
{0 xc78, 0 x44360001}, {0 xc78, 0 x43370001},
{0 xc78, 0 x42380001}, {0 xc78, 0 x41390001},
{0 xc78, 0 x403a0001}, {0 xc78, 0 x403b0001},
{0 xc78, 0 x403c0001}, {0 xc78, 0 x403d0001},
{0 xc78, 0 x403e0001}, {0 xc78, 0 x403f0001},
{0 xc78, 0 xfb400001}, {0 xc78, 0 xfb410001},
{0 xc78, 0 xfb420001}, {0 xc78, 0 xfb430001},
{0 xc78, 0 xfb440001}, {0 xc78, 0 xfb450001},
{0 xc78, 0 xfb460001}, {0 xc78, 0 xfb470001},
{0 xc78, 0 xfb480001}, {0 xc78, 0 xfa490001},
{0 xc78, 0 xf94a0001}, {0 xc78, 0 xf84b0001},
{0 xc78, 0 xf74c0001}, {0 xc78, 0 xf64d0001},
{0 xc78, 0 xf54e0001}, {0 xc78, 0 xf44f0001},
{0 xc78, 0 xf3500001}, {0 xc78, 0 xf2510001},
{0 xc78, 0 xf1520001}, {0 xc78, 0 xf0530001},
{0 xc78, 0 xef540001}, {0 xc78, 0 xee550001},
{0 xc78, 0 xed560001}, {0 xc78, 0 xec570001},
{0 xc78, 0 xeb580001}, {0 xc78, 0 xea590001},
{0 xc78, 0 xe95a0001}, {0 xc78, 0 xe85b0001},
{0 xc78, 0 xe75c0001}, {0 xc78, 0 xe65d0001},
{0 xc78, 0 xe55e0001}, {0 xc78, 0 xe45f0001},
{0 xc78, 0 xe3600001}, {0 xc78, 0 xe2610001},
{0 xc78, 0 xc3620001}, {0 xc78, 0 xc2630001},
{0 xc78, 0 xc1640001}, {0 xc78, 0 x8b650001},
{0 xc78, 0 x8a660001}, {0 xc78, 0 x89670001},
{0 xc78, 0 x88680001}, {0 xc78, 0 x87690001},
{0 xc78, 0 x866a0001}, {0 xc78, 0 x856b0001},
{0 xc78, 0 x846c0001}, {0 xc78, 0 x676d0001},
{0 xc78, 0 x666e0001}, {0 xc78, 0 x656f0001},
{0 xc78, 0 x64700001}, {0 xc78, 0 x63710001},
{0 xc78, 0 x62720001}, {0 xc78, 0 x61730001},
{0 xc78, 0 x60740001}, {0 xc78, 0 x46750001},
{0 xc78, 0 x45760001}, {0 xc78, 0 x44770001},
{0 xc78, 0 x43780001}, {0 xc78, 0 x42790001},
{0 xc78, 0 x417a0001}, {0 xc78, 0 x407b0001},
{0 xc78, 0 x407c0001}, {0 xc78, 0 x407d0001},
{0 xc78, 0 x407e0001}, {0 xc78, 0 x407f0001},
{0 xc50, 0 x69553422}, {0 xc50, 0 x69553420},
{0 xffff, 0 xffffffff}
};
static const struct rtl8xxxu_rfregval rtl8188eu_radioa_init_table[] = {
{0 x00, 0 x00030000}, {0 x08, 0 x00084000},
{0 x18, 0 x00000407}, {0 x19, 0 x00000012},
{0 x1e, 0 x00080009}, {0 x1f, 0 x00000880},
{0 x2f, 0 x0001a060}, {0 x3f, 0 x00000000},
{0 x42, 0 x000060c0}, {0 x57, 0 x000d0000},
{0 x58, 0 x000be180}, {0 x67, 0 x00001552},
{0 x83, 0 x00000000}, {0 xb0, 0 x000ff8fc},
{0 xb1, 0 x00054400}, {0 xb2, 0 x000ccc19},
{0 xb4, 0 x00043003}, {0 xb6, 0 x0004953e},
{0 xb7, 0 x0001c718}, {0 xb8, 0 x000060ff},
{0 xb9, 0 x00080001}, {0 xba, 0 x00040000},
{0 xbb, 0 x00000400}, {0 xbf, 0 x000c0000},
{0 xc2, 0 x00002400}, {0 xc3, 0 x00000009},
{0 xc4, 0 x00040c91}, {0 xc5, 0 x00099999},
{0 xc6, 0 x000000a3}, {0 xc7, 0 x00088820},
{0 xc8, 0 x00076c06}, {0 xc9, 0 x00000000},
{0 xca, 0 x00080000}, {0 xdf, 0 x00000180},
{0 xef, 0 x000001a0}, {0 x51, 0 x0006b27d},
{0 x52, 0 x0007e49d}, /* Set to 0x0007e4dd for SDIO */
{0 x53, 0 x00000073}, {0 x56, 0 x00051ff3},
{0 x35, 0 x00000086}, {0 x35, 0 x00000186},
{0 x35, 0 x00000286}, {0 x36, 0 x00001c25},
{0 x36, 0 x00009c25}, {0 x36, 0 x00011c25},
{0 x36, 0 x00019c25}, {0 xb6, 0 x00048538},
{0 x18, 0 x00000c07}, {0 x5a, 0 x0004bd00},
{0 x19, 0 x000739d0}, {0 x34, 0 x0000adf3},
{0 x34, 0 x00009df0}, {0 x34, 0 x00008ded},
{0 x34, 0 x00007dea}, {0 x34, 0 x00006de7},
{0 x34, 0 x000054ee}, {0 x34, 0 x000044eb},
{0 x34, 0 x000034e8}, {0 x34, 0 x0000246b},
{0 x34, 0 x00001468}, {0 x34, 0 x0000006d},
{0 x00, 0 x00030159}, {0 x84, 0 x00068200},
{0 x86, 0 x000000ce}, {0 x87, 0 x00048a00},
{0 x8e, 0 x00065540}, {0 x8f, 0 x00088000},
{0 xef, 0 x000020a0}, {0 x3b, 0 x000f02b0},
{0 x3b, 0 x000ef7b0}, {0 x3b, 0 x000d4fb0},
{0 x3b, 0 x000cf060}, {0 x3b, 0 x000b0090},
{0 x3b, 0 x000a0080}, {0 x3b, 0 x00090080},
{0 x3b, 0 x0008f780}, {0 x3b, 0 x000722b0},
{0 x3b, 0 x0006f7b0}, {0 x3b, 0 x00054fb0},
{0 x3b, 0 x0004f060}, {0 x3b, 0 x00030090},
{0 x3b, 0 x00020080}, {0 x3b, 0 x00010080},
{0 x3b, 0 x0000f780}, {0 xef, 0 x000000a0},
{0 x00, 0 x00010159}, {0 x18, 0 x0000f407},
{0 xFE, 0 x00000000}, {0 xFE, 0 x00000000},
{0 x1F, 0 x00080003}, {0 xFE, 0 x00000000},
{0 xFE, 0 x00000000}, {0 x1E, 0 x00000001},
{0 x1F, 0 x00080000}, {0 x00, 0 x00033e60},
{0 xff, 0 xffffffff}
};
#define PERENTRY 23
#define RETRYSIZE 5
#define RATESIZE 28
#define TX_RPT2_ITEM_SIZE 8
static const u8 retry_penalty[PERENTRY][RETRYSIZE + 1 ] = {
{5 , 4 , 3 , 2 , 0 , 3 }, /* 92 , idx=0 */
{6 , 5 , 4 , 3 , 0 , 4 }, /* 86 , idx=1 */
{6 , 5 , 4 , 2 , 0 , 4 }, /* 81 , idx=2 */
{8 , 7 , 6 , 4 , 0 , 6 }, /* 75 , idx=3 */
{10 , 9 , 8 , 6 , 0 , 8 }, /* 71 , idx=4 */
{10 , 9 , 8 , 4 , 0 , 8 }, /* 66 , idx=5 */
{10 , 9 , 8 , 2 , 0 , 8 }, /* 62 , idx=6 */
{10 , 9 , 8 , 0 , 0 , 8 }, /* 59 , idx=7 */
{18 , 17 , 16 , 8 , 0 , 16 }, /* 53 , idx=8 */
{26 , 25 , 24 , 16 , 0 , 24 }, /* 50 , idx=9 */
{34 , 33 , 32 , 24 , 0 , 32 }, /* 47 , idx=0x0a */
{34 , 31 , 28 , 20 , 0 , 32 }, /* 43 , idx=0x0b */
{34 , 31 , 27 , 18 , 0 , 32 }, /* 40 , idx=0x0c */
{34 , 31 , 26 , 16 , 0 , 32 }, /* 37 , idx=0x0d */
{34 , 30 , 22 , 16 , 0 , 32 }, /* 32 , idx=0x0e */
{34 , 30 , 24 , 16 , 0 , 32 }, /* 26 , idx=0x0f */
{49 , 46 , 40 , 16 , 0 , 48 }, /* 20 , idx=0x10 */
{49 , 45 , 32 , 0 , 0 , 48 }, /* 17 , idx=0x11 */
{49 , 45 , 22 , 18 , 0 , 48 }, /* 15 , idx=0x12 */
{49 , 40 , 24 , 16 , 0 , 48 }, /* 12 , idx=0x13 */
{49 , 32 , 18 , 12 , 0 , 48 }, /* 9 , idx=0x14 */
{49 , 22 , 18 , 14 , 0 , 48 }, /* 6 , idx=0x15 */
{49 , 16 , 16 , 0 , 0 , 48 } /* 3, idx=0x16 */
};
static const u8 pt_penalty[RETRYSIZE + 1 ] = {34 , 31 , 30 , 24 , 0 , 32 };
static const u8 retry_penalty_idx_normal[2 ][RATESIZE] = {
{ /* RSSI>TH */
4 , 4 , 4 , 5 ,
4 , 4 , 5 , 7 , 7 , 7 , 8 , 0 x0a,
4 , 4 , 4 , 4 , 6 , 0 x0a, 0 x0b, 0 x0d,
5 , 5 , 7 , 7 , 8 , 0 x0b, 0 x0d, 0 x0f
},
{ /* RSSI<TH */
0 x0a, 0 x0a, 0 x0b, 0 x0c,
0 x0a, 0 x0a, 0 x0b, 0 x0c, 0 x0d, 0 x10, 0 x13, 0 x13,
0 x0b, 0 x0c, 0 x0d, 0 x0e, 0 x0f, 0 x11, 0 x13, 0 x13,
9 , 9 , 9 , 9 , 0 x0c, 0 x0e, 0 x11, 0 x13
}
};
static const u8 retry_penalty_idx_cut_i[2 ][RATESIZE] = {
{ /* RSSI>TH */
4 , 4 , 4 , 5 ,
4 , 4 , 5 , 7 , 7 , 7 , 8 , 0 x0a,
4 , 4 , 4 , 4 , 6 , 0 x0a, 0 x0b, 0 x0d,
5 , 5 , 7 , 7 , 8 , 0 x0b, 0 x0d, 0 x0f
},
{ /* RSSI<TH */
0 x0a, 0 x0a, 0 x0b, 0 x0c,
0 x0a, 0 x0a, 0 x0b, 0 x0c, 0 x0d, 0 x10, 0 x13, 0 x13,
0 x06, 0 x07, 0 x08, 0 x0d, 0 x0e, 0 x11, 0 x11, 0 x11,
9 , 9 , 9 , 9 , 0 x0c, 0 x0e, 0 x11, 0 x13
}
};
static const u8 retry_penalty_up_idx_normal[RATESIZE] = {
0 x0c, 0 x0d, 0 x0d, 0 x0f,
0 x0d, 0 x0e, 0 x0f, 0 x0f, 0 x10, 0 x12, 0 x13, 0 x14,
0 x0f, 0 x10, 0 x10, 0 x12, 0 x12, 0 x13, 0 x14, 0 x15,
0 x11, 0 x11, 0 x12, 0 x13, 0 x13, 0 x13, 0 x14, 0 x15
};
static const u8 retry_penalty_up_idx_cut_i[RATESIZE] = {
0 x0c, 0 x0d, 0 x0d, 0 x0f,
0 x0d, 0 x0e, 0 x0f, 0 x0f, 0 x10, 0 x12, 0 x13, 0 x14,
0 x0b, 0 x0b, 0 x11, 0 x11, 0 x12, 0 x12, 0 x12, 0 x12,
0 x11, 0 x11, 0 x12, 0 x13, 0 x13, 0 x13, 0 x14, 0 x15
};
static const u8 rssi_threshold[RATESIZE] = {
0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 x24, 0 x26, 0 x2a,
0 x18, 0 x1a, 0 x1d, 0 x1f, 0 x21, 0 x27, 0 x29, 0 x2a,
0 , 0 , 0 , 0 x1f, 0 x23, 0 x28, 0 x2a, 0 x2c
};
static const u16 n_threshold_high[RATESIZE] = {
4 , 4 , 8 , 16 ,
24 , 36 , 48 , 72 , 96 , 144 , 192 , 216 ,
60 , 80 , 100 , 160 , 240 , 400 , 600 , 800 ,
300 , 320 , 480 , 720 , 1000 , 1200 , 1600 , 2000
};
static const u16 n_threshold_low[RATESIZE] = {
2 , 2 , 4 , 8 ,
12 , 18 , 24 , 36 , 48 , 72 , 96 , 108 ,
30 , 40 , 50 , 80 , 120 , 200 , 300 , 400 ,
150 , 160 , 240 , 360 , 500 , 600 , 800 , 1000
};
static const u8 dropping_necessary[RATESIZE] = {
1 , 1 , 1 , 1 ,
1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
5 , 6 , 7 , 8 , 9 , 10 , 11 , 12
};
static const u8 pending_for_rate_up_fail[5 ] = {2 , 10 , 24 , 40 , 60 };
static const u16 dynamic_tx_rpt_timing[6 ] = {
0 x186a, 0 x30d4, 0 x493e, 0 x61a8, 0 x7a12, 0 x927c /* 200ms-1200ms */
};
enum rtl8188e_tx_rpt_timing {
DEFAULT_TIMING = 0 ,
INCREASE_TIMING,
DECREASE_TIMING
};
static int rtl8188eu_identify_chip(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
u32 sys_cfg, vendor;
int ret = 0 ;
strscpy(priv->chip_name, "8188EU" , sizeof (priv->chip_name));
priv->rtl_chip = RTL8188E;
priv->rf_paths = 1 ;
priv->rx_paths = 1 ;
priv->tx_paths = 1 ;
priv->has_wifi = 1 ;
sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
priv->chip_cut = u32_get_bits(sys_cfg, SYS_CFG_CHIP_VERSION_MASK);
if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
dev_info(dev, "Unsupported test chip\n" );
return -EOPNOTSUPP;
}
/*
* TODO: At a glance, I cut requires a different firmware,
* different initialisation tables, and no software rate
* control. The vendor driver is not configured to handle
* I cut chips by default. Are there any in the wild?
*/
if (priv->chip_cut == 8 ) {
dev_info(dev, "RTL8188EU cut I is not supported. Please complain about it at linux-wireless@vger.kernel.org.\n" );
return -EOPNOTSUPP;
}
vendor = sys_cfg & SYS_CFG_VENDOR_ID;
rtl8xxxu_identify_vendor_1bit(priv, vendor);
ret = rtl8xxxu_config_endpoints_no_sie(priv);
return ret;
}
static void rtl8188eu_config_channel(struct ieee80211_hw *hw)
{
struct rtl8xxxu_priv *priv = hw->priv;
u32 val32, rsr;
u8 opmode;
int sec_ch_above, channel;
int i;
opmode = rtl8xxxu_read8(priv, REG_BW_OPMODE);
rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
channel = hw->conf.chandef.chan->hw_value;
switch (hw->conf.chandef.width) {
case NL80211_CHAN_WIDTH_20_NOHT:
case NL80211_CHAN_WIDTH_20:
opmode |= BW_OPMODE_20MHZ;
rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
val32 &= ~FPGA_RF_MODE;
rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
val32 &= ~FPGA_RF_MODE;
rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
break ;
case NL80211_CHAN_WIDTH_40:
if (hw->conf.chandef.center_freq1 >
hw->conf.chandef.chan->center_freq) {
sec_ch_above = 1 ;
channel += 2 ;
} else {
sec_ch_above = 0 ;
channel -= 2 ;
}
opmode &= ~BW_OPMODE_20MHZ;
rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
rsr &= ~RSR_RSC_BANDWIDTH_40M;
if (sec_ch_above)
rsr |= RSR_RSC_LOWER_SUB_CHANNEL;
else
rsr |= RSR_RSC_UPPER_SUB_CHANNEL;
rtl8xxxu_write32(priv, REG_RESPONSE_RATE_SET, rsr);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_RF_MODE);
val32 |= FPGA_RF_MODE;
rtl8xxxu_write32(priv, REG_FPGA0_RF_MODE, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA1_RF_MODE);
val32 |= FPGA_RF_MODE;
rtl8xxxu_write32(priv, REG_FPGA1_RF_MODE, val32);
/*
* Set Control channel to upper or lower. These settings
* are required only for 40MHz
*/
val32 = rtl8xxxu_read32(priv, REG_CCK0_SYSTEM);
val32 &= ~CCK0_SIDEBAND;
if (!sec_ch_above)
val32 |= CCK0_SIDEBAND;
rtl8xxxu_write32(priv, REG_CCK0_SYSTEM, val32);
val32 = rtl8xxxu_read32(priv, REG_OFDM1_LSTF);
val32 &= ~OFDM_LSTF_PRIME_CH_MASK; /* 0xc00 */
if (sec_ch_above)
val32 |= OFDM_LSTF_PRIME_CH_LOW;
else
val32 |= OFDM_LSTF_PRIME_CH_HIGH;
rtl8xxxu_write32(priv, REG_OFDM1_LSTF, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_POWER_SAVE);
val32 &= ~(FPGA0_PS_LOWER_CHANNEL | FPGA0_PS_UPPER_CHANNEL);
if (sec_ch_above)
val32 |= FPGA0_PS_UPPER_CHANNEL;
else
val32 |= FPGA0_PS_LOWER_CHANNEL;
rtl8xxxu_write32(priv, REG_FPGA0_POWER_SAVE, val32);
break ;
default :
break ;
}
for (i = RF_A; i < priv->rf_paths; i++) {
val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
u32p_replace_bits(&val32, channel, MODE_AG_CHANNEL_MASK);
rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
}
for (i = RF_A; i < priv->rf_paths; i++) {
val32 = rtl8xxxu_read_rfreg(priv, i, RF6052_REG_MODE_AG);
val32 &= ~MODE_AG_BW_MASK;
if (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40)
val32 |= MODE_AG_BW_40MHZ_8723B;
else
val32 |= MODE_AG_BW_20MHZ_8723B;
rtl8xxxu_write_rfreg(priv, i, RF6052_REG_MODE_AG, val32);
}
}
static void rtl8188eu_init_aggregation(struct rtl8xxxu_priv *priv)
{
u8 agg_ctrl, usb_spec;
usb_spec = rtl8xxxu_read8(priv, REG_USB_SPECIAL_OPTION);
usb_spec &= ~USB_SPEC_USB_AGG_ENABLE;
rtl8xxxu_write8(priv, REG_USB_SPECIAL_OPTION, usb_spec);
agg_ctrl = rtl8xxxu_read8(priv, REG_TRXDMA_CTRL);
agg_ctrl &= ~TRXDMA_CTRL_RXDMA_AGG_EN;
rtl8xxxu_write8(priv, REG_TRXDMA_CTRL, agg_ctrl);
}
static int rtl8188eu_parse_efuse(struct rtl8xxxu_priv *priv)
{
struct rtl8188eu_efuse *efuse = &priv->efuse_wifi.efuse8188eu;
if (efuse->rtl_id != cpu_to_le16(0 x8129))
return -EINVAL;
ether_addr_copy(priv->mac_addr, efuse->mac_addr);
memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base,
sizeof (efuse->tx_power_index_A.cck_base));
memcpy(priv->ht40_1s_tx_power_index_A,
efuse->tx_power_index_A.ht40_base,
sizeof (efuse->tx_power_index_A.ht40_base));
priv->default_crystal_cap = efuse->xtal_k & 0 x3f;
return 0 ;
}
static void rtl8188eu_reset_8051(struct rtl8xxxu_priv *priv)
{
u16 sys_func;
sys_func = rtl8xxxu_read16(priv, REG_SYS_FUNC);
sys_func &= ~SYS_FUNC_CPU_ENABLE;
rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
sys_func |= SYS_FUNC_CPU_ENABLE;
rtl8xxxu_write16(priv, REG_SYS_FUNC, sys_func);
}
static int rtl8188eu_load_firmware(struct rtl8xxxu_priv *priv)
{
const char *fw_name;
int ret;
fw_name = "rtlwifi/rtl8188eufw.bin" ;
ret = rtl8xxxu_load_firmware(priv, fw_name);
return ret;
}
static void rtl8188eu_init_phy_bb(struct rtl8xxxu_priv *priv)
{
u8 val8;
u16 val16;
val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB | SYS_FUNC_DIO_RF;
rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
/*
* Per vendor driver, run power sequence before init of RF
*/
val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
val8 = SYS_FUNC_USBA | SYS_FUNC_USBD |
SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB;
rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
rtl8xxxu_init_phy_regs(priv, rtl8188eu_phy_init_table);
rtl8xxxu_init_phy_regs(priv, rtl8188e_agc_table);
}
static int rtl8188eu_init_phy_rf(struct rtl8xxxu_priv *priv)
{
return rtl8xxxu_init_phy_rf(priv, rtl8188eu_radioa_init_table, RF_A);
}
static int rtl8188eu_iqk_path_a(struct rtl8xxxu_priv *priv)
{
u32 reg_eac, reg_e94, reg_e9c;
int result = 0 ;
/* Path A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x10008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x30008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x8214032a);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x28160000);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x00462911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
if (!(reg_eac & BIT(28 )) &&
((reg_e94 & 0 x03ff0000) != 0 x01420000) &&
((reg_e9c & 0 x03ff0000) != 0 x00420000))
result |= 0 x01;
return result;
}
static int rtl8188eu_rx_iqk_path_a(struct rtl8xxxu_priv *priv)
{
u32 reg_ea4, reg_eac, reg_e94, reg_e9c, val32;
int result = 0 ;
/* Leave IQK mode */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 , 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
/* Enable path A PA in TX IQK mode */
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf117b);
/* Enter IQK mode */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 x808000, 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
/* TX IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x81004800);
/* path-A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x10008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x30008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x82160804);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x28160000);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
if (!(reg_eac & BIT(28 )) &&
((reg_e94 & 0 x03ff0000) != 0 x01420000) &&
((reg_e9c & 0 x03ff0000) != 0 x00420000))
result |= 0 x01;
else
goto out;
val32 = 0 x80007c00 |
(reg_e94 & 0 x03ff0000) | ((reg_e9c >> 16 ) & 0 x03ff);
rtl8xxxu_write32(priv, REG_TX_IQK, val32);
/* Modify RX IQK mode table */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 , 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf7ffa);
/* Enter IQK mode */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 x808000, 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
/* IQK setting */
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
/* Path A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x30008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x10008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x82160c05);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x28160c05);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
if (!(reg_eac & BIT(27 )) &&
((reg_ea4 & 0 x03ff0000) != 0 x01320000) &&
((reg_eac & 0 x03ff0000) != 0 x00360000))
result |= 0 x02;
else
dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n" ,
__func__);
out:
return result;
}
static void rtl8188eu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
int result[][8 ], int t)
{
struct device *dev = &priv->udev->dev;
u32 i, val32;
int path_a_ok;
int retry = 2 ;
static const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
REG_TX_OFDM_BBON, REG_TX_TO_RX,
REG_TX_TO_TX, REG_RX_CCK,
REG_RX_OFDM, REG_RX_WAIT_RIFS,
REG_RX_TO_RX, REG_STANDBY,
REG_SLEEP, REG_PMPD_ANAEN
};
static const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
REG_TXPAUSE, REG_BEACON_CTRL,
REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
};
static const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
REG_FPGA0_XB_RF_INT_OE, REG_CCK0_AFE_SETTING
};
/*
* Note: IQ calibration must be performed after loading
* PHY_REG.txt , and radio_a, radio_b.txt
*/
if (t == 0 ) {
/* Save ADDA parameters, turn Path A ADDA on */
rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
RTL8XXXU_ADDA_REGS);
rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
rtl8xxxu_save_regs(priv, iqk_bb_regs,
priv->bb_backup, RTL8XXXU_BB_REGS);
}
rtl8xxxu_path_adda_on(priv, adda_regs, true );
if (t == 0 ) {
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_HSSI_PARM1);
priv->pi_enabled = u32_get_bits(val32, FPGA0_HSSI_PARM1_PI);
}
if (!priv->pi_enabled) {
/* Switch BB to PI mode to do IQ Calibration. */
rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0 x01000100);
rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0 x01000100);
}
/* MAC settings */
rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
u32p_replace_bits(&val32, 0 xf, 0 x0f000000);
rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0 x03a05600);
rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0 x000800e4);
rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0 x22204000);
if (!priv->no_pape) {
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
val32 |= (FPGA0_RF_PAPE |
(FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
}
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
val32 &= ~BIT(10 );
rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
val32 &= ~BIT(10 );
rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
/* Page B init */
rtl8xxxu_write32(priv, REG_CONFIG_ANT_A, 0 x0f600000);
/* IQ calibration setting */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 x808000, 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x81004800);
for (i = 0 ; i < retry; i++) {
path_a_ok = rtl8188eu_iqk_path_a(priv);
if (path_a_ok == 0 x01) {
val32 = rtl8xxxu_read32(priv,
REG_TX_POWER_BEFORE_IQK_A);
result[t][0 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv,
REG_TX_POWER_AFTER_IQK_A);
result[t][1 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_a_ok)
dev_dbg(dev, "%s: Path A TX IQK failed!\n" , __func__);
for (i = 0 ; i < retry; i++) {
path_a_ok = rtl8188eu_rx_iqk_path_a(priv);
if (path_a_ok == 0 x03) {
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_BEFORE_IQK_A_2);
result[t][2 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_AFTER_IQK_A_2);
result[t][3 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_a_ok)
dev_dbg(dev, "%s: Path A RX IQK failed!\n" , __func__);
/* Back to BB mode, load original value */
val32 = rtl8xxxu_read32(priv, REG_FPGA0_IQK);
u32p_replace_bits(&val32, 0 , 0 xffffff00);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, val32);
if (t == 0 )
return ;
if (!priv->pi_enabled) {
/* Switch back BB to SI mode after finishing IQ Calibration */
rtl8xxxu_write32(priv, REG_FPGA0_XA_HSSI_PARM1, 0 x01000000);
rtl8xxxu_write32(priv, REG_FPGA0_XB_HSSI_PARM1, 0 x01000000);
}
/* Reload ADDA power saving parameters */
rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
RTL8XXXU_ADDA_REGS);
/* Reload MAC parameters */
rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
/* Reload BB parameters */
rtl8xxxu_restore_regs(priv, iqk_bb_regs,
priv->bb_backup, RTL8XXXU_BB_REGS);
/* Restore RX initial gain */
rtl8xxxu_write32(priv, REG_FPGA0_XA_LSSI_PARM, 0 x00032ed3);
/* Load 0xe30 IQC default value */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x01008c00);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x01008c00);
}
static void rtl8188eu_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
int result[4 ][8 ]; /* last is final result */
int i, candidate;
bool path_a_ok;
u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
bool simu;
memset(result, 0 , sizeof (result));
result[3 ][0 ] = 0 x100;
result[3 ][2 ] = 0 x100;
result[3 ][4 ] = 0 x100;
result[3 ][6 ] = 0 x100;
candidate = -1 ;
path_a_ok = false ;
for (i = 0 ; i < 3 ; i++) {
rtl8188eu_phy_iqcalibrate(priv, result, i);
if (i == 1 ) {
simu = rtl8xxxu_simularity_compare(priv,
result, 0 , 1 );
if (simu) {
candidate = 0 ;
break ;
}
}
if (i == 2 ) {
simu = rtl8xxxu_simularity_compare(priv,
result, 0 , 2 );
if (simu) {
candidate = 0 ;
break ;
}
simu = rtl8xxxu_simularity_compare(priv,
result, 1 , 2 );
if (simu)
candidate = 1 ;
else
candidate = 3 ;
}
}
if (candidate >= 0 ) {
reg_e94 = result[candidate][0 ];
priv->rege94 = reg_e94;
reg_e9c = result[candidate][1 ];
priv->rege9c = reg_e9c;
reg_ea4 = result[candidate][2 ];
reg_eac = result[candidate][3 ];
reg_eb4 = result[candidate][4 ];
priv->regeb4 = reg_eb4;
reg_ebc = result[candidate][5 ];
priv->regebc = reg_ebc;
reg_ec4 = result[candidate][6 ];
reg_ecc = result[candidate][7 ];
dev_dbg(dev, "%s: candidate is %x\n" , __func__, candidate);
dev_dbg(dev,
"%s: e94=%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x ecc=%x\n" ,
__func__, reg_e94, reg_e9c, reg_ea4, reg_eac,
reg_eb4, reg_ebc, reg_ec4, reg_ecc);
path_a_ok = true ;
} else {
reg_e94 = 0 x100;
reg_eb4 = 0 x100;
priv->rege94 = 0 x100;
priv->regeb4 = 0 x100;
reg_e9c = 0 x0;
reg_ebc = 0 x0;
priv->rege9c = 0 x0;
priv->regebc = 0 x0;
}
if (reg_e94 && candidate >= 0 )
rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
candidate, (reg_ea4 == 0 ));
rtl8xxxu_save_regs(priv, rtl8xxxu_iqk_phy_iq_bb_reg,
priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
}
static void rtl8188e_disabled_to_emu(struct rtl8xxxu_priv *priv)
{
u16 val16;
val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
val16 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE);
rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
}
static int rtl8188e_emu_to_active(struct rtl8xxxu_priv *priv)
{
u8 val8;
u32 val32;
u16 val16;
int count, ret = 0 ;
/* wait till 0x04[17] = 1 power ready*/
for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
if (val32 & BIT(17 ))
break ;
udelay(10 );
}
if (!count) {
ret = -EBUSY;
goto exit ;
}
/* reset baseband */
val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
val8 &= ~(SYS_FUNC_BBRSTB | SYS_FUNC_BB_GLB_RSTN);
rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
/*0x24[23] = 2b'01 schmit trigger */
val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
val32 |= BIT(23 );
rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
/* 0x04[15] = 0 disable HWPDN (control by DRV)*/
val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
val16 &= ~APS_FSMCO_HW_POWERDOWN;
rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
/*0x04[12:11] = 2b'00 disable WL suspend*/
val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
val16 &= ~(APS_FSMCO_HW_SUSPEND | APS_FSMCO_PCIE);
rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
/* set, then poll until 0 */
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
val32 |= APS_FSMCO_MAC_ENABLE;
rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
if ((val32 & APS_FSMCO_MAC_ENABLE) == 0 ) {
ret = 0 ;
break ;
}
udelay(10 );
}
if (!count) {
ret = -EBUSY;
goto exit ;
}
/* LDO normal mode*/
val8 = rtl8xxxu_read8(priv, REG_LPLDO_CTRL);
val8 &= ~BIT(4 );
rtl8xxxu_write8(priv, REG_LPLDO_CTRL, val8);
exit :
return ret;
}
static int rtl8188eu_active_to_emu(struct rtl8xxxu_priv *priv)
{
u8 val8;
/* Turn off RF */
val8 = rtl8xxxu_read8(priv, REG_RF_CTRL);
val8 &= ~RF_ENABLE;
rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
/* LDO Sleep mode */
val8 = rtl8xxxu_read8(priv, REG_LPLDO_CTRL);
val8 |= BIT(4 );
rtl8xxxu_write8(priv, REG_LPLDO_CTRL, val8);
return 0 ;
}
static int rtl8188eu_emu_to_disabled(struct rtl8xxxu_priv *priv)
{
u32 val32;
u16 val16;
u8 val8;
val32 = rtl8xxxu_read32(priv, REG_AFE_XTAL_CTRL);
val32 |= BIT(23 );
rtl8xxxu_write32(priv, REG_AFE_XTAL_CTRL, val32);
val16 = rtl8xxxu_read16(priv, REG_APS_FSMCO);
val16 &= ~APS_FSMCO_PCIE;
val16 |= APS_FSMCO_HW_SUSPEND;
rtl8xxxu_write16(priv, REG_APS_FSMCO, val16);
rtl8xxxu_write8(priv, REG_APS_FSMCO + 3 , 0 x00);
val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG + 1 );
val8 &= ~BIT(4 );
rtl8xxxu_write8(priv, REG_GPIO_MUXCFG + 1 , val8);
/* Set USB suspend enable local register 0xfe10[4]=1 */
val8 = rtl8xxxu_read8(priv, 0 xfe10);
val8 |= BIT(4 );
rtl8xxxu_write8(priv, 0 xfe10, val8);
return 0 ;
}
static int rtl8188eu_active_to_lps(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
u8 val8;
u16 val16;
u32 val32;
int retry, retval;
rtl8xxxu_write8(priv, REG_TXPAUSE, 0 x7f);
retry = 100 ;
retval = -EBUSY;
/* Poll 32 bit wide REG_SCH_TX_CMD for 0 to ensure no TX is pending. */
do {
val32 = rtl8xxxu_read32(priv, REG_SCH_TX_CMD);
if (!val32) {
retval = 0 ;
break ;
}
} while (retry--);
if (!retry) {
dev_warn(dev, "Failed to flush TX queue\n" );
retval = -EBUSY;
goto out;
}
/* Disable CCK and OFDM, clock gated */
val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
val8 &= ~SYS_FUNC_BBRSTB;
rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
udelay(2 );
/* Reset MAC TRX */
val16 = rtl8xxxu_read16(priv, REG_CR);
val16 |= 0 xff;
val16 &= ~(CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE | CR_SECURITY_ENABLE);
rtl8xxxu_write16(priv, REG_CR, val16);
val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
val8 |= DUAL_TSF_TX_OK;
rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
out:
return retval;
}
static int rtl8188eu_power_on(struct rtl8xxxu_priv *priv)
{
u16 val16;
int ret;
rtl8188e_disabled_to_emu(priv);
ret = rtl8188e_emu_to_active(priv);
if (ret)
goto exit ;
/*
* Enable MAC DMA/WMAC/SCHEDULE/SEC block
* Set CR bit10 to enable 32k calibration.
* We do not set CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE here
* due to a hardware bug in the 88E, requiring those to be
* set after REG_TRXFF_BNDY is set. If not the RXFF bundary
* will get set to a larger buffer size than the real buffer
* size.
*/
val16 = (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
rtl8xxxu_write16(priv, REG_CR, val16);
exit :
return ret;
}
static void rtl8188eu_power_off(struct rtl8xxxu_priv *priv)
{
u8 val8;
u16 val16;
rtl8xxxu_flush_fifo(priv);
val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE;
rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
/* Turn off RF */
rtl8xxxu_write8(priv, REG_RF_CTRL, 0 x00);
rtl8188eu_active_to_lps(priv);
/* Reset Firmware if running in RAM */
if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
rtl8xxxu_firmware_self_reset(priv);
/* Reset MCU */
val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
val16 &= ~SYS_FUNC_CPU_ENABLE;
rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
/* Reset MCU ready status */
rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0 x00);
/* 32K_CTRL looks to be very 8188e specific */
val8 = rtl8xxxu_read8(priv, REG_32K_CTRL);
val8 &= ~BIT(0 );
rtl8xxxu_write8(priv, REG_32K_CTRL, val8);
rtl8188eu_active_to_emu(priv);
rtl8188eu_emu_to_disabled(priv);
/* Reset MCU IO Wrapper */
val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1 );
val8 &= ~BIT(3 );
rtl8xxxu_write8(priv, REG_RSV_CTRL + 1 , val8);
val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL + 1 );
val8 |= BIT(3 );
rtl8xxxu_write8(priv, REG_RSV_CTRL + 1 , val8);
/* Vendor driver refers to GPIO_IN */
val8 = rtl8xxxu_read8(priv, REG_GPIO_PIN_CTRL);
/* Vendor driver refers to GPIO_OUT */
rtl8xxxu_write8(priv, REG_GPIO_PIN_CTRL + 1 , val8);
rtl8xxxu_write8(priv, REG_GPIO_PIN_CTRL + 2 , 0 xff);
val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL);
rtl8xxxu_write8(priv, REG_GPIO_IO_SEL, val8 << 4 );
val8 = rtl8xxxu_read8(priv, REG_GPIO_IO_SEL + 1 );
rtl8xxxu_write8(priv, REG_GPIO_IO_SEL + 1 , val8 | 0 x0f);
/*
* Set LNA, TRSW, EX_PA Pin to output mode
* Referred to as REG_BB_PAD_CTRL in 8188eu vendor driver
*/
rtl8xxxu_write32(priv, REG_PAD_CTRL1, 0 x00080808);
rtl8xxxu_write8(priv, REG_RSV_CTRL, 0 x00);
rtl8xxxu_write32(priv, REG_GPIO_MUXCFG, 0 x00000000);
}
static void rtl8188e_enable_rf(struct rtl8xxxu_priv *priv)
{
u32 val32;
rtl8xxxu_write8(priv, REG_RF_CTRL, RF_ENABLE | RF_RSTB | RF_SDMRSTB);
val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
val32 &= ~(OFDM_RF_PATH_RX_MASK | OFDM_RF_PATH_TX_MASK);
val32 |= OFDM_RF_PATH_RX_A | OFDM_RF_PATH_TX_A;
rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
rtl8xxxu_write8(priv, REG_TXPAUSE, 0 x00);
}
static void rtl8188e_disable_rf(struct rtl8xxxu_priv *priv)
{
u32 val32;
val32 = rtl8xxxu_read32(priv, REG_OFDM0_TRX_PATH_ENABLE);
val32 &= ~OFDM_RF_PATH_TX_MASK;
rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, val32);
/* Power down RF module */
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0 );
rtl8188eu_active_to_emu(priv);
}
static void rtl8188e_usb_quirks(struct rtl8xxxu_priv *priv)
{
u16 val16;
/*
* Technically this is not a USB quirk, but a chip quirk.
* This has to be done after REG_TRXFF_BNDY is set, see
* rtl8188eu_power_on() for details.
*/
val16 = rtl8xxxu_read16(priv, REG_CR);
val16 |= (CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE);
rtl8xxxu_write16(priv, REG_CR, val16);
rtl8xxxu_gen2_usb_quirks(priv);
/* Pre-TX enable WEP/TKIP security */
rtl8xxxu_write8(priv, REG_EARLY_MODE_CONTROL_8188E + 3 , 0 x01);
}
static s8 rtl8188e_cck_rssi(struct rtl8xxxu_priv *priv, struct rtl8723au_phy_stats *phy_stats)
{
/* only use lna 0/1/2/3/7 */
static const s8 lna_gain_table_0[8 ] = {17 , -1 , -13 , -29 , -32 , -35 , -38 , -41 };
/* only use lna 3/7 */
static const s8 lna_gain_table_1[8 ] = {29 , 20 , 12 , 3 , -6 , -15 , -24 , -33 };
u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
s8 rx_pwr_all = 0 x00;
u8 vga_idx, lna_idx;
s8 lna_gain = 0 ;
lna_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_LNA_IDX_MASK);
vga_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_VGA_IDX_MASK);
if (priv->chip_cut >= 8 ) /* cut I */ /* SMIC */
lna_gain = lna_gain_table_0[lna_idx];
else /* TSMC */
lna_gain = lna_gain_table_1[lna_idx];
rx_pwr_all = lna_gain - (2 * vga_idx);
return rx_pwr_all;
}
static int rtl8188eu_led_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct rtl8xxxu_priv *priv = container_of(led_cdev,
struct rtl8xxxu_priv,
led_cdev);
u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG2);
if (brightness == LED_OFF) {
ledcfg &= ~LEDCFG2_HW_LED_CONTROL;
ledcfg |= LEDCFG2_SW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE;
} else if (brightness == LED_ON) {
ledcfg &= ~(LEDCFG2_HW_LED_CONTROL | LEDCFG2_SW_LED_DISABLE);
ledcfg |= LEDCFG2_SW_LED_CONTROL;
} else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
ledcfg &= ~LEDCFG2_SW_LED_DISABLE;
ledcfg |= LEDCFG2_HW_LED_CONTROL | LEDCFG2_HW_LED_ENABLE;
}
rtl8xxxu_write8(priv, REG_LEDCFG2, ledcfg);
return 0 ;
}
static void rtl8188e_set_tx_rpt_timing(struct rtl8xxxu_ra_info *ra, u8 timing)
{
u8 idx;
for (idx = 0 ; idx < 5 ; idx++)
if (dynamic_tx_rpt_timing[idx] == ra->rpt_time)
break ;
if (timing == DEFAULT_TIMING) {
idx = 0 ; /* 200ms */
} else if (timing == INCREASE_TIMING) {
if (idx < 5 )
idx++;
} else if (timing == DECREASE_TIMING) {
if (idx > 0 )
idx--;
}
ra->rpt_time = dynamic_tx_rpt_timing[idx];
}
static void rtl8188e_rate_down(struct rtl8xxxu_ra_info *ra)
{
u8 rate_id = ra->pre_rate;
u8 lowest_rate = ra->lowest_rate;
u8 highest_rate = ra->highest_rate;
s8 i;
if (rate_id > highest_rate) {
rate_id = highest_rate;
} else if (ra->rate_sgi) {
ra->rate_sgi = 0 ;
} else if (rate_id > lowest_rate) {
if (rate_id > 0 ) {
for (i = rate_id - 1 ; i >= lowest_rate; i--) {
if (ra->ra_use_rate & BIT(i)) {
rate_id = i;
goto rate_down_finish;
}
}
}
} else if (rate_id <= lowest_rate) {
rate_id = lowest_rate;
}
rate_down_finish:
if (ra->ra_waiting_counter == 1 ) {
ra->ra_waiting_counter++;
ra->ra_pending_counter++;
} else if (ra->ra_waiting_counter > 1 ) {
ra->ra_waiting_counter = 0 ;
ra->ra_pending_counter = 0 ;
}
if (ra->ra_pending_counter >= 4 )
ra->ra_pending_counter = 4 ;
ra->ra_drop_after_down = 1 ;
ra->decision_rate = rate_id;
rtl8188e_set_tx_rpt_timing(ra, DECREASE_TIMING);
}
static void rtl8188e_rate_up(struct rtl8xxxu_ra_info *ra)
{
u8 rate_id = ra->pre_rate;
u8 highest_rate = ra->highest_rate;
u8 i;
if (ra->ra_waiting_counter == 1 ) {
ra->ra_waiting_counter = 0 ;
ra->ra_pending_counter = 0 ;
} else if (ra->ra_waiting_counter > 1 ) {
ra->pre_rssi_sta_ra = ra->rssi_sta_ra;
goto rate_up_finish;
}
rtl8188e_set_tx_rpt_timing(ra, DEFAULT_TIMING);
if (rate_id < highest_rate) {
for (i = rate_id + 1 ; i <= highest_rate; i++) {
if (ra->ra_use_rate & BIT(i)) {
rate_id = i;
goto rate_up_finish;
}
}
} else if (rate_id == highest_rate) {
if (ra->sgi_enable && !ra->rate_sgi)
ra->rate_sgi = 1 ;
else if (!ra->sgi_enable)
ra->rate_sgi = 0 ;
} else { /* rate_id > ra->highest_rate */
rate_id = highest_rate;
}
rate_up_finish:
if (ra->ra_waiting_counter == (4 + pending_for_rate_up_fail[ra->ra_pending_counter]))
ra->ra_waiting_counter = 0 ;
else
ra->ra_waiting_counter++;
ra->decision_rate = rate_id;
}
static void rtl8188e_reset_ra_counter(struct rtl8xxxu_ra_info *ra)
{
u8 rate_id = ra->decision_rate;
ra->nsc_up = (n_threshold_high[rate_id] + n_threshold_low[rate_id]) >> 1 ;
ra->nsc_down = (n_threshold_high[rate_id] + n_threshold_low[rate_id]) >> 1 ;
}
static void rtl8188e_rate_decision(struct rtl8xxxu_ra_info *ra)
{
struct rtl8xxxu_priv *priv = container_of(ra, struct rtl8xxxu_priv, ra_info);
const u8 *retry_penalty_idx_0;
const u8 *retry_penalty_idx_1;
const u8 *retry_penalty_up_idx;
u8 rate_id, penalty_id1, penalty_id2;
int i;
if (ra->total == 0 )
return ;
if (ra->ra_drop_after_down) {
ra->ra_drop_after_down--;
rtl8188e_reset_ra_counter(ra);
return ;
}
if (priv->chip_cut == 8 ) { /* cut I */
retry_penalty_idx_0 = retry_penalty_idx_cut_i[0 ];
retry_penalty_idx_1 = retry_penalty_idx_cut_i[1 ];
retry_penalty_up_idx = retry_penalty_up_idx_cut_i;
} else {
retry_penalty_idx_0 = retry_penalty_idx_normal[0 ];
retry_penalty_idx_1 = retry_penalty_idx_normal[1 ];
retry_penalty_up_idx = retry_penalty_up_idx_normal;
}
if (ra->rssi_sta_ra < (ra->pre_rssi_sta_ra - 3 ) ||
ra->rssi_sta_ra > (ra->pre_rssi_sta_ra + 3 )) {
ra->pre_rssi_sta_ra = ra->rssi_sta_ra;
ra->ra_waiting_counter = 0 ;
ra->ra_pending_counter = 0 ;
}
/* Start RA decision */
if (ra->pre_rate > ra->highest_rate)
rate_id = ra->highest_rate;
else
rate_id = ra->pre_rate;
/* rate down */
if (ra->rssi_sta_ra > rssi_threshold[rate_id])
penalty_id1 = retry_penalty_idx_0[rate_id];
else
penalty_id1 = retry_penalty_idx_1[rate_id];
for (i = 0 ; i < 5 ; i++)
ra->nsc_down += ra->retry[i] * retry_penalty[penalty_id1][i];
if (ra->nsc_down > (ra->total * retry_penalty[penalty_id1][5 ]))
ra->nsc_down -= ra->total * retry_penalty[penalty_id1][5 ];
else
ra->nsc_down = 0 ;
/* rate up */
penalty_id2 = retry_penalty_up_idx[rate_id];
for (i = 0 ; i < 5 ; i++)
ra->nsc_up += ra->retry[i] * retry_penalty[penalty_id2][i];
if (ra->nsc_up > (ra->total * retry_penalty[penalty_id2][5 ]))
ra->nsc_up -= ra->total * retry_penalty[penalty_id2][5 ];
else
ra->nsc_up = 0 ;
if (ra->nsc_down < n_threshold_low[rate_id] ||
ra->drop > dropping_necessary[rate_id]) {
rtl8188e_rate_down(ra);
rtl8xxxu_update_ra_report(&priv->ra_report, ra->decision_rate,
ra->rate_sgi, priv->ra_report.txrate.bw);
} else if (ra->nsc_up > n_threshold_high[rate_id]) {
rtl8188e_rate_up(ra);
rtl8xxxu_update_ra_report(&priv->ra_report, ra->decision_rate,
ra->rate_sgi, priv->ra_report.txrate.bw);
}
if (ra->decision_rate == ra->pre_rate)
ra->dynamic_tx_rpt_timing_counter++;
else
ra->dynamic_tx_rpt_timing_counter = 0 ;
if (ra->dynamic_tx_rpt_timing_counter >= 4 ) {
/* Rate didn't change 4 times, extend RPT timing */
rtl8188e_set_tx_rpt_timing(ra, INCREASE_TIMING);
ra->dynamic_tx_rpt_timing_counter = 0 ;
}
ra->pre_rate = ra->decision_rate;
rtl8188e_reset_ra_counter(ra);
}
static void rtl8188e_power_training_try_state(struct rtl8xxxu_ra_info *ra)
{
ra->pt_try_state = 0 ;
switch (ra->pt_mode_ss) {
case 3 :
if (ra->decision_rate >= DESC_RATE_MCS13)
ra->pt_try_state = 1 ;
break ;
case 2 :
if (ra->decision_rate >= DESC_RATE_MCS5)
ra->pt_try_state = 1 ;
break ;
case 1 :
if (ra->decision_rate >= DESC_RATE_48M)
ra->pt_try_state = 1 ;
break ;
case 0 :
if (ra->decision_rate >= DESC_RATE_11M)
ra->pt_try_state = 1 ;
break ;
default :
break ;
}
if (ra->rssi_sta_ra < 48 ) {
ra->pt_stage = 0 ;
} else if (ra->pt_try_state == 1 ) {
if ((ra->pt_stop_count >= 10 ) ||
(ra->pt_pre_rssi > ra->rssi_sta_ra + 5 ) ||
(ra->pt_pre_rssi < ra->rssi_sta_ra - 5 ) ||
(ra->decision_rate != ra->pt_pre_rate)) {
if (ra->pt_stage == 0 )
ra->pt_stage = 1 ;
else if (ra->pt_stage == 1 )
ra->pt_stage = 3 ;
else
ra->pt_stage = 5 ;
ra->pt_pre_rssi = ra->rssi_sta_ra;
ra->pt_stop_count = 0 ;
} else {
ra->ra_stage = 0 ;
ra->pt_stop_count++;
}
} else {
ra->pt_stage = 0 ;
ra->ra_stage = 0 ;
}
ra->pt_pre_rate = ra->decision_rate;
/* TODO: implement the "false alarm" statistics for this */
/* Disable power training when noisy environment */
/* if (p_dm_odm->is_disable_power_training) { */
if (1 ) {
ra->pt_stage = 0 ;
ra->ra_stage = 0 ;
ra->pt_stop_count = 0 ;
}
}
static void rtl8188e_power_training_decision(struct rtl8xxxu_ra_info *ra)
{
u8 temp_stage;
u32 numsc;
u32 num_total;
u8 stage_id;
u8 j;
numsc = 0 ;
num_total = ra->total * pt_penalty[5 ];
for (j = 0 ; j <= 4 ; j++) {
numsc += ra->retry[j] * pt_penalty[j];
if (numsc > num_total)
break ;
}
j >>= 1 ;
temp_stage = (ra->pt_stage + 1 ) >> 1 ;
if (temp_stage > j)
stage_id = temp_stage - j;
else
stage_id = 0 ;
ra->pt_smooth_factor = (ra->pt_smooth_factor >> 1 ) +
(ra->pt_smooth_factor >> 2 ) +
stage_id * 16 + 2 ;
if (ra->pt_smooth_factor > 192 )
ra->pt_smooth_factor = 192 ;
stage_id = ra->pt_smooth_factor >> 6 ;
temp_stage = stage_id * 2 ;
if (temp_stage != 0 )
temp_stage--;
if (ra->drop > 3 )
temp_stage = 0 ;
ra->pt_stage = temp_stage;
}
void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *skb)
{
u32 *_rx_desc = (u32 *)(skb->data - sizeof (struct rtl8xxxu_rxdesc16));
struct rtl8xxxu_rxdesc16 *rx_desc = (struct rtl8xxxu_rxdesc16 *)_rx_desc;
struct device *dev = &priv->udev->dev;
struct rtl8xxxu_ra_info *ra = &priv->ra_info;
u32 tx_rpt_len = rx_desc->pktlen & 0 x3ff;
u32 items = tx_rpt_len / TX_RPT2_ITEM_SIZE;
u64 macid_valid = ((u64)_rx_desc[5 ] << 32 ) | _rx_desc[4 ];
u32 macid;
u8 *rpt = skb->data;
bool valid;
u16 min_rpt_time = 0 x927c;
dev_dbg(dev, "%s: len: %d items: %d\n" , __func__, tx_rpt_len, items);
/* We only use macid 0, so only the first item is relevant.
* AP mode will use more of them if it's ever implemented.
*/
if (!priv->vifs[0 ] || priv->vifs[0 ]->type == NL80211_IFTYPE_STATION)
items = 1 ;
for (macid = 0 ; macid < items; macid++) {
valid = false ;
if (macid < 64 )
valid = macid_valid & BIT(macid);
if (valid) {
ra->retry[0 ] = le16_to_cpu(*(__le16 *)rpt);
ra->retry[1 ] = rpt[2 ];
ra->retry[2 ] = rpt[3 ];
ra->retry[3 ] = rpt[4 ];
ra->retry[4 ] = rpt[5 ];
ra->drop = rpt[6 ];
ra->total = ra->retry[0 ] + ra->retry[1 ] + ra->retry[2 ] +
ra->retry[3 ] + ra->retry[4 ] + ra->drop;
if (ra->total > 0 ) {
if (ra->ra_stage < 5 )
rtl8188e_rate_decision(ra);
else if (ra->ra_stage == 5 )
rtl8188e_power_training_try_state(ra);
else /* ra->ra_stage == 6 */
rtl8188e_power_training_decision(ra);
if (ra->ra_stage <= 5 )
ra->ra_stage++;
else
ra->ra_stage = 0 ;
}
} else if (macid == 0 ) {
dev_warn(dev, "%s: TX report item 0 not valid\n" , __func__);
}
dev_dbg(dev, "%s: valid: %d retry: %d %d %d %d %d drop: %d\n" ,
__func__, valid,
ra->retry[0 ], ra->retry[1 ], ra->retry[2 ],
ra->retry[3 ], ra->retry[4 ], ra->drop);
if (min_rpt_time > ra->rpt_time)
min_rpt_time = ra->rpt_time;
rpt += TX_RPT2_ITEM_SIZE;
}
if (min_rpt_time != ra->pre_min_rpt_time) {
rtl8xxxu_write16(priv, REG_TX_REPORT_TIME, min_rpt_time);
ra->pre_min_rpt_time = min_rpt_time;
}
}
static void rtl8188e_arfb_refresh(struct rtl8xxxu_ra_info *ra)
{
s8 i;
ra->ra_use_rate = ra->rate_mask;
/* Highest rate */
if (ra->ra_use_rate) {
for (i = RATESIZE; i >= 0 ; i--) {
if (ra->ra_use_rate & BIT(i)) {
ra->highest_rate = i;
break ;
}
}
} else {
ra->highest_rate = 0 ;
}
/* Lowest rate */
if (ra->ra_use_rate) {
for (i = 0 ; i < RATESIZE; i++) {
if (ra->ra_use_rate & BIT(i)) {
ra->lowest_rate = i;
break ;
}
}
} else {
ra->lowest_rate = 0 ;
}
if (ra->highest_rate > DESC_RATE_MCS7)
ra->pt_mode_ss = 3 ;
else if (ra->highest_rate > DESC_RATE_54M)
ra->pt_mode_ss = 2 ;
else if (ra->highest_rate > DESC_RATE_11M)
ra->pt_mode_ss = 1 ;
else
ra->pt_mode_ss = 0 ;
}
static void
rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
u8 macid)
{
struct rtl8xxxu_ra_info *ra = &priv->ra_info;
ra->rate_id = rateid;
ra->rate_mask = ramask;
ra->sgi_enable = sgi;
rtl8188e_arfb_refresh(ra);
}
static void rtl8188e_ra_set_rssi(struct rtl8xxxu_priv *priv, u8 macid, u8 rssi)
{
priv->ra_info.rssi_sta_ra = rssi;
}
void rtl8188e_ra_info_init_all(struct rtl8xxxu_ra_info *ra)
{
ra->decision_rate = DESC_RATE_MCS7;
ra->pre_rate = DESC_RATE_MCS7;
ra->highest_rate = DESC_RATE_MCS7;
ra->lowest_rate = 0 ;
ra->rate_id = 0 ;
ra->rate_mask = 0 xfffff;
ra->rssi_sta_ra = 0 ;
ra->pre_rssi_sta_ra = 0 ;
ra->sgi_enable = 0 ;
ra->ra_use_rate = 0 xfffff;
ra->nsc_down = (n_threshold_high[DESC_RATE_MCS7] + n_threshold_low[DESC_RATE_MCS7]) / 2 ;
ra->nsc_up = (n_threshold_high[DESC_RATE_MCS7] + n_threshold_low[DESC_RATE_MCS7]) / 2 ;
ra->rate_sgi = 0 ;
ra->rpt_time = 0 x927c;
ra->drop = 0 ;
ra->retry[0 ] = 0 ;
ra->retry[1 ] = 0 ;
ra->retry[2 ] = 0 ;
ra->retry[3 ] = 0 ;
ra->retry[4 ] = 0 ;
ra->total = 0 ;
ra->ra_waiting_counter = 0 ;
ra->ra_pending_counter = 0 ;
ra->ra_drop_after_down = 0 ;
ra->pt_try_state = 0 ;
ra->pt_stage = 5 ;
ra->pt_smooth_factor = 192 ;
ra->pt_stop_count = 0 ;
ra->pt_pre_rate = 0 ;
ra->pt_pre_rssi = 0 ;
ra->pt_mode_ss = 0 ;
ra->ra_stage = 0 ;
}
struct rtl8xxxu_fileops rtl8188eu_fops = {
.identify_chip = rtl8188eu_identify_chip,
.parse_efuse = rtl8188eu_parse_efuse,
.load_firmware = rtl8188eu_load_firmware,
.power_on = rtl8188eu_power_on,
.power_off = rtl8188eu_power_off,
.read_efuse = rtl8xxxu_read_efuse,
.reset_8051 = rtl8188eu_reset_8051,
.llt_init = rtl8xxxu_init_llt_table,
.init_phy_bb = rtl8188eu_init_phy_bb,
.init_phy_rf = rtl8188eu_init_phy_rf,
.phy_lc_calibrate = rtl8723a_phy_lc_calibrate,
.phy_iq_calibrate = rtl8188eu_phy_iq_calibrate,
.config_channel = rtl8188eu_config_channel,
.parse_rx_desc = rtl8xxxu_parse_rxdesc16,
.parse_phystats = rtl8723au_rx_parse_phystats,
.init_aggregation = rtl8188eu_init_aggregation,
.enable_rf = rtl8188e_enable_rf,
.disable_rf = rtl8188e_disable_rf,
.usb_quirks = rtl8188e_usb_quirks,
.set_tx_power = rtl8188f_set_tx_power,
.update_rate_mask = rtl8188e_update_rate_mask,
.report_connect = rtl8xxxu_gen2_report_connect,
.report_rssi = rtl8188e_ra_set_rssi,
.fill_txdesc = rtl8xxxu_fill_txdesc_v3,
.set_crystal_cap = rtl8188f_set_crystal_cap,
.cck_rssi = rtl8188e_cck_rssi,
.led_classdev_brightness_set = rtl8188eu_led_brightness_set,
.writeN_block_size = 196 ,
.rx_desc_size = sizeof (struct rtl8xxxu_rxdesc16),
.tx_desc_size = sizeof (struct rtl8xxxu_txdesc32),
.has_tx_report = 1 ,
.init_reg_pkt_life_time = 1 ,
.gen2_thermal_meter = 1 ,
.max_sec_cam_num = 32 ,
.adda_1t_init = 0 x0b1b25a0,
.adda_1t_path_on = 0 x0bdb25a0,
/*
* Use 9K for 8188e normal chip
* Max RX buffer = 10K - max(TxReportSize(64*8), WOLPattern(16*24))
*/
.trxff_boundary = 0 x25ff,
.pbp_rx = PBP_PAGE_SIZE_128,
.pbp_tx = PBP_PAGE_SIZE_128,
.mactable = rtl8188e_mac_init_table,
.total_page_num = TX_TOTAL_PAGE_NUM_8188E,
.page_num_hi = TX_PAGE_NUM_HI_PQ_8188E,
.page_num_lo = TX_PAGE_NUM_LO_PQ_8188E,
.page_num_norm = TX_PAGE_NUM_NORM_PQ_8188E,
.last_llt_entry = 175 ,
};
Messung V0.5 in Prozent C=96 H=92 G=93
¤ Dauer der Verarbeitung: 0.46 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland