hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * RTL8XXXU mac80211 USB driver
34 *
....@@ -10,15 +11,6 @@
1011 * rtl8723au driver. As the Realtek 8xxx chips are very similar in
1112 * their programming interface, I have started adding support for
1213 * 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.
2214 */
2315
2416 #include <linux/init.h>
....@@ -1153,6 +1145,7 @@
11531145 switch (hw->conf.chandef.width) {
11541146 case NL80211_CHAN_WIDTH_20_NOHT:
11551147 ht = false;
1148
+ /* fall through */
11561149 case NL80211_CHAN_WIDTH_20:
11571150 opmode |= BW_OPMODE_20MHZ;
11581151 rtl8xxxu_write8(priv, REG_BW_OPMODE, opmode);
....@@ -1262,7 +1255,7 @@
12621255 void rtl8xxxu_gen2_config_channel(struct ieee80211_hw *hw)
12631256 {
12641257 struct rtl8xxxu_priv *priv = hw->priv;
1265
- u32 val32, rsr;
1258
+ u32 val32;
12661259 u8 val8, subchannel;
12671260 u16 rf_mode_bw;
12681261 bool ht = true;
....@@ -1271,7 +1264,6 @@
12711264
12721265 rf_mode_bw = rtl8xxxu_read16(priv, REG_WMAC_TRXPTCL_CTL);
12731266 rf_mode_bw &= ~WMAC_TRXPTCL_CTL_BW_MASK;
1274
- rsr = rtl8xxxu_read32(priv, REG_RESPONSE_RATE_SET);
12751267 channel = hw->conf.chandef.chan->hw_value;
12761268
12771269 /* Hack */
....@@ -1280,6 +1272,7 @@
12801272 switch (hw->conf.chandef.width) {
12811273 case NL80211_CHAN_WIDTH_20_NOHT:
12821274 ht = false;
1275
+ /* fall through */
12831276 case NL80211_CHAN_WIDTH_20:
12841277 rf_mode_bw |= WMAC_TRXPTCL_CTL_BW_20;
12851278 subchannel = 0;
....@@ -1748,9 +1741,11 @@
17481741 case 3:
17491742 priv->ep_tx_low_queue = 1;
17501743 priv->ep_tx_count++;
1744
+ /* fall through */
17511745 case 2:
17521746 priv->ep_tx_normal_queue = 1;
17531747 priv->ep_tx_count++;
1748
+ /* fall through */
17541749 case 1:
17551750 priv->ep_tx_high_queue = 1;
17561751 priv->ep_tx_count++;
....@@ -1879,13 +1874,6 @@
18791874
18801875 /* We have 8 bits to indicate validity */
18811876 map_addr = offset * 8;
1882
- if (map_addr >= EFUSE_MAP_LEN) {
1883
- dev_warn(dev, "%s: Illegal map_addr (%04x), "
1884
- "efuse corrupt!\n",
1885
- __func__, map_addr);
1886
- ret = -EINVAL;
1887
- goto exit;
1888
- }
18891877 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
18901878 /* Check word enable condition in the section */
18911879 if (word_mask & BIT(i)) {
....@@ -1896,6 +1884,13 @@
18961884 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
18971885 if (ret)
18981886 goto exit;
1887
+ if (map_addr >= EFUSE_MAP_LEN - 1) {
1888
+ dev_warn(dev, "%s: Illegal map_addr (%04x), "
1889
+ "efuse corrupt!\n",
1890
+ __func__, map_addr);
1891
+ ret = -EINVAL;
1892
+ goto exit;
1893
+ }
18991894 priv->efuse_wifi.raw[map_addr++] = val8;
19001895
19011896 ret = rtl8xxxu_read_efuse8(priv, efuse_addr++, &val8);
....@@ -2930,12 +2925,12 @@
29302925 }
29312926
29322927 if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
2933
- /* path B RX OK */
2928
+ /* path B TX OK */
29342929 for (i = 4; i < 6; i++)
29352930 result[3][i] = result[c1][i];
29362931 }
29372932
2938
- if (!(simubitmap & 0x30) && priv->tx_paths > 1) {
2933
+ if (!(simubitmap & 0xc0) && priv->tx_paths > 1) {
29392934 /* path B RX OK */
29402935 for (i = 6; i < 8; i++)
29412936 result[3][i] = result[c1][i];
....@@ -3119,7 +3114,7 @@
31193114 u32 i, val32;
31203115 int path_a_ok, path_b_ok;
31213116 int retry = 2;
3122
- const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
3117
+ static const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
31233118 REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
31243119 REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
31253120 REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
....@@ -3129,11 +3124,11 @@
31293124 REG_RX_TO_RX, REG_STANDBY,
31303125 REG_SLEEP, REG_PMPD_ANAEN
31313126 };
3132
- const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
3127
+ static const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
31333128 REG_TXPAUSE, REG_BEACON_CTRL,
31343129 REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
31353130 };
3136
- const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
3131
+ static const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
31373132 REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
31383133 REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
31393134 REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
....@@ -3824,9 +3819,8 @@
38243819 rtl8xxxu_write8(priv, REG_RSV_CTRL, 0x0e);
38253820 }
38263821
3827
-#ifdef NEED_PS_TDMA
3828
-static void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv *priv,
3829
- u8 arg1, u8 arg2, u8 arg3, u8 arg4, u8 arg5)
3822
+void rtl8723bu_set_ps_tdma(struct rtl8xxxu_priv *priv,
3823
+ u8 arg1, u8 arg2, u8 arg3, u8 arg4, u8 arg5)
38303824 {
38313825 struct h2c_cmd h2c;
38323826
....@@ -3839,7 +3833,6 @@
38393833 h2c.b_type_dma.data5 = arg5;
38403834 rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.b_type_dma));
38413835 }
3842
-#endif
38433836
38443837 void rtl8xxxu_gen2_disable_rf(struct rtl8xxxu_priv *priv)
38453838 {
....@@ -3895,12 +3888,13 @@
38953888
38963889 /* Check if MAC is already powered on */
38973890 val8 = rtl8xxxu_read8(priv, REG_CR);
3891
+ val16 = rtl8xxxu_read16(priv, REG_SYS_CLKR);
38983892
38993893 /*
39003894 * Fix 92DU-VC S3 hang with the reason is that secondary mac is not
39013895 * initialized. First MAC returns 0xea, second MAC returns 0x00
39023896 */
3903
- if (val8 == 0xea)
3897
+ if (val8 == 0xea || !(val16 & SYS_CLK_MAC_CLK_ENABLE))
39043898 macpower = false;
39053899 else
39063900 macpower = true;
....@@ -4310,7 +4304,8 @@
43104304 rtl8xxxu_write8(priv, REG_BEACON_CTRL, val8);
43114305 }
43124306
4313
-void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv, u32 ramask, int sgi)
4307
+void rtl8xxxu_update_rate_mask(struct rtl8xxxu_priv *priv,
4308
+ u32 ramask, u8 rateid, int sgi)
43144309 {
43154310 struct h2c_cmd h2c;
43164311
....@@ -4330,10 +4325,10 @@
43304325 }
43314326
43324327 void rtl8xxxu_gen2_update_rate_mask(struct rtl8xxxu_priv *priv,
4333
- u32 ramask, int sgi)
4328
+ u32 ramask, u8 rateid, int sgi)
43344329 {
43354330 struct h2c_cmd h2c;
4336
- u8 bw = 0;
4331
+ u8 bw = RTL8XXXU_CHANNEL_WIDTH_20;
43374332
43384333 memset(&h2c, 0, sizeof(struct h2c_cmd));
43394334
....@@ -4343,15 +4338,14 @@
43434338 h2c.b_macid_cfg.ramask2 = (ramask >> 16) & 0xff;
43444339 h2c.b_macid_cfg.ramask3 = (ramask >> 24) & 0xff;
43454340
4346
- h2c.ramask.arg = 0x80;
4347
- h2c.b_macid_cfg.data1 = 0;
4341
+ h2c.b_macid_cfg.data1 = rateid;
43484342 if (sgi)
43494343 h2c.b_macid_cfg.data1 |= BIT(7);
43504344
43514345 h2c.b_macid_cfg.data2 = bw;
43524346
4353
- dev_dbg(&priv->udev->dev, "%s: rate mask %08x, arg %02x, size %zi\n",
4354
- __func__, ramask, h2c.ramask.arg, sizeof(h2c.b_macid_cfg));
4347
+ dev_dbg(&priv->udev->dev, "%s: rate mask %08x, rateid %02x, sgi %d, size %zi\n",
4348
+ __func__, ramask, rateid, sgi, sizeof(h2c.b_macid_cfg));
43554349 rtl8xxxu_gen2_h2c_cmd(priv, &h2c, sizeof(h2c.b_macid_cfg));
43564350 }
43574351
....@@ -4484,6 +4478,82 @@
44844478 rtl8xxxu_write8(priv, REG_INIRTS_RATE_SEL, rate_idx);
44854479 }
44864480
4481
+static u16
4482
+rtl8xxxu_wireless_mode(struct ieee80211_hw *hw, struct ieee80211_sta *sta)
4483
+{
4484
+ u16 network_type = WIRELESS_MODE_UNKNOWN;
4485
+
4486
+ if (hw->conf.chandef.chan->band == NL80211_BAND_5GHZ) {
4487
+ if (sta->vht_cap.vht_supported)
4488
+ network_type = WIRELESS_MODE_AC;
4489
+ else if (sta->ht_cap.ht_supported)
4490
+ network_type = WIRELESS_MODE_N_5G;
4491
+
4492
+ network_type |= WIRELESS_MODE_A;
4493
+ } else {
4494
+ if (sta->vht_cap.vht_supported)
4495
+ network_type = WIRELESS_MODE_AC;
4496
+ else if (sta->ht_cap.ht_supported)
4497
+ network_type = WIRELESS_MODE_N_24G;
4498
+
4499
+ if (sta->supp_rates[0] <= 0xf)
4500
+ network_type |= WIRELESS_MODE_B;
4501
+ else if (sta->supp_rates[0] & 0xf)
4502
+ network_type |= (WIRELESS_MODE_B | WIRELESS_MODE_G);
4503
+ else
4504
+ network_type |= WIRELESS_MODE_G;
4505
+ }
4506
+
4507
+ return network_type;
4508
+}
4509
+
4510
+static void rtl8xxxu_set_aifs(struct rtl8xxxu_priv *priv, u8 slot_time)
4511
+{
4512
+ u32 reg_edca_param[IEEE80211_NUM_ACS] = {
4513
+ [IEEE80211_AC_VO] = REG_EDCA_VO_PARAM,
4514
+ [IEEE80211_AC_VI] = REG_EDCA_VI_PARAM,
4515
+ [IEEE80211_AC_BE] = REG_EDCA_BE_PARAM,
4516
+ [IEEE80211_AC_BK] = REG_EDCA_BK_PARAM,
4517
+ };
4518
+ u32 val32;
4519
+ u16 wireless_mode = 0;
4520
+ u8 aifs, aifsn, sifs;
4521
+ int i;
4522
+
4523
+ if (priv->vif) {
4524
+ struct ieee80211_sta *sta;
4525
+
4526
+ rcu_read_lock();
4527
+ sta = ieee80211_find_sta(priv->vif, priv->vif->bss_conf.bssid);
4528
+ if (sta)
4529
+ wireless_mode = rtl8xxxu_wireless_mode(priv->hw, sta);
4530
+ rcu_read_unlock();
4531
+ }
4532
+
4533
+ if (priv->hw->conf.chandef.chan->band == NL80211_BAND_5GHZ ||
4534
+ (wireless_mode & WIRELESS_MODE_N_24G))
4535
+ sifs = 16;
4536
+ else
4537
+ sifs = 10;
4538
+
4539
+ for (i = 0; i < IEEE80211_NUM_ACS; i++) {
4540
+ val32 = rtl8xxxu_read32(priv, reg_edca_param[i]);
4541
+
4542
+ /* It was set in conf_tx. */
4543
+ aifsn = val32 & 0xff;
4544
+
4545
+ /* aifsn not set yet or already fixed */
4546
+ if (aifsn < 2 || aifsn > 15)
4547
+ continue;
4548
+
4549
+ aifs = aifsn * slot_time + sifs;
4550
+
4551
+ val32 &= ~0xff;
4552
+ val32 |= aifs;
4553
+ rtl8xxxu_write32(priv, reg_edca_param[i], val32);
4554
+ }
4555
+}
4556
+
44874557 static void
44884558 rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
44894559 struct ieee80211_bss_conf *bss_conf, u32 changed)
....@@ -4526,7 +4596,10 @@
45264596 sgi = 1;
45274597 rcu_read_unlock();
45284598
4529
- priv->fops->update_rate_mask(priv, ramask, sgi);
4599
+ priv->vif = vif;
4600
+ priv->rssi_level = RTL8XXXU_RATR_STA_INIT;
4601
+
4602
+ priv->fops->update_rate_mask(priv, ramask, 0, sgi);
45304603
45314604 rtl8xxxu_write8(priv, REG_BCN_MAX_ERR, 0xff);
45324605
....@@ -4566,6 +4639,8 @@
45664639 else
45674640 val8 = 20;
45684641 rtl8xxxu_write8(priv, REG_SLOT, val8);
4642
+
4643
+ rtl8xxxu_set_aifs(priv, val8);
45694644 }
45704645
45714646 if (changed & BSS_CHANGED_BSSID) {
....@@ -4778,6 +4853,8 @@
47784853 struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
47794854 struct rtl8xxxu_priv *priv = hw->priv;
47804855 struct device *dev = &priv->udev->dev;
4856
+ u8 *qc = ieee80211_get_qos_ctl(hdr);
4857
+ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
47814858 u32 rate;
47824859 u16 rate_flags = tx_info->control.rates[0].flags;
47834860 u16 seq_number;
....@@ -4789,8 +4866,8 @@
47894866 rate = tx_rate->hw_value;
47904867
47914868 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
4792
- dev_info(dev, "%s: TX rate: %d, pkt size %d\n",
4793
- __func__, rate, cpu_to_le16(tx_desc->pkt_size));
4869
+ dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
4870
+ __func__, rate, le16_to_cpu(tx_desc->pkt_size));
47944871
47954872 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
47964873
....@@ -4801,7 +4878,7 @@
48014878
48024879 tx_desc->txdw3 = cpu_to_le32((u32)seq_number << TXDESC32_SEQ_SHIFT);
48034880
4804
- if (ampdu_enable)
4881
+ if (ampdu_enable && test_bit(tid, priv->tid_tx_operational))
48054882 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_ENABLE);
48064883 else
48074884 tx_desc->txdw1 |= cpu_to_le32(TXDESC32_AGG_BREAK);
....@@ -4849,6 +4926,8 @@
48494926 struct rtl8xxxu_priv *priv = hw->priv;
48504927 struct device *dev = &priv->udev->dev;
48514928 struct rtl8xxxu_txdesc40 *tx_desc40;
4929
+ u8 *qc = ieee80211_get_qos_ctl(hdr);
4930
+ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
48524931 u32 rate;
48534932 u16 rate_flags = tx_info->control.rates[0].flags;
48544933 u16 seq_number;
....@@ -4862,8 +4941,8 @@
48624941 rate = tx_rate->hw_value;
48634942
48644943 if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
4865
- dev_info(dev, "%s: TX rate: %d, pkt size %d\n",
4866
- __func__, rate, cpu_to_le16(tx_desc40->pkt_size));
4944
+ dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
4945
+ __func__, rate, le16_to_cpu(tx_desc40->pkt_size));
48674946
48684947 seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
48694948
....@@ -4875,7 +4954,7 @@
48754954
48764955 tx_desc40->txdw9 = cpu_to_le32((u32)seq_number << TXDESC40_SEQ_SHIFT);
48774956
4878
- if (ampdu_enable)
4957
+ if (ampdu_enable && test_bit(tid, priv->tid_tx_operational))
48794958 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_ENABLE);
48804959 else
48814960 tx_desc40->txdw2 |= cpu_to_le32(TXDESC40_AGG_BREAK);
....@@ -4921,11 +5000,10 @@
49215000 struct device *dev = &priv->udev->dev;
49225001 u32 queue, rts_rate;
49235002 u16 pktlen = skb->len;
4924
- u16 seq_number;
49255003 u16 rate_flag = tx_info->control.rates[0].flags;
49265004 int tx_desc_size = priv->fops->tx_desc_size;
49275005 int ret;
4928
- bool usedesc40, ampdu_enable, sgi = false, short_preamble = false;
5006
+ bool ampdu_enable, sgi = false, short_preamble = false;
49295007
49305008 if (skb_headroom(skb) < tx_desc_size) {
49315009 dev_warn(dev,
....@@ -4949,11 +5027,12 @@
49495027 if (ieee80211_is_action(hdr->frame_control))
49505028 rtl8xxxu_dump_action(dev, hdr);
49515029
4952
- usedesc40 = (tx_desc_size == 40);
49535030 tx_info->rate_driver_data[0] = hw;
49545031
49555032 if (control && control->sta)
49565033 sta = control->sta;
5034
+
5035
+ queue = rtl8xxxu_queue_select(hw, skb);
49575036
49585037 tx_desc = skb_push(skb, tx_desc_size);
49595038
....@@ -4967,7 +5046,6 @@
49675046 is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
49685047 tx_desc->txdw0 |= TXDESC_BROADMULTICAST;
49695048
4970
- queue = rtl8xxxu_queue_select(hw, skb);
49715049 tx_desc->txdw1 = cpu_to_le32(queue << TXDESC_QUEUE_SHIFT);
49725050
49735051 if (tx_info->control.hw_key) {
....@@ -4990,12 +5068,19 @@
49905068 if (ieee80211_is_data_qos(hdr->frame_control) && sta) {
49915069 if (sta->ht_cap.ht_supported) {
49925070 u32 ampdu, val32;
5071
+ u8 *qc = ieee80211_get_qos_ctl(hdr);
5072
+ u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
49935073
49945074 ampdu = (u32)sta->ht_cap.ampdu_density;
49955075 val32 = ampdu << TXDESC_AMPDU_DENSITY_SHIFT;
49965076 tx_desc->txdw2 |= cpu_to_le32(val32);
49975077
49985078 ampdu_enable = true;
5079
+
5080
+ if (!test_bit(tid, priv->tx_aggr_started) &&
5081
+ !(skb->protocol == cpu_to_be16(ETH_P_PAE)))
5082
+ if (!ieee80211_start_tx_ba_session(sta, tid, 0))
5083
+ set_bit(tid, priv->tx_aggr_started);
49995084 }
50005085 }
50015086
....@@ -5016,7 +5101,6 @@
50165101 else
50175102 rts_rate = 0;
50185103
5019
- seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
50205104
50215105 priv->fops->fill_txdesc(hw, hdr, tx_info, tx_desc, sgi, short_preamble,
50225106 ampdu_enable, rts_rate);
....@@ -5157,12 +5241,325 @@
51575241 }
51585242 }
51595243
5244
+/*
5245
+ * The RTL8723BU/RTL8192EU vendor driver use coexistence table type
5246
+ * 0-7 to represent writing different combinations of register values
5247
+ * to REG_BT_COEX_TABLEs. It's for different kinds of coexistence use
5248
+ * cases which Realtek doesn't provide detail for these settings. Keep
5249
+ * this aligned with vendor driver for easier maintenance.
5250
+ */
5251
+static
5252
+void rtl8723bu_set_coex_with_type(struct rtl8xxxu_priv *priv, u8 type)
5253
+{
5254
+ switch (type) {
5255
+ case 0:
5256
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555);
5257
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x55555555);
5258
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5259
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5260
+ break;
5261
+ case 1:
5262
+ case 3:
5263
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555);
5264
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x5a5a5a5a);
5265
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5266
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5267
+ break;
5268
+ case 2:
5269
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x5a5a5a5a);
5270
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0x5a5a5a5a);
5271
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5272
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5273
+ break;
5274
+ case 4:
5275
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x5a5a5a5a);
5276
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0xaaaa5a5a);
5277
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5278
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5279
+ break;
5280
+ case 5:
5281
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x5a5a5a5a);
5282
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0xaa5a5a5a);
5283
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5284
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5285
+ break;
5286
+ case 6:
5287
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0x55555555);
5288
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0xaaaaaaaa);
5289
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5290
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5291
+ break;
5292
+ case 7:
5293
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE1, 0xaaaaaaaa);
5294
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE2, 0xaaaaaaaa);
5295
+ rtl8xxxu_write32(priv, REG_BT_COEX_TABLE3, 0x00ffffff);
5296
+ rtl8xxxu_write8(priv, REG_BT_COEX_TABLE4, 0x03);
5297
+ break;
5298
+ default:
5299
+ break;
5300
+ }
5301
+}
5302
+
5303
+static
5304
+void rtl8723bu_update_bt_link_info(struct rtl8xxxu_priv *priv, u8 bt_info)
5305
+{
5306
+ struct rtl8xxxu_btcoex *btcoex = &priv->bt_coex;
5307
+
5308
+ if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE)
5309
+ btcoex->c2h_bt_inquiry = true;
5310
+ else
5311
+ btcoex->c2h_bt_inquiry = false;
5312
+
5313
+ if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
5314
+ btcoex->bt_status = BT_8723B_1ANT_STATUS_NON_CONNECTED_IDLE;
5315
+ btcoex->has_sco = false;
5316
+ btcoex->has_hid = false;
5317
+ btcoex->has_pan = false;
5318
+ btcoex->has_a2dp = false;
5319
+ } else {
5320
+ if ((bt_info & 0x1f) == BT_INFO_8723B_1ANT_B_CONNECTION)
5321
+ btcoex->bt_status = BT_8723B_1ANT_STATUS_CONNECTED_IDLE;
5322
+ else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
5323
+ (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY))
5324
+ btcoex->bt_status = BT_8723B_1ANT_STATUS_SCO_BUSY;
5325
+ else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY)
5326
+ btcoex->bt_status = BT_8723B_1ANT_STATUS_ACL_BUSY;
5327
+ else
5328
+ btcoex->bt_status = BT_8723B_1ANT_STATUS_MAX;
5329
+
5330
+ if (bt_info & BT_INFO_8723B_1ANT_B_FTP)
5331
+ btcoex->has_pan = true;
5332
+ else
5333
+ btcoex->has_pan = false;
5334
+
5335
+ if (bt_info & BT_INFO_8723B_1ANT_B_A2DP)
5336
+ btcoex->has_a2dp = true;
5337
+ else
5338
+ btcoex->has_a2dp = false;
5339
+
5340
+ if (bt_info & BT_INFO_8723B_1ANT_B_HID)
5341
+ btcoex->has_hid = true;
5342
+ else
5343
+ btcoex->has_hid = false;
5344
+
5345
+ if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO)
5346
+ btcoex->has_sco = true;
5347
+ else
5348
+ btcoex->has_sco = false;
5349
+ }
5350
+
5351
+ if (!btcoex->has_a2dp && !btcoex->has_sco &&
5352
+ !btcoex->has_pan && btcoex->has_hid)
5353
+ btcoex->hid_only = true;
5354
+ else
5355
+ btcoex->hid_only = false;
5356
+
5357
+ if (!btcoex->has_sco && !btcoex->has_pan &&
5358
+ !btcoex->has_hid && btcoex->has_a2dp)
5359
+ btcoex->has_a2dp = true;
5360
+ else
5361
+ btcoex->has_a2dp = false;
5362
+
5363
+ if (btcoex->bt_status == BT_8723B_1ANT_STATUS_SCO_BUSY ||
5364
+ btcoex->bt_status == BT_8723B_1ANT_STATUS_ACL_BUSY)
5365
+ btcoex->bt_busy = true;
5366
+ else
5367
+ btcoex->bt_busy = false;
5368
+}
5369
+
5370
+static
5371
+void rtl8723bu_handle_bt_inquiry(struct rtl8xxxu_priv *priv)
5372
+{
5373
+ struct ieee80211_vif *vif;
5374
+ struct rtl8xxxu_btcoex *btcoex;
5375
+ bool wifi_connected;
5376
+
5377
+ vif = priv->vif;
5378
+ btcoex = &priv->bt_coex;
5379
+ wifi_connected = (vif && vif->bss_conf.assoc);
5380
+
5381
+ if (!wifi_connected) {
5382
+ rtl8723bu_set_ps_tdma(priv, 0x8, 0x0, 0x0, 0x0, 0x0);
5383
+ rtl8723bu_set_coex_with_type(priv, 0);
5384
+ } else if (btcoex->has_sco || btcoex->has_hid || btcoex->has_a2dp) {
5385
+ rtl8723bu_set_ps_tdma(priv, 0x61, 0x35, 0x3, 0x11, 0x11);
5386
+ rtl8723bu_set_coex_with_type(priv, 4);
5387
+ } else if (btcoex->has_pan) {
5388
+ rtl8723bu_set_ps_tdma(priv, 0x61, 0x3f, 0x3, 0x11, 0x11);
5389
+ rtl8723bu_set_coex_with_type(priv, 4);
5390
+ } else {
5391
+ rtl8723bu_set_ps_tdma(priv, 0x8, 0x0, 0x0, 0x0, 0x0);
5392
+ rtl8723bu_set_coex_with_type(priv, 7);
5393
+ }
5394
+}
5395
+
5396
+static
5397
+void rtl8723bu_handle_bt_info(struct rtl8xxxu_priv *priv)
5398
+{
5399
+ struct ieee80211_vif *vif;
5400
+ struct rtl8xxxu_btcoex *btcoex;
5401
+ bool wifi_connected;
5402
+
5403
+ vif = priv->vif;
5404
+ btcoex = &priv->bt_coex;
5405
+ wifi_connected = (vif && vif->bss_conf.assoc);
5406
+
5407
+ if (wifi_connected) {
5408
+ u32 val32 = 0;
5409
+ u32 high_prio_tx = 0, high_prio_rx = 0;
5410
+
5411
+ val32 = rtl8xxxu_read32(priv, 0x770);
5412
+ high_prio_tx = val32 & 0x0000ffff;
5413
+ high_prio_rx = (val32 & 0xffff0000) >> 16;
5414
+
5415
+ if (btcoex->bt_busy) {
5416
+ if (btcoex->hid_only) {
5417
+ rtl8723bu_set_ps_tdma(priv, 0x61, 0x20,
5418
+ 0x3, 0x11, 0x11);
5419
+ rtl8723bu_set_coex_with_type(priv, 5);
5420
+ } else if (btcoex->a2dp_only) {
5421
+ rtl8723bu_set_ps_tdma(priv, 0x61, 0x35,
5422
+ 0x3, 0x11, 0x11);
5423
+ rtl8723bu_set_coex_with_type(priv, 4);
5424
+ } else if ((btcoex->has_a2dp && btcoex->has_pan) ||
5425
+ (btcoex->has_hid && btcoex->has_a2dp &&
5426
+ btcoex->has_pan)) {
5427
+ rtl8723bu_set_ps_tdma(priv, 0x51, 0x21,
5428
+ 0x3, 0x10, 0x10);
5429
+ rtl8723bu_set_coex_with_type(priv, 4);
5430
+ } else if (btcoex->has_hid && btcoex->has_a2dp) {
5431
+ rtl8723bu_set_ps_tdma(priv, 0x51, 0x21,
5432
+ 0x3, 0x10, 0x10);
5433
+ rtl8723bu_set_coex_with_type(priv, 3);
5434
+ } else {
5435
+ rtl8723bu_set_ps_tdma(priv, 0x61, 0x35,
5436
+ 0x3, 0x11, 0x11);
5437
+ rtl8723bu_set_coex_with_type(priv, 4);
5438
+ }
5439
+ } else {
5440
+ rtl8723bu_set_ps_tdma(priv, 0x8, 0x0, 0x0, 0x0, 0x0);
5441
+ if (high_prio_tx + high_prio_rx <= 60)
5442
+ rtl8723bu_set_coex_with_type(priv, 2);
5443
+ else
5444
+ rtl8723bu_set_coex_with_type(priv, 7);
5445
+ }
5446
+ } else {
5447
+ rtl8723bu_set_ps_tdma(priv, 0x8, 0x0, 0x0, 0x0, 0x0);
5448
+ rtl8723bu_set_coex_with_type(priv, 0);
5449
+ }
5450
+}
5451
+
5452
+static struct ieee80211_rate rtl8xxxu_legacy_ratetable[] = {
5453
+ {.bitrate = 10, .hw_value = 0x00,},
5454
+ {.bitrate = 20, .hw_value = 0x01,},
5455
+ {.bitrate = 55, .hw_value = 0x02,},
5456
+ {.bitrate = 110, .hw_value = 0x03,},
5457
+ {.bitrate = 60, .hw_value = 0x04,},
5458
+ {.bitrate = 90, .hw_value = 0x05,},
5459
+ {.bitrate = 120, .hw_value = 0x06,},
5460
+ {.bitrate = 180, .hw_value = 0x07,},
5461
+ {.bitrate = 240, .hw_value = 0x08,},
5462
+ {.bitrate = 360, .hw_value = 0x09,},
5463
+ {.bitrate = 480, .hw_value = 0x0a,},
5464
+ {.bitrate = 540, .hw_value = 0x0b,},
5465
+};
5466
+
5467
+static void rtl8xxxu_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss)
5468
+{
5469
+ if (rate <= DESC_RATE_54M)
5470
+ return;
5471
+
5472
+ if (rate >= DESC_RATE_MCS0 && rate <= DESC_RATE_MCS15) {
5473
+ if (rate < DESC_RATE_MCS8)
5474
+ *nss = 1;
5475
+ else
5476
+ *nss = 2;
5477
+ *mcs = rate - DESC_RATE_MCS0;
5478
+ }
5479
+}
5480
+
5481
+static void rtl8xxxu_c2hcmd_callback(struct work_struct *work)
5482
+{
5483
+ struct rtl8xxxu_priv *priv;
5484
+ struct rtl8723bu_c2h *c2h;
5485
+ struct sk_buff *skb = NULL;
5486
+ unsigned long flags;
5487
+ u8 bt_info = 0;
5488
+ struct rtl8xxxu_btcoex *btcoex;
5489
+ struct rtl8xxxu_ra_report *rarpt;
5490
+ u8 rate, sgi, bw;
5491
+ u32 bit_rate;
5492
+ u8 mcs = 0, nss = 0;
5493
+
5494
+ priv = container_of(work, struct rtl8xxxu_priv, c2hcmd_work);
5495
+ btcoex = &priv->bt_coex;
5496
+ rarpt = &priv->ra_report;
5497
+
5498
+ if (priv->rf_paths > 1)
5499
+ goto out;
5500
+
5501
+ while (!skb_queue_empty(&priv->c2hcmd_queue)) {
5502
+ spin_lock_irqsave(&priv->c2hcmd_lock, flags);
5503
+ skb = __skb_dequeue(&priv->c2hcmd_queue);
5504
+ spin_unlock_irqrestore(&priv->c2hcmd_lock, flags);
5505
+
5506
+ c2h = (struct rtl8723bu_c2h *)skb->data;
5507
+
5508
+ switch (c2h->id) {
5509
+ case C2H_8723B_BT_INFO:
5510
+ bt_info = c2h->bt_info.bt_info;
5511
+
5512
+ rtl8723bu_update_bt_link_info(priv, bt_info);
5513
+ if (btcoex->c2h_bt_inquiry) {
5514
+ rtl8723bu_handle_bt_inquiry(priv);
5515
+ break;
5516
+ }
5517
+ rtl8723bu_handle_bt_info(priv);
5518
+ break;
5519
+ case C2H_8723B_RA_REPORT:
5520
+ rarpt->txrate.flags = 0;
5521
+ rate = c2h->ra_report.rate;
5522
+ sgi = c2h->ra_report.sgi;
5523
+ bw = c2h->ra_report.bw;
5524
+
5525
+ if (rate < DESC_RATE_MCS0) {
5526
+ rarpt->txrate.legacy =
5527
+ rtl8xxxu_legacy_ratetable[rate].bitrate;
5528
+ } else {
5529
+ rtl8xxxu_desc_to_mcsrate(rate, &mcs, &nss);
5530
+ rarpt->txrate.flags |= RATE_INFO_FLAGS_MCS;
5531
+
5532
+ rarpt->txrate.mcs = mcs;
5533
+ rarpt->txrate.nss = nss;
5534
+
5535
+ if (sgi) {
5536
+ rarpt->txrate.flags |=
5537
+ RATE_INFO_FLAGS_SHORT_GI;
5538
+ }
5539
+
5540
+ if (bw == RATE_INFO_BW_20)
5541
+ rarpt->txrate.bw |= RATE_INFO_BW_20;
5542
+ }
5543
+ bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate);
5544
+ rarpt->bit_rate = bit_rate;
5545
+ rarpt->desc_rate = rate;
5546
+ break;
5547
+ default:
5548
+ break;
5549
+ }
5550
+ }
5551
+
5552
+out:
5553
+ dev_kfree_skb(skb);
5554
+}
5555
+
51605556 static void rtl8723bu_handle_c2h(struct rtl8xxxu_priv *priv,
51615557 struct sk_buff *skb)
51625558 {
51635559 struct rtl8723bu_c2h *c2h = (struct rtl8723bu_c2h *)skb->data;
51645560 struct device *dev = &priv->udev->dev;
51655561 int len;
5562
+ unsigned long flags;
51665563
51675564 len = skb->len - 2;
51685565
....@@ -5190,7 +5587,7 @@
51905587 case C2H_8723B_RA_REPORT:
51915588 dev_dbg(dev,
51925589 "C2H RA RPT: rate %02x, unk %i, macid %02x, noise %i\n",
5193
- c2h->ra_report.rate, c2h->ra_report.dummy0_0,
5590
+ c2h->ra_report.rate, c2h->ra_report.sgi,
51945591 c2h->ra_report.macid, c2h->ra_report.noisy_state);
51955592 break;
51965593 default:
....@@ -5200,6 +5597,12 @@
52005597 16, 1, c2h->raw.payload, len, false);
52015598 break;
52025599 }
5600
+
5601
+ spin_lock_irqsave(&priv->c2hcmd_lock, flags);
5602
+ __skb_queue_tail(&priv->c2hcmd_queue, skb);
5603
+ spin_unlock_irqrestore(&priv->c2hcmd_lock, flags);
5604
+
5605
+ schedule_work(&priv->c2hcmd_work);
52035606 }
52045607
52055608 int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb)
....@@ -5324,7 +5727,6 @@
53245727 struct device *dev = &priv->udev->dev;
53255728 dev_dbg(dev, "%s: C2H packet\n", __func__);
53265729 rtl8723bu_handle_c2h(priv, skb);
5327
- dev_kfree_skb(skb);
53285730 return RX_TYPE_C2H;
53295731 }
53305732
....@@ -5474,6 +5876,10 @@
54745876
54755877 switch (vif->type) {
54765878 case NL80211_IFTYPE_STATION:
5879
+ if (!priv->vif)
5880
+ priv->vif = vif;
5881
+ else
5882
+ return -EOPNOTSUPP;
54775883 rtl8xxxu_stop_tx_beacon(priv);
54785884
54795885 val8 = rtl8xxxu_read8(priv, REG_BEACON_CTRL);
....@@ -5497,6 +5903,9 @@
54975903 struct rtl8xxxu_priv *priv = hw->priv;
54985904
54995905 dev_dbg(&priv->udev->dev, "%s\n", __func__);
5906
+
5907
+ if (priv->vif)
5908
+ priv->vif = NULL;
55005909 }
55015910
55025911 static int rtl8xxxu_config(struct ieee80211_hw *hw, u32 changed)
....@@ -5746,6 +6155,7 @@
57466155 struct device *dev = &priv->udev->dev;
57476156 u8 ampdu_factor, ampdu_density;
57486157 struct ieee80211_sta *sta = params->sta;
6158
+ u16 tid = params->tid;
57496159 enum ieee80211_ampdu_mlme_action action = params->action;
57506160
57516161 switch (action) {
....@@ -5758,17 +6168,20 @@
57586168 dev_dbg(dev,
57596169 "Changed HT: ampdu_factor %02x, ampdu_density %02x\n",
57606170 ampdu_factor, ampdu_density);
5761
- break;
6171
+ return IEEE80211_AMPDU_TX_START_IMMEDIATE;
6172
+ case IEEE80211_AMPDU_TX_STOP_CONT:
57626173 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5763
- dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH\n", __func__);
5764
- rtl8xxxu_set_ampdu_factor(priv, 0);
5765
- rtl8xxxu_set_ampdu_min_space(priv, 0);
5766
- break;
57676174 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5768
- dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP_FLUSH_CONT\n",
5769
- __func__);
6175
+ dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_STOP\n", __func__);
57706176 rtl8xxxu_set_ampdu_factor(priv, 0);
57716177 rtl8xxxu_set_ampdu_min_space(priv, 0);
6178
+ clear_bit(tid, priv->tx_aggr_started);
6179
+ clear_bit(tid, priv->tid_tx_operational);
6180
+ ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
6181
+ break;
6182
+ case IEEE80211_AMPDU_TX_OPERATIONAL:
6183
+ dev_dbg(dev, "%s: IEEE80211_AMPDU_TX_OPERATIONAL\n", __func__);
6184
+ set_bit(tid, priv->tid_tx_operational);
57726185 break;
57736186 case IEEE80211_AMPDU_RX_START:
57746187 dev_dbg(dev, "%s: IEEE80211_AMPDU_RX_START\n", __func__);
....@@ -5780,6 +6193,188 @@
57806193 break;
57816194 }
57826195 return 0;
6196
+}
6197
+
6198
+static void
6199
+rtl8xxxu_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6200
+ struct ieee80211_sta *sta, struct station_info *sinfo)
6201
+{
6202
+ struct rtl8xxxu_priv *priv = hw->priv;
6203
+
6204
+ sinfo->txrate = priv->ra_report.txrate;
6205
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
6206
+}
6207
+
6208
+static u8 rtl8xxxu_signal_to_snr(int signal)
6209
+{
6210
+ if (signal < RTL8XXXU_NOISE_FLOOR_MIN)
6211
+ signal = RTL8XXXU_NOISE_FLOOR_MIN;
6212
+ else if (signal > 0)
6213
+ signal = 0;
6214
+ return (u8)(signal - RTL8XXXU_NOISE_FLOOR_MIN);
6215
+}
6216
+
6217
+static void rtl8xxxu_refresh_rate_mask(struct rtl8xxxu_priv *priv,
6218
+ int signal, struct ieee80211_sta *sta)
6219
+{
6220
+ struct ieee80211_hw *hw = priv->hw;
6221
+ u16 wireless_mode;
6222
+ u8 rssi_level, ratr_idx;
6223
+ u8 txbw_40mhz;
6224
+ u8 snr, snr_thresh_high, snr_thresh_low;
6225
+ u8 go_up_gap = 5;
6226
+
6227
+ rssi_level = priv->rssi_level;
6228
+ snr = rtl8xxxu_signal_to_snr(signal);
6229
+ snr_thresh_high = RTL8XXXU_SNR_THRESH_HIGH;
6230
+ snr_thresh_low = RTL8XXXU_SNR_THRESH_LOW;
6231
+ txbw_40mhz = (hw->conf.chandef.width == NL80211_CHAN_WIDTH_40) ? 1 : 0;
6232
+
6233
+ switch (rssi_level) {
6234
+ case RTL8XXXU_RATR_STA_MID:
6235
+ snr_thresh_high += go_up_gap;
6236
+ break;
6237
+ case RTL8XXXU_RATR_STA_LOW:
6238
+ snr_thresh_high += go_up_gap;
6239
+ snr_thresh_low += go_up_gap;
6240
+ break;
6241
+ default:
6242
+ break;
6243
+ }
6244
+
6245
+ if (snr > snr_thresh_high)
6246
+ rssi_level = RTL8XXXU_RATR_STA_HIGH;
6247
+ else if (snr > snr_thresh_low)
6248
+ rssi_level = RTL8XXXU_RATR_STA_MID;
6249
+ else
6250
+ rssi_level = RTL8XXXU_RATR_STA_LOW;
6251
+
6252
+ if (rssi_level != priv->rssi_level) {
6253
+ int sgi = 0;
6254
+ u32 rate_bitmap = 0;
6255
+
6256
+ rcu_read_lock();
6257
+ rate_bitmap = (sta->supp_rates[0] & 0xfff) |
6258
+ (sta->ht_cap.mcs.rx_mask[0] << 12) |
6259
+ (sta->ht_cap.mcs.rx_mask[1] << 20);
6260
+ if (sta->ht_cap.cap &
6261
+ (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
6262
+ sgi = 1;
6263
+ rcu_read_unlock();
6264
+
6265
+ wireless_mode = rtl8xxxu_wireless_mode(hw, sta);
6266
+ switch (wireless_mode) {
6267
+ case WIRELESS_MODE_B:
6268
+ ratr_idx = RATEID_IDX_B;
6269
+ if (rate_bitmap & 0x0000000c)
6270
+ rate_bitmap &= 0x0000000d;
6271
+ else
6272
+ rate_bitmap &= 0x0000000f;
6273
+ break;
6274
+ case WIRELESS_MODE_A:
6275
+ case WIRELESS_MODE_G:
6276
+ ratr_idx = RATEID_IDX_G;
6277
+ if (rssi_level == RTL8XXXU_RATR_STA_HIGH)
6278
+ rate_bitmap &= 0x00000f00;
6279
+ else
6280
+ rate_bitmap &= 0x00000ff0;
6281
+ break;
6282
+ case (WIRELESS_MODE_B | WIRELESS_MODE_G):
6283
+ ratr_idx = RATEID_IDX_BG;
6284
+ if (rssi_level == RTL8XXXU_RATR_STA_HIGH)
6285
+ rate_bitmap &= 0x00000f00;
6286
+ else if (rssi_level == RTL8XXXU_RATR_STA_MID)
6287
+ rate_bitmap &= 0x00000ff0;
6288
+ else
6289
+ rate_bitmap &= 0x00000ff5;
6290
+ break;
6291
+ case WIRELESS_MODE_N_24G:
6292
+ case WIRELESS_MODE_N_5G:
6293
+ case (WIRELESS_MODE_G | WIRELESS_MODE_N_24G):
6294
+ case (WIRELESS_MODE_A | WIRELESS_MODE_N_5G):
6295
+ if (priv->tx_paths == 2 && priv->rx_paths == 2)
6296
+ ratr_idx = RATEID_IDX_GN_N2SS;
6297
+ else
6298
+ ratr_idx = RATEID_IDX_GN_N1SS;
6299
+ break;
6300
+ case (WIRELESS_MODE_B | WIRELESS_MODE_G | WIRELESS_MODE_N_24G):
6301
+ case (WIRELESS_MODE_B | WIRELESS_MODE_N_24G):
6302
+ if (txbw_40mhz) {
6303
+ if (priv->tx_paths == 2 && priv->rx_paths == 2)
6304
+ ratr_idx = RATEID_IDX_BGN_40M_2SS;
6305
+ else
6306
+ ratr_idx = RATEID_IDX_BGN_40M_1SS;
6307
+ } else {
6308
+ if (priv->tx_paths == 2 && priv->rx_paths == 2)
6309
+ ratr_idx = RATEID_IDX_BGN_20M_2SS_BN;
6310
+ else
6311
+ ratr_idx = RATEID_IDX_BGN_20M_1SS_BN;
6312
+ }
6313
+
6314
+ if (priv->tx_paths == 2 && priv->rx_paths == 2) {
6315
+ if (rssi_level == RTL8XXXU_RATR_STA_HIGH) {
6316
+ rate_bitmap &= 0x0f8f0000;
6317
+ } else if (rssi_level == RTL8XXXU_RATR_STA_MID) {
6318
+ rate_bitmap &= 0x0f8ff000;
6319
+ } else {
6320
+ if (txbw_40mhz)
6321
+ rate_bitmap &= 0x0f8ff015;
6322
+ else
6323
+ rate_bitmap &= 0x0f8ff005;
6324
+ }
6325
+ } else {
6326
+ if (rssi_level == RTL8XXXU_RATR_STA_HIGH) {
6327
+ rate_bitmap &= 0x000f0000;
6328
+ } else if (rssi_level == RTL8XXXU_RATR_STA_MID) {
6329
+ rate_bitmap &= 0x000ff000;
6330
+ } else {
6331
+ if (txbw_40mhz)
6332
+ rate_bitmap &= 0x000ff015;
6333
+ else
6334
+ rate_bitmap &= 0x000ff005;
6335
+ }
6336
+ }
6337
+ break;
6338
+ default:
6339
+ ratr_idx = RATEID_IDX_BGN_40M_2SS;
6340
+ rate_bitmap &= 0x0fffffff;
6341
+ break;
6342
+ }
6343
+
6344
+ priv->rssi_level = rssi_level;
6345
+ priv->fops->update_rate_mask(priv, rate_bitmap, ratr_idx, sgi);
6346
+ }
6347
+}
6348
+
6349
+static void rtl8xxxu_watchdog_callback(struct work_struct *work)
6350
+{
6351
+ struct ieee80211_vif *vif;
6352
+ struct rtl8xxxu_priv *priv;
6353
+
6354
+ priv = container_of(work, struct rtl8xxxu_priv, ra_watchdog.work);
6355
+ vif = priv->vif;
6356
+
6357
+ if (vif && vif->type == NL80211_IFTYPE_STATION) {
6358
+ int signal;
6359
+ struct ieee80211_sta *sta;
6360
+
6361
+ rcu_read_lock();
6362
+ sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
6363
+ if (!sta) {
6364
+ struct device *dev = &priv->udev->dev;
6365
+
6366
+ dev_dbg(dev, "%s: no sta found\n", __func__);
6367
+ rcu_read_unlock();
6368
+ goto out;
6369
+ }
6370
+ rcu_read_unlock();
6371
+
6372
+ signal = ieee80211_ave_rssi(vif);
6373
+ rtl8xxxu_refresh_rate_mask(priv, signal, sta);
6374
+ }
6375
+
6376
+out:
6377
+ schedule_delayed_work(&priv->ra_watchdog, 2 * HZ);
57836378 }
57846379
57856380 static int rtl8xxxu_start(struct ieee80211_hw *hw)
....@@ -5846,6 +6441,8 @@
58466441 rtl8xxxu_queue_rx_urb(priv, rx_urb);
58476442 }
58486443 }
6444
+
6445
+ schedule_delayed_work(&priv->ra_watchdog, 2 * HZ);
58496446 exit:
58506447 /*
58516448 * Accept all data and mgmt frames
....@@ -5897,6 +6494,8 @@
58976494 if (priv->usb_interrupts)
58986495 rtl8xxxu_write32(priv, REG_USB_HIMR, 0);
58996496
6497
+ cancel_delayed_work_sync(&priv->ra_watchdog);
6498
+
59006499 rtl8xxxu_free_rx_resources(priv);
59016500 rtl8xxxu_free_tx_resources(priv);
59026501 }
....@@ -5916,6 +6515,7 @@
59166515 .sw_scan_complete = rtl8xxxu_sw_scan_complete,
59176516 .set_key = rtl8xxxu_set_key,
59186517 .ampdu_action = rtl8xxxu_ampdu_action,
6518
+ .sta_statistics = rtl8xxxu_sta_statistics,
59196519 };
59206520
59216521 static int rtl8xxxu_parse_usb(struct rtl8xxxu_priv *priv,
....@@ -6019,7 +6619,7 @@
60196619 }
60206620 break;
60216621 case 0x7392:
6022
- if (id->idProduct == 0x7811)
6622
+ if (id->idProduct == 0x7811 || id->idProduct == 0xa611)
60236623 untested = 0;
60246624 break;
60256625 case 0x050d:
....@@ -6069,6 +6669,10 @@
60696669 INIT_LIST_HEAD(&priv->rx_urb_pending_list);
60706670 spin_lock_init(&priv->rx_urb_lock);
60716671 INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);
6672
+ INIT_DELAYED_WORK(&priv->ra_watchdog, rtl8xxxu_watchdog_callback);
6673
+ spin_lock_init(&priv->c2hcmd_lock);
6674
+ INIT_WORK(&priv->c2hcmd_work, rtl8xxxu_c2hcmd_callback);
6675
+ skb_queue_head_init(&priv->c2hcmd_queue);
60726676
60736677 usb_set_intfdata(interface, hw);
60746678
....@@ -6223,6 +6827,8 @@
62236827 .driver_info = (unsigned long)&rtl8192eu_fops},
62246828 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0xb720, 0xff, 0xff, 0xff),
62256829 .driver_info = (unsigned long)&rtl8723bu_fops},
6830
+{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xa611, 0xff, 0xff, 0xff),
6831
+ .driver_info = (unsigned long)&rtl8723bu_fops},
62266832 #ifdef CONFIG_RTL8XXXU_UNTESTED
62276833 /* Still supported by rtlwifi */
62286834 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8176, 0xff, 0xff, 0xff),
....@@ -6244,6 +6850,8 @@
62446850 {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x3308, 0xff, 0xff, 0xff),
62456851 .driver_info = (unsigned long)&rtl8192cu_fops},
62466852 /* Currently untested 8188 series devices */
6853
+{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x018a, 0xff, 0xff, 0xff),
6854
+ .driver_info = (unsigned long)&rtl8192cu_fops},
62476855 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8191, 0xff, 0xff, 0xff),
62486856 .driver_info = (unsigned long)&rtl8192cu_fops},
62496857 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8170, 0xff, 0xff, 0xff),