Intel 8260 Firmware Init Failure

2018-11-16 Thread Tom Gutteridge
What can I do about this? My wireless card is unusable. Seems to be a
spontaneous failure. This is the output of dmesg | grep iwlwifi:

[7.206387] iwlwifi :02:00.0: enabling device ( -> 0002)
[7.215066] iwlwifi :02:00.0: loaded firmware version
36.7596afd4.0 op_mode iwlmvm
[7.686950] iwlwifi :02:00.0: Detected Intel(R) Dual Band
Wireless AC 8260, REV=0x208
[7.769839] iwlwifi :02:00.0: base HW address: 14:ab:c5:7c:5e:a2
[7.770427] iwlwifi :02:00.0: Microcode SW error detected.
Restarting 0x200.
[7.770555] iwlwifi :02:00.0: Start IWL Error Log Dump:
[7.770557] iwlwifi :02:00.0: Status: 0x0100, count: 6
[7.770559] iwlwifi :02:00.0: Loaded firmware version: 36.7596afd4.0
[7.770561] iwlwifi :02:00.0: 0x1392 | ADVANCED_SYSASSERT
[7.770562] iwlwifi :02:00.0: 0x02F2 | trm_hw_status0
[7.770564] iwlwifi :02:00.0: 0x | trm_hw_status1
[7.770565] iwlwifi :02:00.0: 0x000124BE | branchlink2
[7.770566] iwlwifi :02:00.0: 0x0001C1E2 | interruptlink1
[7.770568] iwlwifi :02:00.0: 0x | interruptlink2
[7.770569] iwlwifi :02:00.0: 0x010B | data1
[7.770570] iwlwifi :02:00.0: 0x | data2
[7.770572] iwlwifi :02:00.0: 0xDEADBEEF | data3
[7.770573] iwlwifi :02:00.0: 0x | beacon time
[7.770574] iwlwifi :02:00.0: 0x169F | tsf low
[7.770576] iwlwifi :02:00.0: 0x | tsf hi
[7.770577] iwlwifi :02:00.0: 0x | time gp1
[7.770578] iwlwifi :02:00.0: 0x169F | time gp2
[7.770580] iwlwifi :02:00.0: 0x0009 | uCode revision type
[7.770581] iwlwifi :02:00.0: 0x0024 | uCode version major
[7.770583] iwlwifi :02:00.0: 0x7596AFD4 | uCode version minor
[7.770584] iwlwifi :02:00.0: 0x0201 | hw version
[7.770585] iwlwifi :02:00.0: 0x00489008 | board version
[7.770587] iwlwifi :02:00.0: 0x0010016A | hcmd
[7.770588] iwlwifi :02:00.0: 0x02322080 | isr0
[7.770589] iwlwifi :02:00.0: 0x | isr1
[7.770591] iwlwifi :02:00.0: 0x28201802 | isr2
[7.770592] iwlwifi :02:00.0: 0x004000C0 | isr3
[7.770593] iwlwifi :02:00.0: 0x | isr4
[7.770595] iwlwifi :02:00.0: 0x0010016A | last cmd Id
[7.770596] iwlwifi :02:00.0: 0x | wait_event
[7.770598] iwlwifi :02:00.0: 0xE45C | l2p_control
[7.770599] iwlwifi :02:00.0: 0x1420 | l2p_duration
[7.770600] iwlwifi :02:00.0: 0x | l2p_mhvalid
[7.770602] iwlwifi :02:00.0: 0x | l2p_addr_match
[7.770603] iwlwifi :02:00.0: 0x000D | lmpm_pmg_sel
[7.770604] iwlwifi :02:00.0: 0x22040707 | timestamp
[7.770606] iwlwifi :02:00.0: 0x0818 | flow_handler
[7.770669] iwlwifi :02:00.0: Start IWL Error Log Dump:
[7.770670] iwlwifi :02:00.0: Status: 0x0100, count: 7
[7.770672] iwlwifi :02:00.0: 0x0070 | ADVANCED_SYSASSERT
[7.770673] iwlwifi :02:00.0: 0x | umac branchlink1
[7.770674] iwlwifi :02:00.0: 0xC0086AA4 | umac branchlink2
[7.770675] iwlwifi :02:00.0: 0xC0083CB0 | umac interruptlink1
[7.770677] iwlwifi :02:00.0: 0xC0083C90 | umac interruptlink2
[7.770678] iwlwifi :02:00.0: 0x0800 | umac data1
[7.770679] iwlwifi :02:00.0: 0xC0083C90 | umac data2
[7.770682] iwlwifi :02:00.0: 0xDEADBEEF | umac data3
[7.770683] iwlwifi :02:00.0: 0x0024 | umac major
[7.770684] iwlwifi :02:00.0: 0x7596AFD4 | umac minor
[7.770686] iwlwifi :02:00.0: 0xC088628C | frame pointer
[7.770687] iwlwifi :02:00.0: 0xC088628C | stack pointer
[7.770688] iwlwifi :02:00.0: 0x0010016A | last host cmd
[7.770690] iwlwifi :02:00.0: 0x | isr status reg
[7.770697] iwlwifi :02:00.0: Failed to run INIT calibrations: -5
[7.770699] iwlwifi :02:00.0: Failed to run INIT ucode: -5

uname -a gives:
Linux tomg-p5510 4.19.1-1-MANJARO #1 SMP PREEMPT Sun Nov 4 16:05:34
UTC 2018 x86_64 GNU/Linux

This happened once before, about a year ago. It resolved itself when I
tried installing Windows 10 and running an update. Now when I try a
clean install of Windows 10 it bluescreens on startup with probable
cause Netwtw06.sys.

Thanks,
Tom.


Re: [EXTERNAL] [PATCH] ath9k_htc: add fw 1.4.1

2018-11-16 Thread Tom Psyborg
Every build attempt of the firmware without modifying the code results
in same checksum of the built file. So I guess this should be easy to
verify.


Re: [PATCH v2 6/7] mt76: mt76x02: remove mt76x02_txq_init

2018-11-16 Thread Lorenzo Bianconi
> Open-coding it simplifies the code
>
> Signed-off-by: Felix Fietkau 
> ---
>  .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 23 ---
>  .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  2 --
>  .../net/wireless/mediatek/mt76/mt76x02_util.c | 15 +---
>  3 files changed, 12 insertions(+), 28 deletions(-)
>

[...]

> @@ -191,8 +191,13 @@ int mt76x02_sta_add(struct ieee80211_hw *hw, struct 
> ieee80211_vif *vif,
> msta->wcid.hw_key_idx = -1;
> mt76x02_mac_wcid_setup(dev, idx, mvif->idx, sta->addr);
> mt76x02_mac_wcid_set_drop(dev, idx, false);
> -   for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
> -   mt76x02_txq_init(dev, sta->txq[i]);
> +   for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
> +   struct mt76_txq *mtxq;
> +
> +   mtxq = (struct mt76_txq *) sta->txq[i]->drv_priv;

I think sta->txq[i] can be NULL here

> +   mtxq->wcid = >wcid;
> +   mt76_txq_init(>mt76, sta->txq[i]);
> +   }
>
> if (vif->type == NL80211_IFTYPE_AP)
> set_bit(MT_WCID_FLAG_CHECK_PS, >wcid.flags);
> @@ -230,11 +235,15 @@ void mt76x02_vif_init(struct mt76x02_dev *dev, struct 
> ieee80211_vif *vif,
>   unsigned int idx)
>  {
> struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;
> +   struct mt76_txq *mtxq;
>
> mvif->idx = idx;
> mvif->group_wcid.idx = MT_VIF_WCID(idx);
> mvif->group_wcid.hw_key_idx = -1;
> -   mt76x02_txq_init(dev, vif->txq);
> +   mtxq = (struct mt76_txq *) vif->txq->drv_priv;
> +   mtxq->wcid = >group_wcid;
> +
> +   mt76_txq_init(>mt76, vif->txq);
>  }
>  EXPORT_SYMBOL_GPL(mt76x02_vif_init);
>
> --
> 2.17.0
>


-- 
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch;
unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp;
umount; make clean; sleep


Re: [PATCH FIX] brcmfmac: fix reporting support for 160 MHz channels

2018-11-16 Thread Kalle Valo
Rafał Miłecki wrote:

> From: Rafał Miłecki 
> 
> Driver can report IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ so it's
> important to provide valid & complete info about supported bands for
> each channel. By default no support for 160 MHz should be assumed unless
> firmware reports it for a given channel later.
> 
> This fixes info passed to the userspace. Without that change userspace
> could try to use invalid channel and fail to start an interface.
> 
> Signed-off-by: Rafał Miłecki 
> Cc: sta...@vger.kernel.org

Patch applied to wireless-drivers.git, thanks.

d1fe6ad6f6bd brcmfmac: fix reporting support for 160 MHz channels

-- 
https://patchwork.kernel.org/patch/10674521/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



[PATCH v3 7/7] mt76: replace sta_add/remove ops with common sta_state function

2018-11-16 Thread Felix Fietkau
Allows adding unassociated stations from mac80211

Signed-off-by: Felix Fietkau 
Signed-off-by: Lorenzo Bianconi 
---
v3: fix typo in mt76x2u

 drivers/net/wireless/mediatek/mt76/mac80211.c | 61 ++-
 drivers/net/wireless/mediatek/mt76/mt76.h | 12 +++-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  5 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  5 +-
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  8 +--
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 40 +++-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  2 +
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  3 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  2 +
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  3 +-
 10 files changed, 92 insertions(+), 49 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c 
b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 1098919f5498..d3f94163ef8e 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -631,8 +631,40 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum 
mt76_rxq_id q,
 }
 EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
 
-void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
-struct ieee80211_sta *sta)
+static int
+mt76_sta_add(struct mt76_dev *dev, struct ieee80211_vif *vif,
+struct ieee80211_sta *sta)
+{
+   struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+   int ret;
+   int i;
+
+   mutex_lock(>mutex);
+
+   ret = dev->drv->sta_add(dev, vif, sta);
+   if (ret)
+   goto out;
+
+   for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
+   struct mt76_txq *mtxq;
+
+   mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
+   mtxq->wcid = wcid;
+
+   mt76_txq_init(dev, sta->txq[i]);
+   }
+
+   rcu_assign_pointer(dev->wcid[wcid->idx], wcid);
+
+out:
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+
+static void
+mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
+   struct ieee80211_sta *sta)
 {
struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
int idx = wcid->idx;
@@ -642,10 +674,33 @@ void mt76_sta_remove(struct mt76_dev *dev, struct 
ieee80211_vif *vif,
synchronize_rcu();
 
mutex_lock(>mutex);
+
+   if (dev->drv->sta_remove)
+   dev->drv->sta_remove(dev, vif, sta);
+
mt76_tx_status_check(dev, wcid, true);
for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
mt76_txq_remove(dev, sta->txq[i]);
mt76_wcid_free(dev->wcid_mask, idx);
+
mutex_unlock(>mutex);
 }
-EXPORT_SYMBOL_GPL(mt76_sta_remove);
+
+int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta,
+  enum ieee80211_sta_state old_state,
+  enum ieee80211_sta_state new_state)
+{
+   struct mt76_dev *dev = hw->priv;
+
+   if (old_state == IEEE80211_STA_NOTEXIST &&
+   new_state == IEEE80211_STA_NONE)
+   return mt76_sta_add(dev, vif, sta);
+
+   if (old_state == IEEE80211_STA_NONE &&
+new_state == IEEE80211_STA_NOTEXIST)
+   mt76_sta_remove(dev, vif, sta);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(mt76_sta_state);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index 878836fe80d3..5cd508a68609 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -288,6 +288,12 @@ struct mt76_driver_ops {
 
void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,
   bool ps);
+
+   int (*sta_add)(struct mt76_dev *dev, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta);
+
+   void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta);
 };
 
 struct mt76_channel_state {
@@ -664,8 +670,10 @@ void mt76_tx_status_skb_done(struct mt76_dev *dev, struct 
sk_buff *skb,
 void mt76_tx_complete_skb(struct mt76_dev *dev, struct sk_buff *skb);
 void mt76_tx_status_check(struct mt76_dev *dev, struct mt76_wcid *wcid,
  bool flush);
-void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
-struct ieee80211_sta *sta);
+int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta,
+  enum ieee80211_sta_state old_state,
+  enum ieee80211_sta_state new_state);
 
 struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 757816d2b1ab..d895b6f3dc44 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ 

[PATCH] cfg80211: Allow drivers to advertise supported AKM suites

2018-11-16 Thread Veerendranath Jakkam
There was no such capability advertisement from the driver and thus the
current user space has to assume the driver to support all the AKMs. While
that may be the case with some drivers (e.g., mac80211-based ones), there
are cfg80211-based drivers that have constraints on which AKMs can be used.
Allow such drivers to advertise the exact set of supported AKMs so that
user space tools can determine what network profile options should be
allowed to be configured.

Signed-off-by: Veerendranath Jakkam 
---
 include/net/cfg80211.h   | 5 +
 include/uapi/linux/nl80211.h | 4 
 net/wireless/nl80211.c   | 6 ++
 3 files changed, 15 insertions(+)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index ede7fcd..7cff5ab 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -4110,6 +4110,8 @@ struct cfg80211_pmsr_capabilities {
  * @signal_type: signal type reported in  cfg80211_bss.
  * @cipher_suites: supported cipher suites
  * @n_cipher_suites: number of supported cipher suites
+ * @akm_suites: supported AKM suites
+ * @n_akm_suites: number of supported AKM suites
  * @retry_short: Retry limit for short frames (dot11ShortRetryLimit)
  * @retry_long: Retry limit for long frames (dot11LongRetryLimit)
  * @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold);
@@ -4308,6 +4310,9 @@ struct wiphy {
int n_cipher_suites;
const u32 *cipher_suites;
 
+   int n_akm_suites;
+   const u32 *akm_suites;
+
u8 retry_short;
u8 retry_long;
u32 frag_threshold;
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h
index 51bd85b..c21c238 100644
--- a/include/uapi/linux/nl80211.h
+++ b/include/uapi/linux/nl80211.h
@@ -1558,6 +1558,10 @@ enum nl80211_commands {
  * (a u32 with flags from  nl80211_wpa_versions).
  * @NL80211_ATTR_AKM_SUITES: Used with CONNECT, ASSOCIATE, and NEW_BEACON to
  * indicate which key management algorithm(s) to use (an array of u32).
+ * This attribute is also sent in response to @NL80211_CMD_GET_WIPHY,
+ * indicating the supported AKM suites. If there is no such notification
+ * from the driver, user space should assume the driver supports all the
+ * AKM suites.
  *
  * @NL80211_ATTR_REQ_IE: (Re)association request information elements as
  * sent out by the card, for ROAM and successful CONNECT events.
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index e20329b..3974752c 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2269,6 +2269,12 @@ static int nl80211_send_wiphy(struct 
cfg80211_registered_device *rdev,
if (nl80211_send_pmsr_capa(rdev, msg))
goto nla_put_failure;
 
+   if (rdev->wiphy.akm_suites)
+   if (nla_put(msg, NL80211_ATTR_AKM_SUITES,
+   sizeof(u32) * rdev->wiphy.n_akm_suites,
+   rdev->wiphy.akm_suites))
+   goto nla_put_failure;
+
/* done */
state->split_start = 0;
break;
-- 
1.9.1



[PATCH v2 07/13] rtw88: phy files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

phy files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/phy.c | 1670 ++
 drivers/net/wireless/realtek/rtw88/phy.h |  125 +++
 2 files changed, 1795 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/phy.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/phy.h

diff --git a/drivers/net/wireless/realtek/rtw88/phy.c 
b/drivers/net/wireless/realtek/rtw88/phy.c
new file mode 100644
index 000..51b7fca
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/phy.c
@@ -0,0 +1,1670 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include 
+
+#include "main.h"
+#include "fw.h"
+#include "phy.h"
+#include "debug.h"
+
+struct phy_cfg_pair {
+   u32 addr;
+   u32 data;
+};
+
+union phy_table_tile {
+   struct rtw_phy_cond cond;
+   struct phy_cfg_pair cfg;
+};
+
+struct phy_pg_cfg_pair {
+   u32 band;
+   u32 rf_path;
+   u32 tx_num;
+   u32 addr;
+   u32 bitmask;
+   u32 data;
+};
+
+struct txpwr_lmt_cfg_pair {
+   u8 regd;
+   u8 band;
+   u8 bw;
+   u8 rs;
+   u8 ch;
+   s8 txpwr_lmt;
+};
+
+static const u32 db_invert_table[12][8] = {
+   {10,13, 16, 20,
+25,32, 40, 50},
+   {64,80, 101,128,
+160,   201,256,318},
+   {401,   505,635,800,
+1007,  1268,   1596,   2010},
+   {316,   398,501,631,
+794,   1000,   1259,   1585},
+   {1995,  2512,   3162,   3981,
+5012,  6310,   7943,   1},
+   {12589, 15849,  19953,  25119,
+31623, 39811,  50119,  63098},
+   {79433, 10, 125893, 158489,
+199526,251189, 316228, 398107},
+   {501187,630957, 794328, 100,
+1258925,   1584893,1995262,2511886},
+   {3162278,   3981072,5011872,6309573,
+7943282,   100,12589254,   15848932},
+   {19952623,  25118864,   31622777,   39810717,
+50118723,  63095734,   79432823,   1},
+   {125892541, 158489319,  199526232,  251188643,
+316227766, 398107171,  501187234,  630957345},
+   {794328235, 10, 1258925412, 1584893192,
+1995262315,2511886432U,3162277660U,3981071706U}
+};
+
+enum rtw_phy_band_type {
+   PHY_BAND_2G = 0,
+   PHY_BAND_5G = 1,
+};
+
+void rtw_phy_init(struct rtw_dev *rtwdev)
+{
+   struct rtw_chip_info *chip = rtwdev->chip;
+   struct rtw_dm_info *dm_info = >dm_info;
+   u32 addr, mask;
+
+   dm_info->fa_history[3] = 0;
+   dm_info->fa_history[2] = 0;
+   dm_info->fa_history[1] = 0;
+   dm_info->fa_history[0] = 0;
+   dm_info->igi_bitmap = 0;
+   dm_info->igi_history[3] = 0;
+   dm_info->igi_history[2] = 0;
+   dm_info->igi_history[1] = 0;
+
+   addr = chip->dig[0].addr;
+   mask = chip->dig[0].mask;
+   dm_info->igi_history[0] = rtw_read32_mask(rtwdev, addr, mask);
+}
+
+void rtw_phy_dig_write(struct rtw_dev *rtwdev, u8 igi)
+{
+   struct rtw_chip_info *chip = rtwdev->chip;
+   struct rtw_hal *hal = >hal;
+   u32 addr, mask;
+   u8 path;
+
+   for (path = 0; path < hal->rf_path_num; path++) {
+   addr = chip->dig[path].addr;
+   mask = chip->dig[path].mask;
+   rtw_write32_mask(rtwdev, addr, mask, igi);
+   }
+}
+
+static void rtw_phy_stat_false_alarm(struct rtw_dev *rtwdev)
+{
+   struct rtw_chip_info *chip = rtwdev->chip;
+
+   chip->ops->false_alarm_statistics(rtwdev);
+}
+
+#define RA_FLOOR_TABLE_SIZE7
+#define RA_FLOOR_UP_GAP3
+
+static u8 rtw_phy_get_rssi_level(u8 old_level, u8 rssi)
+{
+   u8 table[RA_FLOOR_TABLE_SIZE] = {20, 34, 38, 42, 46, 50, 100};
+   u8 new_level = 0;
+   int i;
+
+   for (i = 0; i < RA_FLOOR_TABLE_SIZE; i++)
+   if (i >= old_level)
+   table[i] += RA_FLOOR_UP_GAP;
+
+   for (i = 0; i < RA_FLOOR_TABLE_SIZE; i++) {
+   if (rssi < table[i]) {
+   new_level = i;
+   break;
+   }
+   }
+
+   return new_level;
+}
+
+struct rtw_phy_stat_iter_data {
+   struct rtw_dev *rtwdev;
+   u8 min_rssi;
+};
+
+static void rtw_phy_stat_rssi_iter(void *data, struct ieee80211_sta *sta)
+{
+   struct rtw_phy_stat_iter_data *iter_data = data;
+   struct rtw_dev 

[PATCH v2 09/13] rtw88: chip files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

chip files Realtek 802.11ac wireless network chips
8822B & 8822C series files

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/rtw8822b.c  | 1590 
 drivers/net/wireless/realtek/rtw88/rtw8822b.h  |  155 ++
 .../net/wireless/realtek/rtw88/rtw8822b_table.h|   18 +
 drivers/net/wireless/realtek/rtw88/rtw8822c.c  | 1169 ++
 drivers/net/wireless/realtek/rtw88/rtw8822c.h  |  171 +++
 .../net/wireless/realtek/rtw88/rtw8822c_table.h|   16 +
 6 files changed, 3119 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822b.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822b.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822b_table.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822c.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822c.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822c_table.h

diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822b.c 
b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
new file mode 100644
index 000..0339041
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
@@ -0,0 +1,1590 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "fw.h"
+#include "tx.h"
+#include "rx.h"
+#include "phy.h"
+#include "rtw8822b.h"
+#include "rtw8822b_table.h"
+#include "mac.h"
+#include "reg.h"
+#include "debug.h"
+
+static void rtw8822b_config_trx_mode(struct rtw_dev *rtwdev, u8 tx_path,
+u8 rx_path, bool is_tx2_path);
+
+static void rtw8822be_efuse_parsing(struct rtw_efuse *efuse,
+   struct rtw8822b_efuse *map)
+{
+   ether_addr_copy(efuse->addr, map->e.mac_addr);
+}
+
+static int rtw8822b_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
+{
+   struct rtw_efuse *efuse = >efuse;
+   struct rtw8822b_efuse *map;
+   int i;
+
+   map = (struct rtw8822b_efuse *)log_map;
+
+   efuse->rfe_option = map->rfe_option;
+   efuse->crystal_cap = map->xtal_k;
+   efuse->pa_type_2g = map->pa_type;
+   efuse->pa_type_5g = map->pa_type;
+   efuse->lna_type_2g = map->lna_type_2g[0];
+   efuse->lna_type_5g = map->lna_type_5g[0];
+   efuse->channel_plan = map->channel_plan;
+   efuse->country_code[0] = map->country_code[0];
+   efuse->country_code[1] = map->country_code[1];
+   efuse->bt_setting = map->rf_bt_setting;
+   efuse->regd = map->rf_board_option & 0x7;
+
+   for (i = 0; i < 4; i++)
+   efuse->txpwr_idx_table[i] = map->txpwr_idx_table[i];
+
+   switch (rtw_hci_type(rtwdev)) {
+   case RTW_HCI_TYPE_PCIE:
+   rtw8822be_efuse_parsing(efuse, map);
+   break;
+   default:
+   /* unsupported now */
+   return -ENOTSUPP;
+   }
+
+   return 0;
+}
+
+static void rtw8822b_phy_rfe_init(struct rtw_dev *rtwdev)
+{
+   /* chip top mux */
+   rtw_write32_mask(rtwdev, 0x64, BIT(29) | BIT(28), 0x3);
+   rtw_write32_mask(rtwdev, 0x4c, BIT(26) | BIT(25), 0x0);
+   rtw_write32_mask(rtwdev, 0x40, BIT(2), 0x1);
+
+   /* from s0 or s1 */
+   rtw_write32_mask(rtwdev, 0x1990, 0x3f, 0x30);
+   rtw_write32_mask(rtwdev, 0x1990, (BIT(11) | BIT(10)), 0x3);
+
+   /* input or output */
+   rtw_write32_mask(rtwdev, 0x974, 0x3f, 0x3f);
+   rtw_write32_mask(rtwdev, 0x974, (BIT(11) | BIT(10)), 0x3);
+}
+
+static void rtw8822b_phy_set_param(struct rtw_dev *rtwdev)
+{
+   struct rtw_hal *hal = >hal;
+   u8 crystal_cap;
+   bool is_tx2_path;
+
+   /* power on BB/RF domain */
+   rtw_write8_set(rtwdev, REG_SYS_FUNC_EN,
+  BIT_FEN_BB_RSTB | BIT_FEN_BB_GLB_RST);
+   rtw_write8_set(rtwdev, REG_RF_CTRL,
+  BIT_RF_EN | BIT_RF_RSTB | BIT_RF_SDM_RSTB);
+   rtw_write32_set(rtwdev, REG_WLRF1, BIT_WLRF1_BBRF_EN);
+
+   /* pre init before header files config */
+   rtw_write32_clr(rtwdev, REG_RXPSEL, BIT_RX_PSEL_RST);
+
+   rtw_phy_load_tables(rtwdev);
+
+   crystal_cap = rtwdev->efuse.crystal_cap & 0x3F;
+   rtw_write32_mask(rtwdev, 0x24, 0x7e00, crystal_cap);
+   rtw_write32_mask(rtwdev, 0x28, 0x7e, crystal_cap);
+
+   /* post init after header files config */
+   rtw_write32_set(rtwdev, REG_RXPSEL, BIT_RX_PSEL_RST);
+
+   is_tx2_path = false;
+   rtw8822b_config_trx_mode(rtwdev, hal->antenna_tx, hal->antenna_rx,
+is_tx2_path);
+   rtw_phy_init(rtwdev);
+
+   rtw8822b_phy_rfe_init(rtwdev);
+
+   /* wifi path controller */
+   rtw_write32_mask(rtwdev, 0x70, 0x400, 1);
+   /* BB control */
+   rtw_write32_mask(rtwdev, 0x4c, 0x0180, 0x2);
+   /* antenna mux switch */
+   rtw_write8(rtwdev, 0x974, 0xff);
+   rtw_write32_mask(rtwdev, 0x1990, 0x300, 0);
+   

[PATCH v2 06/13] rtw88: fw and efuse files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

fw and efuse files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/efuse.c | 150 +++
 drivers/net/wireless/realtek/rtw88/efuse.h |  53 +++
 drivers/net/wireless/realtek/rtw88/fw.c| 611 +
 drivers/net/wireless/realtek/rtw88/fw.h| 213 ++
 4 files changed, 1027 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/efuse.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/efuse.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/fw.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/fw.h

diff --git a/drivers/net/wireless/realtek/rtw88/efuse.c 
b/drivers/net/wireless/realtek/rtw88/efuse.c
new file mode 100644
index 000..7c1b782
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/efuse.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "efuse.h"
+#include "reg.h"
+#include "debug.h"
+
+#define RTW_EFUSE_BANK_WIFI0x0
+
+static void switch_efuse_bank(struct rtw_dev *rtwdev)
+{
+   rtw_write32_mask(rtwdev, REG_LDO_EFUSE_CTRL, BIT_MASK_EFUSE_BANK_SEL,
+RTW_EFUSE_BANK_WIFI);
+}
+
+static int rtw_dump_logical_efuse_map(struct rtw_dev *rtwdev, u8 *phy_map,
+ u8 *log_map)
+{
+   u32 physical_size = rtwdev->efuse.physical_size;
+   u32 protect_size = rtwdev->efuse.protect_size;
+   u32 logical_size = rtwdev->efuse.logical_size;
+   u32 phy_idx, log_idx;
+   u8 hdr1, hdr2;
+   u8 blk_idx;
+   u8 valid;
+   u8 word_en;
+   int i;
+
+   phy_idx = 0;
+
+   do {
+   hdr1 = *(phy_map + phy_idx);
+   if ((hdr1 & 0x1f) == 0xf) {
+   phy_idx++;
+   hdr2 = *(phy_map + phy_idx);
+   if (hdr2 == 0xff)
+   break;
+   blk_idx = ((hdr2 & 0xf0) >> 1) | ((hdr1 >> 5) & 0x07);
+   word_en = hdr2 & 0x0f;
+   } else {
+   blk_idx = (hdr1 & 0xf0) >> 4;
+   word_en = hdr1 & 0x0f;
+   }
+
+   if (hdr1 == 0xff)
+   break;
+
+   phy_idx++;
+   for (i = 0; i < 4; i++) {
+   valid = (~(word_en >> i)) & 0x1;
+   if (valid != 0x1)
+   continue;
+   log_idx = (blk_idx << 3) + (i << 1);
+   *(log_map + log_idx) = *(phy_map + phy_idx);
+   log_idx++;
+   phy_idx++;
+   *(log_map + log_idx) = *(phy_map + phy_idx);
+   phy_idx++;
+   if (phy_idx > physical_size - protect_size ||
+   log_idx > logical_size)
+   return -EINVAL;
+   }
+   } while (1);
+
+   return 0;
+}
+
+static int rtw_dump_physical_efuse_map(struct rtw_dev *rtwdev, u8 *map)
+{
+   struct rtw_chip_info *chip = rtwdev->chip;
+   u32 size = rtwdev->efuse.physical_size;
+   u32 efuse_ctl;
+   u32 addr;
+   u32 cnt;
+
+   switch_efuse_bank(rtwdev);
+
+   /* disable 2.5V LDO */
+   chip->ops->cfg_ldo25(rtwdev, false);
+
+   efuse_ctl = rtw_read32(rtwdev, REG_EFUSE_CTRL);
+
+   for (addr = 0; addr < size; addr++) {
+   efuse_ctl &= ~(BIT_MASK_EF_DATA | BITS_EF_ADDR);
+   efuse_ctl |= (addr & BIT_MASK_EF_ADDR) << BIT_SHIFT_EF_ADDR;
+   rtw_write32(rtwdev, REG_EFUSE_CTRL, efuse_ctl & (~BIT_EF_FLAG));
+
+   cnt = 100;
+   do {
+   udelay(1);
+   efuse_ctl = rtw_read32(rtwdev, REG_EFUSE_CTRL);
+   if (--cnt == 0)
+   return -EBUSY;
+   } while (!(efuse_ctl & BIT_EF_FLAG));
+
+   *(map + addr) = (u8)(efuse_ctl & BIT_MASK_EF_DATA);
+   }
+
+   return 0;
+}
+
+int rtw_parse_efuse_map(struct rtw_dev *rtwdev)
+{
+   struct rtw_chip_info *chip = rtwdev->chip;
+   struct rtw_efuse *efuse = >efuse;
+   u32 phy_size = efuse->physical_size;
+   u32 log_size = efuse->logical_size;
+   u8 *phy_map = NULL;
+   u8 *log_map = NULL;
+   int ret = 0;
+
+   phy_map = kmalloc(phy_size, GFP_KERNEL);
+   log_map = kmalloc(log_size, GFP_KERNEL);
+   if (!phy_map || !log_map) {
+   ret = -ENOMEM;
+   goto out_free;
+   }
+
+   ret = rtw_dump_physical_efuse_map(rtwdev, phy_map);
+   if (ret) {
+   rtw_err(rtwdev, "failed to dump efuse physical map\n");
+   goto out_free;
+   }
+
+   memset(log_map, 0xff, log_size);
+   ret = rtw_dump_logical_efuse_map(rtwdev, phy_map, 

[PATCH v2 02/13] rtw88: core files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

core files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/ps.c   | 165 +
 drivers/net/wireless/realtek/rtw88/ps.h   |  20 ++
 drivers/net/wireless/realtek/rtw88/regd.c | 391 ++
 drivers/net/wireless/realtek/rtw88/regd.h |  67 +
 drivers/net/wireless/realtek/rtw88/sec.c  | 120 +
 drivers/net/wireless/realtek/rtw88/sec.h  |  39 +++
 6 files changed, 802 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/ps.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/ps.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/regd.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/regd.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/sec.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/sec.h

diff --git a/drivers/net/wireless/realtek/rtw88/ps.c 
b/drivers/net/wireless/realtek/rtw88/ps.c
new file mode 100644
index 000..db51910
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/ps.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "fw.h"
+#include "ps.h"
+#include "mac.h"
+#include "debug.h"
+
+static int rtw_ips_pwr_up(struct rtw_dev *rtwdev)
+{
+   int ret;
+
+   ret = rtw_core_start(rtwdev);
+   if (ret)
+   rtw_err(rtwdev, "leave idle state failed\n");
+
+   rtw_flag_clear(rtwdev, RTW_FLAG_INACTIVE_PS);
+
+   return ret;
+}
+
+int rtw_enter_ips(struct rtw_dev *rtwdev)
+{
+   rtw_flag_set(rtwdev, RTW_FLAG_INACTIVE_PS);
+
+   rtw_core_stop(rtwdev);
+
+   return 0;
+}
+
+static void rtw_restore_port_cfg_iter(void *data, u8 *mac,
+ struct ieee80211_vif *vif)
+{
+   struct rtw_dev *rtwdev = data;
+   struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv;
+   u32 config = ~0;
+
+   rtw_vif_port_config(rtwdev, rtwvif, config);
+}
+
+int rtw_leave_ips(struct rtw_dev *rtwdev)
+{
+   int ret;
+
+   ret = rtw_ips_pwr_up(rtwdev);
+   if (ret) {
+   rtw_err(rtwdev, "failed to leave ips state\n");
+   return ret;
+   }
+
+   rtw_iterate_vifs_atomic(rtwdev, rtw_restore_port_cfg_iter, rtwdev);
+
+   return 0;
+}
+
+static void rtw_leave_lps_core(struct rtw_dev *rtwdev)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   conf->state = RTW_ALL_ON;
+   conf->awake_interval = 1;
+   conf->rlbm = 0;
+   conf->smart_ps = 0;
+
+   rtw_fw_set_pwr_mode(rtwdev);
+   rtw_flag_clear(rtwdev, RTW_FLAG_LEISURE_PS);
+}
+
+static void rtw_enter_lps_core(struct rtw_dev *rtwdev)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   conf->state = RTW_RF_OFF;
+   conf->awake_interval = 1;
+   conf->rlbm = 1;
+   conf->smart_ps = 2;
+
+   rtw_fw_set_pwr_mode(rtwdev);
+   rtw_flag_set(rtwdev, RTW_FLAG_LEISURE_PS);
+}
+
+void rtw_lps_work(struct work_struct *work)
+{
+   struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
+ lps_work.work);
+   struct rtw_lps_conf *conf = >lps_conf;
+   struct rtw_vif *rtwvif = conf->rtwvif;
+
+   if (WARN_ON(!rtwvif))
+   return;
+
+   if (conf->mode == RTW_MODE_LPS)
+   rtw_enter_lps_core(rtwdev);
+   else
+   rtw_leave_lps_core(rtwdev);
+}
+
+void rtw_enter_lps_irqsafe(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   if (rtwvif->in_lps)
+   return;
+
+   conf->mode = RTW_MODE_LPS;
+   conf->rtwvif = rtwvif;
+   rtwvif->in_lps = true;
+
+   ieee80211_queue_delayed_work(rtwdev->hw, >lps_work, 0);
+}
+
+void rtw_leave_lps_irqsafe(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   if (!rtwvif->in_lps)
+   return;
+
+   conf->mode = RTW_MODE_ACTIVE;
+   conf->rtwvif = rtwvif;
+   rtwvif->in_lps = false;
+
+   ieee80211_queue_delayed_work(rtwdev->hw, >lps_work, 0);
+}
+
+bool rtw_in_lps(struct rtw_dev *rtwdev)
+{
+   return rtw_flag_check(rtwdev, RTW_FLAG_LEISURE_PS);
+}
+
+void rtw_enter_lps(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   if (WARN_ON(!rtwvif))
+   return;
+
+   if (rtwvif->in_lps)
+   return;
+
+   conf->mode = RTW_MODE_LPS;
+   conf->rtwvif = rtwvif;
+   rtwvif->in_lps = true;
+
+   rtw_enter_lps_core(rtwdev);
+}
+
+void rtw_leave_lps(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
+{
+   struct rtw_lps_conf *conf = >lps_conf;
+
+   if (WARN_ON(!rtwvif))
+   return;
+
+   if (!rtwvif->in_lps)
+   return;
+
+   conf->mode = RTW_MODE_ACTIVE;
+   conf->rtwvif = rtwvif;
+   rtwvif->in_lps = false;
+

[PATCH v2 13/13] rtw88: add support for Realtek 802.11ac wireless chips

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

Signed-off-by: Yan-Hsuan Chuang 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9ad052a..138515b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12546,6 +12546,14 @@ T: git 
git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.g
 S: Maintained
 F: drivers/net/wireless/realtek/rtlwifi/
 
+REALTEK WIRELESS DRIVER (rtw88)
+M: Yan-Hsuan Chuang 
+L: linux-wireless@vger.kernel.org
+W: http://wireless.kernel.org/
+T: git 
git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
+S: Maintained
+F: drivers/net/wireless/realtek/rtw88/
+
 RTL8XXXU WIRELESS DRIVER (rtl8xxxu)
 M: Jes Sorensen 
 L: linux-wireless@vger.kernel.org
-- 
2.7.4



[PATCH v2 08/13] rtw88: debug files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

debug files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/debug.c | 631 +
 drivers/net/wireless/realtek/rtw88/debug.h |  35 ++
 2 files changed, 666 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/debug.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/debug.h

diff --git a/drivers/net/wireless/realtek/rtw88/debug.c 
b/drivers/net/wireless/realtek/rtw88/debug.c
new file mode 100644
index 000..d0cb9d3
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/debug.c
@@ -0,0 +1,631 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include 
+#include 
+#include "main.h"
+#include "sec.h"
+#include "fw.h"
+#include "debug.h"
+
+#ifdef CONFIG_RTW88_DEBUGFS
+
+struct rtw_debugfs_priv {
+   struct rtw_dev *rtwdev;
+   int (*cb_read)(struct seq_file *m, void *v);
+   ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
+   size_t count, loff_t *loff);
+   union {
+   u32 cb_data;
+   u8 *buf;
+   struct {
+   u32 page_offset;
+   u32 page_num;
+   } rsvd_page;
+   struct {
+   u8 rf_path;
+   u32 rf_addr;
+   u32 rf_mask;
+   };
+   struct {
+   u32 addr;
+   u32 len;
+   } read_reg;
+   };
+};
+
+static int rtw_debugfs_single_show(struct seq_file *m, void *v)
+{
+   struct rtw_debugfs_priv *debugfs_priv = m->private;
+
+   return debugfs_priv->cb_read(m, v);
+}
+
+static ssize_t rtw_debugfs_common_write(struct file *filp,
+   const char __user *buffer,
+   size_t count, loff_t *loff)
+{
+   struct rtw_debugfs_priv *debugfs_priv = filp->private_data;
+
+   return debugfs_priv->cb_write(filp, buffer, count, loff);
+}
+
+static ssize_t rtw_debugfs_single_write(struct file *filp,
+   const char __user *buffer,
+   size_t count, loff_t *loff)
+{
+   struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
+   struct rtw_debugfs_priv *debugfs_priv = seqpriv->private;
+
+   return debugfs_priv->cb_write(filp, buffer, count, loff);
+}
+
+static int rtw_debugfs_single_open_rw(struct inode *inode, struct file *filp)
+{
+   return single_open(filp, rtw_debugfs_single_show, inode->i_private);
+}
+
+static int rtw_debugfs_close(struct inode *inode, struct file *filp)
+{
+   return 0;
+}
+
+static const struct file_operations file_ops_single_r = {
+   .owner = THIS_MODULE,
+   .open = rtw_debugfs_single_open_rw,
+   .read = seq_read,
+   .llseek = seq_lseek,
+   .release = seq_release,
+};
+
+static const struct file_operations file_ops_single_rw = {
+   .owner = THIS_MODULE,
+   .open = rtw_debugfs_single_open_rw,
+   .release = single_release,
+   .read = seq_read,
+   .llseek = seq_lseek,
+   .write = rtw_debugfs_single_write,
+};
+
+static const struct file_operations file_ops_common_write = {
+   .owner = THIS_MODULE,
+   .write = rtw_debugfs_common_write,
+   .open = simple_open,
+   .release = rtw_debugfs_close,
+};
+
+static int rtw_debugfs_get_read_reg(struct seq_file *m, void *v)
+{
+   struct rtw_debugfs_priv *debugfs_priv = m->private;
+   struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
+   u32 val, len, addr;
+
+   len = debugfs_priv->read_reg.len;
+   addr = debugfs_priv->read_reg.addr;
+   switch (len) {
+   case 1:
+   val = rtw_read8(rtwdev, addr);
+   seq_printf(m, "reg 0x%03x: 0x%02x\n", addr, val);
+   break;
+   case 2:
+   val = rtw_read16(rtwdev, addr);
+   seq_printf(m, "reg 0x%03x: 0x%04x\n", addr, val);
+   break;
+   case 4:
+   val = rtw_read32(rtwdev, addr);
+   seq_printf(m, "reg 0x%03x: 0x%08x\n", addr, val);
+   break;
+   }
+   return 0;
+}
+
+static int rtw_debugfs_get_rf_read(struct seq_file *m, void *v)
+{
+   struct rtw_debugfs_priv *debugfs_priv = m->private;
+   struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
+   u32 val, addr, mask;
+   u8 path;
+
+   path = debugfs_priv->rf_path;
+   addr = debugfs_priv->rf_addr;
+   mask = debugfs_priv->rf_mask;
+
+   val = rtw_read_rf(rtwdev, path, addr, mask);
+
+   seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n",
+  path, addr, mask, val);
+
+   return 0;
+}
+
+static int rtw_debugfs_copy_from_user(char tmp[], int size,
+ const char __user *buffer, size_t count,
+   

[PATCH v2 03/13] rtw88: hci files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

hci files for Realtek 802.11ac wireless network chips

For now there is only PCI bus supported by rtwlan, in the future it
will also have USB/SDIO

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/hci.h |  211 ++
 drivers/net/wireless/realtek/rtw88/pci.c | 1208 ++
 drivers/net/wireless/realtek/rtw88/pci.h |  229 ++
 3 files changed, 1648 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/hci.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/pci.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/pci.h

diff --git a/drivers/net/wireless/realtek/rtw88/hci.h 
b/drivers/net/wireless/realtek/rtw88/hci.h
new file mode 100644
index 000..91b15ef
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/hci.h
@@ -0,0 +1,211 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#ifndef__RTW_HCI_H__
+#define __RTW_HCI_H__
+
+/* ops for PCI, USB and SDIO */
+struct rtw_hci_ops {
+   int (*tx)(struct rtw_dev *rtwdev,
+ struct rtw_tx_pkt_info *pkt_info,
+ struct sk_buff *skb);
+   int (*setup)(struct rtw_dev *rtwdev);
+   int (*start)(struct rtw_dev *rtwdev);
+   void (*stop)(struct rtw_dev *rtwdev);
+
+   int (*write_data_rsvd_page)(struct rtw_dev *rtwdev, u8 *buf, u32 size);
+   int (*write_data_h2c)(struct rtw_dev *rtwdev, u8 *buf, u32 size);
+
+   u8 (*read8)(struct rtw_dev *rtwdev, u32 addr);
+   u16 (*read16)(struct rtw_dev *rtwdev, u32 addr);
+   u32 (*read32)(struct rtw_dev *rtwdev, u32 addr);
+   void (*write8)(struct rtw_dev *rtwdev, u32 addr, u8 val);
+   void (*write16)(struct rtw_dev *rtwdev, u32 addr, u16 val);
+   void (*write32)(struct rtw_dev *rtwdev, u32 addr, u32 val);
+};
+
+static inline int rtw_hci_tx(struct rtw_dev *rtwdev,
+struct rtw_tx_pkt_info *pkt_info,
+struct sk_buff *skb)
+{
+   return rtwdev->hci.ops->tx(rtwdev, pkt_info, skb);
+}
+
+static inline int rtw_hci_setup(struct rtw_dev *rtwdev)
+{
+   return rtwdev->hci.ops->setup(rtwdev);
+}
+
+static inline int rtw_hci_start(struct rtw_dev *rtwdev)
+{
+   return rtwdev->hci.ops->start(rtwdev);
+}
+
+static inline void rtw_hci_stop(struct rtw_dev *rtwdev)
+{
+   rtwdev->hci.ops->stop(rtwdev);
+}
+
+static inline int
+rtw_hci_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf, u32 size)
+{
+   return rtwdev->hci.ops->write_data_rsvd_page(rtwdev, buf, size);
+}
+
+static inline int
+rtw_hci_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
+{
+   return rtwdev->hci.ops->write_data_h2c(rtwdev, buf, size);
+}
+
+static inline u8 rtw_read8(struct rtw_dev *rtwdev, u32 addr)
+{
+   return rtwdev->hci.ops->read8(rtwdev, addr);
+}
+
+static inline u16 rtw_read16(struct rtw_dev *rtwdev, u32 addr)
+{
+   return rtwdev->hci.ops->read16(rtwdev, addr);
+}
+
+static inline u32 rtw_read32(struct rtw_dev *rtwdev, u32 addr)
+{
+   return rtwdev->hci.ops->read32(rtwdev, addr);
+}
+
+static inline void rtw_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
+{
+   rtwdev->hci.ops->write8(rtwdev, addr, val);
+}
+
+static inline void rtw_write16(struct rtw_dev *rtwdev, u32 addr, u16 val)
+{
+   rtwdev->hci.ops->write16(rtwdev, addr, val);
+}
+
+static inline void rtw_write32(struct rtw_dev *rtwdev, u32 addr, u32 val)
+{
+   rtwdev->hci.ops->write32(rtwdev, addr, val);
+}
+
+static inline void rtw_write8_set(struct rtw_dev *rtwdev, u32 addr, u8 bit)
+{
+   u8 val;
+
+   val = rtw_read8(rtwdev, addr);
+   rtw_write8(rtwdev, addr, val | bit);
+}
+
+static inline void rtw_writ16_set(struct rtw_dev *rtwdev, u32 addr, u16 bit)
+{
+   u16 val;
+
+   val = rtw_read16(rtwdev, addr);
+   rtw_write16(rtwdev, addr, val | bit);
+}
+
+static inline void rtw_write32_set(struct rtw_dev *rtwdev, u32 addr, u32 bit)
+{
+   u32 val;
+
+   val = rtw_read32(rtwdev, addr);
+   rtw_write32(rtwdev, addr, val | bit);
+}
+
+static inline void rtw_write8_clr(struct rtw_dev *rtwdev, u32 addr, u8 bit)
+{
+   u8 val;
+
+   val = rtw_read8(rtwdev, addr);
+   rtw_write8(rtwdev, addr, val & ~bit);
+}
+
+static inline void rtw_write16_clr(struct rtw_dev *rtwdev, u32 addr, u16 bit)
+{
+   u16 val;
+
+   val = rtw_read16(rtwdev, addr);
+   rtw_write16(rtwdev, addr, val & ~bit);
+}
+
+static inline void rtw_write32_clr(struct rtw_dev *rtwdev, u32 addr, u32 bit)
+{
+   u32 val;
+
+   val = rtw_read32(rtwdev, addr);
+   rtw_write32(rtwdev, addr, val & ~bit);
+}
+
+static inline u32
+rtw_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
+   u32 addr, u32 mask)
+{
+   unsigned long flags;
+   u32 val;
+
+   spin_lock_irqsave(>rf_lock, flags);
+   val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
+   spin_unlock_irqrestore(>rf_lock, 

[PATCH v2 01/13] rtw88: main files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

main files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/mac80211.c |  480 ++
 drivers/net/wireless/realtek/rtw88/main.c | 1190 +
 drivers/net/wireless/realtek/rtw88/main.h | 1119 +++
 drivers/net/wireless/realtek/rtw88/reg.h  |  411 +
 4 files changed, 3200 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/mac80211.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/main.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/main.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/reg.h

diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c 
b/drivers/net/wireless/realtek/rtw88/mac80211.c
new file mode 100644
index 000..17b3651
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/mac80211.c
@@ -0,0 +1,480 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "sec.h"
+#include "tx.h"
+#include "fw.h"
+#include "mac.h"
+#include "ps.h"
+#include "reg.h"
+#include "debug.h"
+
+static void rtw_ops_tx(struct ieee80211_hw *hw,
+  struct ieee80211_tx_control *control,
+  struct sk_buff *skb)
+{
+   struct rtw_dev *rtwdev = hw->priv;
+   struct rtw_tx_pkt_info pkt_info = {0};
+
+   if (!rtw_flag_check(rtwdev, RTW_FLAG_RUNNING))
+   goto out;
+
+   rtw_tx_pkt_info_update(rtwdev, _info, control, skb);
+   if (rtw_hci_tx(rtwdev, _info, skb))
+   goto out;
+
+   return;
+
+out:
+   ieee80211_free_txskb(hw, skb);
+}
+
+static int rtw_ops_start(struct ieee80211_hw *hw)
+{
+   struct rtw_dev *rtwdev = hw->priv;
+   int ret;
+
+   mutex_lock(>mutex);
+   ret = rtw_core_start(rtwdev);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+
+static void rtw_ops_stop(struct ieee80211_hw *hw)
+{
+   struct rtw_dev *rtwdev = hw->priv;
+
+   mutex_lock(>mutex);
+   rtw_core_stop(rtwdev);
+   mutex_unlock(>mutex);
+}
+
+static int rtw_ops_config(struct ieee80211_hw *hw, u32 changed)
+{
+   struct rtw_dev *rtwdev = hw->priv;
+   int ret = 0;
+
+   mutex_lock(>mutex);
+
+   if (changed & IEEE80211_CONF_CHANGE_IDLE) {
+   if (hw->conf.flags & IEEE80211_CONF_IDLE) {
+   rtw_enter_ips(rtwdev);
+   } else {
+   ret = rtw_leave_ips(rtwdev);
+   if (ret) {
+   rtw_err(rtwdev, "failed to leave idle state\n");
+   goto out;
+   }
+   }
+   }
+
+   if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
+   rtw_set_channel(rtwdev);
+
+out:
+   mutex_unlock(>mutex);
+   return ret;
+}
+
+static const struct rtw_vif_port rtw_vif_port[] = {
+   [0] = {
+   .mac_addr   = {.addr = 0x0610},
+   .bssid  = {.addr = 0x0618},
+   .net_type   = {.addr = 0x0100, .mask = 0x3},
+   .aid= {.addr = 0x06a8, .mask = 0x7ff},
+   },
+   [1] = {
+   .mac_addr   = {.addr = 0x0700},
+   .bssid  = {.addr = 0x0708},
+   .net_type   = {.addr = 0x0100, .mask = 0xc},
+   .aid= {.addr = 0x0710, .mask = 0x7ff},
+   },
+   [2] = {
+   .mac_addr   = {.addr = 0x1620},
+   .bssid  = {.addr = 0x1628},
+   .net_type   = {.addr = 0x1100, .mask = 0x3},
+   .aid= {.addr = 0x1600, .mask = 0x7ff},
+   },
+   [3] = {
+   .mac_addr   = {.addr = 0x1630},
+   .bssid  = {.addr = 0x1638},
+   .net_type   = {.addr = 0x1100, .mask = 0xc},
+   .aid= {.addr = 0x1604, .mask = 0x7ff},
+   },
+   [4] = {
+   .mac_addr   = {.addr = 0x1640},
+   .bssid  = {.addr = 0x1648},
+   .net_type   = {.addr = 0x1100, .mask = 0x30},
+   .aid= {.addr = 0x1608, .mask = 0x7ff},
+   },
+};
+
+static int rtw_ops_add_interface(struct ieee80211_hw *hw,
+struct ieee80211_vif *vif)
+{
+   struct rtw_dev *rtwdev = hw->priv;
+   struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv;
+   enum rtw_net_type net_type;
+   u32 config = 0;
+   u8 port = 0;
+
+   vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
+   rtwvif->port = port;
+   rtwvif->vif = vif;
+   rtwvif->stats.tx_unicast = 0;
+   rtwvif->stats.rx_unicast = 0;
+   rtwvif->stats.tx_cnt = 0;
+   rtwvif->stats.rx_cnt = 0;
+   rtwvif->in_lps = false;
+   rtwvif->conf = _vif_port[port];
+
+   mutex_lock(>mutex);
+
+   switch (vif->type) {
+   

[PATCH v2 12/13] rtw88: Kconfig & Makefile

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

Kconfig & Makefile for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/Kconfig|  1 +
 drivers/net/wireless/realtek/Makefile   |  1 +
 drivers/net/wireless/realtek/rtw88/Kconfig  | 55 +
 drivers/net/wireless/realtek/rtw88/Makefile | 19 ++
 4 files changed, 76 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/Kconfig
 create mode 100644 drivers/net/wireless/realtek/rtw88/Makefile

diff --git a/drivers/net/wireless/realtek/Kconfig 
b/drivers/net/wireless/realtek/Kconfig
index 3db988e..9189fd6 100644
--- a/drivers/net/wireless/realtek/Kconfig
+++ b/drivers/net/wireless/realtek/Kconfig
@@ -14,5 +14,6 @@ if WLAN_VENDOR_REALTEK
 source "drivers/net/wireless/realtek/rtl818x/Kconfig"
 source "drivers/net/wireless/realtek/rtlwifi/Kconfig"
 source "drivers/net/wireless/realtek/rtl8xxxu/Kconfig"
+source "drivers/net/wireless/realtek/rtw88/Kconfig"
 
 endif # WLAN_VENDOR_REALTEK
diff --git a/drivers/net/wireless/realtek/Makefile 
b/drivers/net/wireless/realtek/Makefile
index 9c78deb..118af99 100644
--- a/drivers/net/wireless/realtek/Makefile
+++ b/drivers/net/wireless/realtek/Makefile
@@ -6,4 +6,5 @@ obj-$(CONFIG_RTL8180)   += rtl818x/
 obj-$(CONFIG_RTL8187)  += rtl818x/
 obj-$(CONFIG_RTLWIFI)  += rtlwifi/
 obj-$(CONFIG_RTL8XXXU) += rtl8xxxu/
+obj-$(CONFIG_RTW88)+= rtw88/
 
diff --git a/drivers/net/wireless/realtek/rtw88/Kconfig 
b/drivers/net/wireless/realtek/rtw88/Kconfig
new file mode 100644
index 000..bd68c7c
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/Kconfig
@@ -0,0 +1,55 @@
+menuconfig RTW88
+   tristate "Realtek 802.11ac wireless chips support"
+   depends on MAC80211
+   default y
+   help
+ This module adds support for mac80211-based wireless drivers that
+ enables Realtek IEEE 802.11ac wireless chipsets.
+
+ If you choose to build a module, it'll be called rtw88.
+
+if RTW88
+
+config RTW88_CORE
+   tristate
+
+config RTW88_PCI
+   tristate
+
+config RTW88_8822BE
+   bool "Realtek 8822BE PCI wireless network adapter"
+   depends on PCI
+   select RTW88_CORE
+   select RTW88_PCI
+   help
+ Select this option will enable support for 8822BE chipset
+
+ 802.11ac PCIe wireless network adapter
+
+config RTW88_8822CE
+   bool "Realtek 8822CE PCI wireless network adapter"
+   depends on PCI
+   select RTW88_CORE
+   select RTW88_PCI
+   help
+ Select this option will enable support for 8822CE chipset
+
+ 802.11ac PCIe wireless network adapter
+
+config RTW88_DEBUG
+   bool "Realtek rtw88 debug support"
+   depends on RTW88_CORE
+   help
+ Enable debug support
+
+ If unsure, say Y to simplify debug problems
+
+config RTW88_DEBUGFS
+   bool "Realtek rtw88 debugfs support"
+   depends on RTW88_CORE
+   help
+ Enable debug support
+
+ If unsure, say Y to simplify debug problems
+
+endif
diff --git a/drivers/net/wireless/realtek/rtw88/Makefile 
b/drivers/net/wireless/realtek/rtw88/Makefile
new file mode 100644
index 000..d70782a
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/Makefile
@@ -0,0 +1,19 @@
+obj-$(CONFIG_RTW88_CORE)   += rtw88.o
+rtw88-y += main.o \
+  mac80211.o \
+  debug.o \
+  tx.o \
+  rx.o \
+  mac.o \
+  phy.o \
+  efuse.o \
+  fw.o \
+  ps.o \
+  sec.o \
+  regd.o
+
+rtw88-$(CONFIG_RTW88_8822BE)   += rtw8822b.o rtw8822b_table.o
+rtw88-$(CONFIG_RTW88_8822CE)   += rtw8822c.o rtw8822c_table.o
+
+obj-$(CONFIG_RTW88_PCI)+= rtwpci.o
+rtwpci-objs:= pci.o
-- 
2.7.4



[PATCH v2 11/13] rtw88: 8822C init table

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

8822C init table for chip files Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 .../net/wireless/realtek/rtw88/rtw8822c_table.c| 4150 
 1 file changed, 4150 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/rtw8822c_table.c

diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c_table.c 
b/drivers/net/wireless/realtek/rtw88/rtw8822c_table.c
new file mode 100644
index 000..e95ad82
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c_table.c
@@ -0,0 +1,4150 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "phy.h"
+#include "rtw8822c_table.h"
+
+static const u32 rtw8822c_mac[] = {
+};
+
+RTW_DECL_TABLE_PHY_COND(rtw8822c_mac, rtw_phy_cfg_mac);
+
+static const u32 rtw8822c_agc[] = {
+   0x1D90, 0x31FF,
+   0x1D90, 0x300101FF,
+   0x1D90, 0x300201FF,
+   0x1D90, 0x300301FF,
+   0x1D90, 0x300401FF,
+   0x1D90, 0x300501FF,
+   0x1D90, 0x300601FE,
+   0x1D90, 0x300701FD,
+   0x1D90, 0x300801FC,
+   0x1D90, 0x300901FB,
+   0x1D90, 0x300A01FA,
+   0x1D90, 0x300B01F9,
+   0x1D90, 0x300C01F8,
+   0x1D90, 0x300D01F7,
+   0x1D90, 0x300E01F6,
+   0x1D90, 0x300F01F5,
+   0x1D90, 0x301001F4,
+   0x1D90, 0x301101F3,
+   0x1D90, 0x301201F2,
+   0x1D90, 0x301301F1,
+   0x1D90, 0x301401F0,
+   0x1D90, 0x301501EF,
+   0x1D90, 0x301601AF,
+   0x1D90, 0x301701AE,
+   0x1D90, 0x301801AD,
+   0x1D90, 0x301901AC,
+   0x1D90, 0x301A01AB,
+   0x1D90, 0x301B01AA,
+   0x1D90, 0x301C01A9,
+   0x1D90, 0x301D0188,
+   0x1D90, 0x301E0187,
+   0x1D90, 0x301F0186,
+   0x1D90, 0x30200185,
+   0x1D90, 0x30210168,
+   0x1D90, 0x30220167,
+   0x1D90, 0x30230166,
+   0x1D90, 0x30240108,
+   0x1D90, 0x30250107,
+   0x1D90, 0x30260106,
+   0x1D90, 0x30270144,
+   0x1D90, 0x30280143,
+   0x1D90, 0x30290142,
+   0x1D90, 0x302A0141,
+   0x1D90, 0x302B0140,
+   0x1D90, 0x302C00C9,
+   0x1D90, 0x302D00C8,
+   0x1D90, 0x302E00C7,
+   0x1D90, 0x302F00C6,
+   0x1D90, 0x303000C5,
+   0x1D90, 0x303100C4,
+   0x1D90, 0x303200C3,
+   0x1D90, 0x30330088,
+   0x1D90, 0x30340087,
+   0x1D90, 0x30350086,
+   0x1D90, 0x30360045,
+   0x1D90, 0x30370044,
+   0x1D90, 0x30380043,
+   0x1D90, 0x30390023,
+   0x1D90, 0x303A0022,
+   0x1D90, 0x303B0021,
+   0x1D90, 0x303C0020,
+   0x1D90, 0x303D0002,
+   0x1D90, 0x303E0001,
+   0x1D90, 0x303F,
+   0x1D90, 0x304000FF,
+   0x1D90, 0x304100FF,
+   0x1D90, 0x304200FF,
+   0x1D90, 0x304300FF,
+   0x1D90, 0x304400FF,
+   0x1D90, 0x304500FE,
+   0x1D90, 0x304600FD,
+   0x1D90, 0x304700FC,
+   0x1D90, 0x304800FB,
+   0x1D90, 0x304900FA,
+   0x1D90, 0x304A00F9,
+   0x1D90, 0x304B00F8,
+   0x1D90, 0x304C00F7,
+   0x1D90, 0x304D00F6,
+   0x1D90, 0x304E00F5,
+   0x1D90, 0x304F00F4,
+   0x1D90, 0x305000F3,
+   0x1D90, 0x305100F2,
+   0x1D90, 0x305200F1,
+   0x1D90, 0x305300F0,
+   0x1D90, 0x305400EF,
+   0x1D90, 0x305500EE,
+   0x1D90, 0x305600ED,
+   0x1D90, 0x305700EC,
+   0x1D90, 0x305800EB,
+   0x1D90, 0x305900EA,
+   0x1D90, 0x305A00E9,
+   0x1D90, 0x305B00E8,
+   0x1D90, 0x305C00E7,
+   0x1D90, 0x305D00E6,
+   0x1D90, 0x305E00E5,
+   0x1D90, 0x305F00E4,
+   0x1D90, 0x306000E3,
+   0x1D90, 0x306100C3,
+   0x1D90, 0x306200C2,
+   0x1D90, 0x306300C1,
+   0x1D90, 0x30640088,
+   0x1D90, 0x30650087,
+   0x1D90, 0x30660086,
+   0x1D90, 0x30670085,
+   0x1D90, 0x30680084,
+   0x1D90, 0x30690083,
+   0x1D90, 0x306A0082,
+   0x1D90, 0x306B0081,
+   0x1D90, 0x306C0068,
+   0x1D90, 0x306D0067,
+   0x1D90, 0x306E0066,
+   0x1D90, 0x306F0065,
+   0x1D90, 0x30700064,
+   0x1D90, 0x30710063,
+   

[PATCH v2 00/13] rtw88: mac80211 driver for Realtek 802.11ac wireless network chips

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

This is a new mac80211 driver for Realtek 802.11ac wireless network chips.
rtw88 supports 8822BE and 8822CE chips, and will be able to support
multi-vif combinations in run-time.

For now, only PCI bus is supported, but rtw88 was originally designed
to optionally support three buses includes USB & SDIO. USB & SDIO modules
will soon be supported by rtw88, with configurable core module to fit
with different bus modules in the same time.

For example, if we choose 8822BE and 8822CU, only PCI & USB modules will
be selected, built, loaded into kernel. This is one of the major
difference from rtlwifi, which can only support specific combinations.

Another difference from rtlwifi is that rtw88 is designed to support
the latest Realtek 802.11ac wireless network chips like 8822B and
8822C series. Compared to the earlier chips supported by rtlwifi like
the 802.11n 8192EE chipset or 802.11ac 8821AE/8812AE chips, newer ICs
have different MAC & PHY settings, such as new multi-port feature for the
MAC layer design and Jaguar2/Jaguar3 PHY layer IPs.

Multi-Port feature is also supported under rtw88's software architecture.
rtlwifi can only support one vif in the same time, most because of the
hardware limitations for early chips, hence the original design of it
also restricts the usage of multi-vif support, so latest chipset seems not
take advantages from its new MAC engine.

However, rtw88 can run multiple vifs concurrently by holding them on
hardware ports provided by MAC engine, hence can easily start different
roles on a single device.

Based on the reasons mentioned before, we implemented rtw88. It had many
authors, they are listed here alphabetically:

Ping-Ke Shih 
Tzu-En Huang 
Yan-Hsuan Chuang 


v2

 - add comment for watch dog


Yan-Hsuan Chuang (13):
  rtw88: main files
  rtw88: core files
  rtw88: hci files
  rtw88: trx files
  rtw88: mac files
  rtw88: fw and efuse files
  rtw88: phy files
  rtw88: debug files
  rtw88: chip files
  rtw88: 8822B init table
  rtw88: 8822C init table
  rtw88: Kconfig & Makefile
  rtw88: add support for Realtek 802.11ac wireless chips

 MAINTAINERS| 8 +
 drivers/net/wireless/realtek/Kconfig   | 1 +
 drivers/net/wireless/realtek/Makefile  | 1 +
 drivers/net/wireless/realtek/rtw88/Kconfig |55 +
 drivers/net/wireless/realtek/rtw88/Makefile|19 +
 drivers/net/wireless/realtek/rtw88/debug.c |   631 +
 drivers/net/wireless/realtek/rtw88/debug.h |35 +
 drivers/net/wireless/realtek/rtw88/efuse.c |   150 +
 drivers/net/wireless/realtek/rtw88/efuse.h |53 +
 drivers/net/wireless/realtek/rtw88/fw.c|   611 +
 drivers/net/wireless/realtek/rtw88/fw.h|   213 +
 drivers/net/wireless/realtek/rtw88/hci.h   |   211 +
 drivers/net/wireless/realtek/rtw88/mac.c   |  1010 +
 drivers/net/wireless/realtek/rtw88/mac.h   |35 +
 drivers/net/wireless/realtek/rtw88/mac80211.c  |   480 +
 drivers/net/wireless/realtek/rtw88/main.c  |  1190 ++
 drivers/net/wireless/realtek/rtw88/main.h  |  1119 +
 drivers/net/wireless/realtek/rtw88/pci.c   |  1208 ++
 drivers/net/wireless/realtek/rtw88/pci.h   |   229 +
 drivers/net/wireless/realtek/rtw88/phy.c   |  1670 ++
 drivers/net/wireless/realtek/rtw88/phy.h   |   125 +
 drivers/net/wireless/realtek/rtw88/ps.c|   165 +
 drivers/net/wireless/realtek/rtw88/ps.h|20 +
 drivers/net/wireless/realtek/rtw88/reg.h   |   411 +
 drivers/net/wireless/realtek/rtw88/regd.c  |   391 +
 drivers/net/wireless/realtek/rtw88/regd.h  |67 +
 drivers/net/wireless/realtek/rtw88/rtw8822b.c  |  1590 ++
 drivers/net/wireless/realtek/rtw88/rtw8822b.h  |   155 +
 .../net/wireless/realtek/rtw88/rtw8822b_table.c| 20783 +++
 .../net/wireless/realtek/rtw88/rtw8822b_table.h|18 +
 drivers/net/wireless/realtek/rtw88/rtw8822c.c  |  1169 ++
 drivers/net/wireless/realtek/rtw88/rtw8822c.h  |   171 +
 .../net/wireless/realtek/rtw88/rtw8822c_table.c|  4150 
 .../net/wireless/realtek/rtw88/rtw8822c_table.h|16 +
 drivers/net/wireless/realtek/rtw88/rx.c|   151 +
 drivers/net/wireless/realtek/rtw88/rx.h|41 +
 drivers/net/wireless/realtek/rtw88/sec.c   |   120 +
 drivers/net/wireless/realtek/rtw88/sec.h   |39 +
 drivers/net/wireless/realtek/rtw88/tx.c|   273 +
 drivers/net/wireless/realtek/rtw88/tx.h|81 +
 40 files changed, 38865 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/Kconfig
 create mode 100644 drivers/net/wireless/realtek/rtw88/Makefile
 create mode 100644 drivers/net/wireless/realtek/rtw88/debug.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/debug.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/efuse.c
 create 

[PATCH v2 04/13] rtw88: trx files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

trx files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/rx.c | 151 ++
 drivers/net/wireless/realtek/rtw88/rx.h |  41 +
 drivers/net/wireless/realtek/rtw88/tx.c | 273 
 drivers/net/wireless/realtek/rtw88/tx.h |  81 ++
 4 files changed, 546 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/rx.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/rx.h
 create mode 100644 drivers/net/wireless/realtek/rtw88/tx.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/tx.h

diff --git a/drivers/net/wireless/realtek/rtw88/rx.c 
b/drivers/net/wireless/realtek/rtw88/rx.c
new file mode 100644
index 000..276856e
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/rx.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "rx.h"
+#include "ps.h"
+
+void rtw_rx_stats(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
+ struct sk_buff *skb)
+{
+   struct ieee80211_hdr *hdr;
+   struct rtw_vif *rtwvif;
+
+   hdr = (struct ieee80211_hdr *)skb->data;
+
+   if (!ieee80211_is_data(hdr->frame_control))
+   return;
+
+   if (!is_broadcast_ether_addr(hdr->addr1) &&
+   !is_multicast_ether_addr(hdr->addr1)) {
+   rtwdev->stats.rx_unicast += skb->len;
+   rtwdev->stats.rx_cnt++;
+   if (vif) {
+   rtwvif = (struct rtw_vif *)vif->drv_priv;
+   rtwvif->stats.rx_unicast += skb->len;
+   rtwvif->stats.rx_cnt++;
+   if (rtwvif->stats.rx_cnt > RTW_LPS_THRESHOLD)
+   rtw_leave_lps_irqsafe(rtwdev, rtwvif);
+   }
+   }
+}
+EXPORT_SYMBOL(rtw_rx_stats);
+
+struct rtw_rx_addr_match_data {
+   struct rtw_dev *rtwdev;
+   struct ieee80211_hdr *hdr;
+   struct rtw_rx_pkt_stat *pkt_stat;
+   u8 *bssid;
+};
+
+static void rtw_rx_addr_match_iter(void *data, u8 *mac,
+  struct ieee80211_vif *vif)
+{
+   struct rtw_rx_addr_match_data *iter_data = data;
+   struct ieee80211_sta *sta;
+   struct ieee80211_hdr *hdr = iter_data->hdr;
+   struct rtw_dev *rtwdev = iter_data->rtwdev;
+   struct rtw_sta_info *si;
+   struct rtw_rx_pkt_stat *pkt_stat = iter_data->pkt_stat;
+   u8 *bssid = iter_data->bssid;
+
+   if (ether_addr_equal(vif->bss_conf.bssid, bssid) &&
+   (ether_addr_equal(vif->addr, hdr->addr1) ||
+ieee80211_is_beacon(hdr->frame_control)))
+   sta = ieee80211_find_sta_by_ifaddr(rtwdev->hw, hdr->addr2,
+  vif->addr);
+   else
+   return;
+
+   if (!sta)
+   return;
+
+   si = (struct rtw_sta_info *)sta->drv_priv;
+   ewma_rssi_add(>avg_rssi, pkt_stat->rssi);
+}
+
+static void rtw_rx_addr_match(struct rtw_dev *rtwdev,
+ struct rtw_rx_pkt_stat *pkt_stat,
+ struct ieee80211_hdr *hdr)
+{
+   struct rtw_rx_addr_match_data data = {};
+
+   if (pkt_stat->crc_err || pkt_stat->icv_err || !pkt_stat->phy_status ||
+   ieee80211_is_ctl(hdr->frame_control))
+   return;
+
+   data.rtwdev = rtwdev;
+   data.hdr = hdr;
+   data.pkt_stat = pkt_stat;
+   data.bssid = get_hdr_bssid(hdr);
+
+   rtw_iterate_vifs_atomic(rtwdev, rtw_rx_addr_match_iter, );
+}
+
+void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
+  struct rtw_rx_pkt_stat *pkt_stat,
+  struct ieee80211_hdr *hdr,
+  struct ieee80211_rx_status *rx_status,
+  u8 *phy_status)
+{
+   struct ieee80211_hw *hw = rtwdev->hw;
+
+   memset(rx_status, 0, sizeof(*rx_status));
+   rx_status->freq = hw->conf.chandef.chan->center_freq;
+   rx_status->band = hw->conf.chandef.chan->band;
+   if (pkt_stat->crc_err)
+   rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
+   if (pkt_stat->decrypted)
+   rx_status->flag |= RX_FLAG_DECRYPTED;
+
+   if (pkt_stat->rate >= DESC_RATEVHT1SS_MCS0)
+   rx_status->encoding = RX_ENC_VHT;
+   else if (pkt_stat->rate >= DESC_RATEMCS0)
+   rx_status->encoding = RX_ENC_HT;
+
+   if (pkt_stat->rate >= DESC_RATEVHT1SS_MCS0 &&
+   pkt_stat->rate <= DESC_RATEVHT1SS_MCS9) {
+   rx_status->nss = 1;
+   rx_status->rate_idx = pkt_stat->rate - DESC_RATEVHT1SS_MCS0;
+   } else if (pkt_stat->rate >= DESC_RATEVHT2SS_MCS0 &&
+  pkt_stat->rate <= DESC_RATEVHT2SS_MCS9) {
+   rx_status->nss = 2;
+   rx_status->rate_idx = pkt_stat->rate - DESC_RATEVHT2SS_MCS0;
+   } else if 

[PATCH v2 05/13] rtw88: mac files

2018-11-16 Thread yhchuang
From: Yan-Hsuan Chuang 

mac files for Realtek 802.11ac wireless network chips

Signed-off-by: Yan-Hsuan Chuang 
---
 drivers/net/wireless/realtek/rtw88/mac.c | 1010 ++
 drivers/net/wireless/realtek/rtw88/mac.h |   35 ++
 2 files changed, 1045 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw88/mac.c
 create mode 100644 drivers/net/wireless/realtek/rtw88/mac.h

diff --git a/drivers/net/wireless/realtek/rtw88/mac.c 
b/drivers/net/wireless/realtek/rtw88/mac.c
new file mode 100644
index 000..126e489
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/mac.c
@@ -0,0 +1,1010 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2018  Realtek Corporation.
+ */
+
+#include "main.h"
+#include "mac.h"
+#include "reg.h"
+#include "fw.h"
+#include "debug.h"
+
+void rtw_set_channel_mac(struct rtw_dev *rtwdev, u8 channel, u8 bw,
+u8 primary_ch_idx)
+{
+   u8 txsc40 = 0, txsc20 = 0;
+   u32 value32;
+   u8 value8;
+
+   txsc20 = primary_ch_idx;
+   if (txsc20 == 1 || txsc20 == 3)
+   txsc40 = 9;
+   else
+   txsc40 = 10;
+   rtw_write8(rtwdev, REG_DATA_SC,
+  BIT_TXSC_20M(txsc20) | BIT_TXSC_40M(txsc40));
+
+   value32 = rtw_read32(rtwdev, REG_WMAC_TRXPTCL_CTL);
+   value32 &= ~BIT_RFMOD;
+   switch (bw) {
+   case RTW_CHANNEL_WIDTH_80:
+   value32 |= BIT_RFMOD_80M;
+   break;
+   case RTW_CHANNEL_WIDTH_40:
+   value32 |= BIT_RFMOD_40M;
+   break;
+   case RTW_CHANNEL_WIDTH_20:
+   default:
+   break;
+   }
+   rtw_write32(rtwdev, REG_WMAC_TRXPTCL_CTL, value32);
+
+   value32 = rtw_read32(rtwdev, REG_AFE_CTRL1) & ~(BIT_MAC_CLK_SEL);
+   value32 |= (MAC_CLK_HW_DEF_80M << BIT_SHIFT_MAC_CLK_SEL);
+   rtw_write32(rtwdev, REG_AFE_CTRL1, value32);
+
+   rtw_write8(rtwdev, REG_USTIME_TSF, MAC_CLK_SPEED);
+   rtw_write8(rtwdev, REG_USTIME_EDCA, MAC_CLK_SPEED);
+
+   value8 = rtw_read8(rtwdev, REG_CCK_CHECK);
+   value8 = value8 & ~BIT_CHECK_CCK_EN;
+   if (channel > 35)
+   value8 |= BIT_CHECK_CCK_EN;
+   rtw_write8(rtwdev, REG_CCK_CHECK, value8);
+}
+
+static int rtw_mac_pre_system_cfg(struct rtw_dev *rtwdev)
+{
+   u32 value32;
+   u8 value8;
+
+   rtw_write8(rtwdev, REG_RSV_CTRL, 0);
+
+   switch (rtw_hci_type(rtwdev)) {
+   case RTW_HCI_TYPE_PCIE:
+   rtw_write32_set(rtwdev, REG_HCI_OPT_CTRL, BIT_BT_DIG_CLK_EN);
+   break;
+   case RTW_HCI_TYPE_USB:
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   /* config PIN Mux */
+   value32 = rtw_read32(rtwdev, REG_PAD_CTRL1);
+   value32 |= BIT_PAPE_WLBT_SEL | BIT_LNAON_WLBT_SEL;
+   rtw_write32(rtwdev, REG_PAD_CTRL1, value32);
+
+   value32 = rtw_read32(rtwdev, REG_LED_CFG);
+   value32 &= ~(BIT_PAPE_SEL_EN | BIT_LNAON_SEL_EN);
+   rtw_write32(rtwdev, REG_LED_CFG, value32);
+
+   value32 = rtw_read32(rtwdev, REG_GPIO_MUXCFG);
+   value32 |= BIT_WLRFE_4_5_EN;
+   rtw_write32(rtwdev, REG_GPIO_MUXCFG, value32);
+
+   /* disable BB/RF */
+   value8 = rtw_read8(rtwdev, REG_SYS_FUNC_EN);
+   value8 &= ~(BIT_FEN_BB_RSTB | BIT_FEN_BB_GLB_RST);
+   rtw_write8(rtwdev, REG_SYS_FUNC_EN, value8);
+
+   value8 = rtw_read8(rtwdev, REG_RF_CTRL);
+   value8 &= ~(BIT_RF_SDM_RSTB | BIT_RF_RSTB | BIT_RF_EN);
+   rtw_write8(rtwdev, REG_RF_CTRL, value8);
+
+   value32 = rtw_read32(rtwdev, REG_WLRF1);
+   value32 &= ~BIT_WLRF1_BBRF_EN;
+   rtw_write32(rtwdev, REG_WLRF1, value32);
+
+   return 0;
+}
+
+static int rtw_pwr_cmd_polling(struct rtw_dev *rtwdev,
+  struct rtw_pwr_seq_cmd *cmd)
+{
+   u8 value;
+   u8 flag = 0;
+   u32 offset;
+   u32 cnt = RTW_PWR_POLLING_CNT;
+
+   if (cmd->base == RTW_PWR_ADDR_SDIO)
+   offset = cmd->offset | SDIO_LOCAL_OFFSET;
+   else
+   offset = cmd->offset;
+
+   do {
+   cnt--;
+   value = rtw_read8(rtwdev, offset);
+   value &= cmd->mask;
+   if (value == (cmd->value & cmd->mask))
+   return 0;
+   if (cnt == 0) {
+   if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_PCIE &&
+   flag == 0) {
+   value = rtw_read8(rtwdev, REG_SYS_PW_CTRL);
+   value |= BIT(3);
+   rtw_write8(rtwdev, REG_SYS_PW_CTRL, value);
+   value &= ~BIT(3);
+   rtw_write8(rtwdev, REG_SYS_PW_CTRL, value);
+   cnt = RTW_PWR_POLLING_CNT;
+   flag = 1;
+   } else {
+   return -EBUSY;
+   }
+   

[PATCH v2 3/7] mt76: fix race condition in station removal

2018-11-16 Thread Felix Fietkau
If there are still pending packets in the tx queue when removing a station,
it could possibly lead to a call to further attempts to pull packets from
the mac80211 tx queue after it has already been removed from the scheduling
list.
Prevent this from happening by calling synchronize_rcu after deleting the
wcid pointer before further cleaning up the tx queues.
To be extra careful, ensure that mtxq->list is always initialized properly.

Signed-off-by: Felix Fietkau 
---
v2: keep the call to mt76x02_mac_wcid_setup in place

 drivers/net/wireless/mediatek/mt76/mt76x02_util.c | 4 +++-
 drivers/net/wireless/mediatek/mt76/tx.c   | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index d2ac1a84668c..1a51193d5d59 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -216,9 +216,11 @@ int mt76x02_sta_remove(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
int idx = msta->wcid.idx;
int i;
 
+   rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
+   synchronize_rcu();
+
mutex_lock(>mt76.mutex);
mt76_tx_status_check(>mt76, >wcid, true);
-   rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
mt76_txq_remove(>mt76, sta->txq[i]);
mt76x02_mac_wcid_set_drop(dev, idx, true);
diff --git a/drivers/net/wireless/mediatek/mt76/tx.c 
b/drivers/net/wireless/mediatek/mt76/tx.c
index e42a24628e4f..f4093dc0e174 100644
--- a/drivers/net/wireless/mediatek/mt76/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/tx.c
@@ -590,7 +590,7 @@ void mt76_txq_remove(struct mt76_dev *dev, struct 
ieee80211_txq *txq)
 
spin_lock_bh(>lock);
if (!list_empty(>list))
-   list_del(>list);
+   list_del_init(>list);
spin_unlock_bh(>lock);
 
while ((skb = skb_dequeue(>retry_q)) != NULL)
-- 
2.17.0



[PATCH v2 6/7] mt76: mt76x02: remove mt76x02_txq_init

2018-11-16 Thread Felix Fietkau
Open-coding it simplifies the code

Signed-off-by: Felix Fietkau 
---
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 23 ---
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  2 --
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 15 +---
 3 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index 4c35d3f7fb15..c08bf371e527 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -126,29 +126,6 @@ void mt76x02_mac_wcid_set_drop(struct mt76x02_dev *dev, u8 
idx, bool drop)
mt76_wr(dev, MT_WCID_DROP(idx), (val & ~bit) | (bit * drop));
 }
 
-void mt76x02_txq_init(struct mt76x02_dev *dev, struct ieee80211_txq *txq)
-{
-   struct mt76_txq *mtxq;
-
-   if (!txq)
-   return;
-
-   mtxq = (struct mt76_txq *) txq->drv_priv;
-   if (txq->sta) {
-   struct mt76x02_sta *sta;
-
-   sta = (struct mt76x02_sta *) txq->sta->drv_priv;
-   mtxq->wcid = >wcid;
-   } else {
-   struct mt76x02_vif *mvif;
-
-   mvif = (struct mt76x02_vif *) txq->vif->drv_priv;
-   mtxq->wcid = >group_wcid;
-   }
-
-   mt76_txq_init(>mt76, txq);
-}
-
 static __le16
 mt76x02_mac_tx_rate_val(struct mt76x02_dev *dev,
const struct ieee80211_tx_rate *rate, u8 *nss_val)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
index cf5c06a0a58a..4e597004c445 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
@@ -178,8 +178,6 @@ static inline bool mt76x02_wait_for_mac(struct mt76_dev 
*dev)
return false;
 }
 
-void mt76x02_txq_init(struct mt76x02_dev *dev, struct ieee80211_txq *txq);
-
 void mt76x02_mac_set_short_preamble(struct mt76x02_dev *dev, bool enable);
 int mt76x02_mac_shared_key_setup(struct mt76x02_dev *dev, u8 vif_idx,
 u8 key_idx, struct ieee80211_key_conf *key);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index 0ea7ab9cf0c6..f5ebed75b939 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -191,8 +191,13 @@ int mt76x02_sta_add(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
msta->wcid.hw_key_idx = -1;
mt76x02_mac_wcid_setup(dev, idx, mvif->idx, sta->addr);
mt76x02_mac_wcid_set_drop(dev, idx, false);
-   for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
-   mt76x02_txq_init(dev, sta->txq[i]);
+   for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
+   struct mt76_txq *mtxq;
+
+   mtxq = (struct mt76_txq *) sta->txq[i]->drv_priv;
+   mtxq->wcid = >wcid;
+   mt76_txq_init(>mt76, sta->txq[i]);
+   }
 
if (vif->type == NL80211_IFTYPE_AP)
set_bit(MT_WCID_FLAG_CHECK_PS, >wcid.flags);
@@ -230,11 +235,15 @@ void mt76x02_vif_init(struct mt76x02_dev *dev, struct 
ieee80211_vif *vif,
  unsigned int idx)
 {
struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;
+   struct mt76_txq *mtxq;
 
mvif->idx = idx;
mvif->group_wcid.idx = MT_VIF_WCID(idx);
mvif->group_wcid.hw_key_idx = -1;
-   mt76x02_txq_init(dev, vif->txq);
+   mtxq = (struct mt76_txq *) vif->txq->drv_priv;
+   mtxq->wcid = >group_wcid;
+
+   mt76_txq_init(>mt76, vif->txq);
 }
 EXPORT_SYMBOL_GPL(mt76x02_vif_init);
 
-- 
2.17.0



[PATCH v2 1/7] mt76: avoid queue/status spinlocks while passing tx status to mac80211

2018-11-16 Thread Felix Fietkau
There is some code in the mac80211 tx status processing code that could
potentially call back into the tx codepath.
To avoid deadlocks, make sure that no tx related spinlocks are taken
during the ieee80211_tx_status call.

Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/dma.c  | 11 ++--
 drivers/net/wireless/mediatek/mt76/mac80211.c |  2 +-
 drivers/net/wireless/mediatek/mt76/mt76.h | 30 --
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 11 ++--
 .../net/wireless/mediatek/mt76/mt76x02_util.c |  2 +-
 drivers/net/wireless/mediatek/mt76/tx.c   | 58 ---
 6 files changed, 76 insertions(+), 38 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/dma.c 
b/drivers/net/wireless/mediatek/mt76/dma.c
index 2d7bd26875c6..d62f8d9f2ea1 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -157,17 +157,20 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, enum 
mt76_txq_id qid, bool flush)
if (entry.schedule)
q->swq_queued--;
 
-   if (entry.skb)
+   q->tail = (q->tail + 1) % q->ndesc;
+   q->queued--;
+
+   if (entry.skb) {
+   spin_unlock_bh(>lock);
dev->drv->tx_complete_skb(dev, q, , flush);
+   spin_lock_bh(>lock);
+   }
 
if (entry.txwi) {
mt76_put_txwi(dev, entry.txwi);
wake = true;
}
 
-   q->tail = (q->tail + 1) % q->ndesc;
-   q->queued--;
-
if (!flush && q->tail == last)
last = ioread32(>regs->dma_idx);
}
diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c 
b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 85e05a825b5d..3be73b021d27 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -359,7 +359,7 @@ void mt76_unregister_device(struct mt76_dev *dev)
 {
struct ieee80211_hw *hw = dev->hw;
 
-   mt76_tx_status_flush(dev, NULL);
+   mt76_tx_status_check(dev, NULL, true);
ieee80211_unregister_hw(hw);
mt76_tx_free(dev);
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index e1d89163ee6b..ea74ba00aebc 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -648,28 +648,22 @@ void mt76_rx_aggr_stop(struct mt76_dev *dev, struct 
mt76_wcid *wcid, u8 tid);
 
 void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
 struct ieee80211_key_conf *key);
+
+void mt76_tx_status_lock(struct mt76_dev *dev, struct sk_buff_head *list)
+__acquires(>status_list.lock);
+void mt76_tx_status_unlock(struct mt76_dev *dev, struct sk_buff_head *list)
+  __releases(>status_list.lock);
+
 int mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid,
   struct sk_buff *skb);
 struct sk_buff *mt76_tx_status_skb_get(struct mt76_dev *dev,
-  struct mt76_wcid *wcid, int pktid);
-void mt76_tx_status_skb_done(struct mt76_dev *dev, struct sk_buff *skb);
+  struct mt76_wcid *wcid, int pktid,
+  struct sk_buff_head *list);
+void mt76_tx_status_skb_done(struct mt76_dev *dev, struct sk_buff *skb,
+struct sk_buff_head *list);
 void mt76_tx_complete_skb(struct mt76_dev *dev, struct sk_buff *skb);
-
-static inline void
-mt76_tx_status_check(struct mt76_dev *dev)
-{
-   spin_lock_bh(>status_list.lock);
-   mt76_tx_status_skb_get(dev, NULL, 0);
-   spin_unlock_bh(>status_list.lock);
-}
-
-static inline void
-mt76_tx_status_flush(struct mt76_dev *dev, struct mt76_wcid *wcid)
-{
-   spin_lock_bh(>status_list.lock);
-   mt76_tx_status_skb_get(dev, wcid, -1);
-   spin_unlock_bh(>status_list.lock);
-}
+void mt76_tx_status_check(struct mt76_dev *dev, struct mt76_wcid *wcid,
+ bool flush);
 
 struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
index 59b336e34cb5..4c35d3f7fb15 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
@@ -438,12 +438,13 @@ void mt76x02_send_tx_status(struct mt76x02_dev *dev,
struct mt76_wcid *wcid = NULL;
struct mt76x02_sta *msta = NULL;
struct mt76_dev *mdev = >mt76;
+   struct sk_buff_head list;
 
if (stat->pktid == MT_PACKET_ID_NO_ACK)
return;
 
rcu_read_lock();
-   spin_lock_bh(>status_list.lock);
+   mt76_tx_status_lock(mdev, );
 
if (stat->wcid < 

[PATCH v2 5/7] mt76: mt76x02: make group_wcid the first member in struct mt76x02_vif

2018-11-16 Thread Felix Fietkau
Allows mt76 core to cast vif->drv_priv to struct mt76_wcid

Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
index b076c4305585..cf5c06a0a58a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
@@ -37,9 +37,8 @@ struct mt76x02_tx_status {
 #define MT_MAX_VIFS8
 
 struct mt76x02_vif {
+   struct mt76_wcid group_wcid; /* must be first */
u8 idx;
-
-   struct mt76_wcid group_wcid;
 };
 
 DECLARE_EWMA(signal, 10, 8);
-- 
2.17.0



[PATCH v2 4/7] mt76: add mt76_sta_remove helper

2018-11-16 Thread Felix Fietkau
This allows station removal code to be used by mt7603 later

Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 19 +++
 drivers/net/wireless/mediatek/mt76/mt76.h |  2 ++
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 12 +++-
 3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c 
b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 3be73b021d27..1098919f5498 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -630,3 +630,22 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum 
mt76_rxq_id q,
mt76_rx_complete(dev, , napi);
 }
 EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
+
+void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
+struct ieee80211_sta *sta)
+{
+   struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+   int idx = wcid->idx;
+   int i;
+
+   rcu_assign_pointer(dev->wcid[idx], NULL);
+   synchronize_rcu();
+
+   mutex_lock(>mutex);
+   mt76_tx_status_check(dev, wcid, true);
+   for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
+   mt76_txq_remove(dev, sta->txq[i]);
+   mt76_wcid_free(dev->wcid_mask, idx);
+   mutex_unlock(>mutex);
+}
+EXPORT_SYMBOL_GPL(mt76_sta_remove);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index ea74ba00aebc..878836fe80d3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -664,6 +664,8 @@ void mt76_tx_status_skb_done(struct mt76_dev *dev, struct 
sk_buff *skb,
 void mt76_tx_complete_skb(struct mt76_dev *dev, struct sk_buff *skb);
 void mt76_tx_status_check(struct mt76_dev *dev, struct mt76_wcid *wcid,
  bool flush);
+void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
+struct ieee80211_sta *sta);
 
 struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
index 1a51193d5d59..0ea7ab9cf0c6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
@@ -212,19 +212,13 @@ int mt76x02_sta_remove(struct ieee80211_hw *hw, struct 
ieee80211_vif *vif,
   struct ieee80211_sta *sta)
 {
struct mt76x02_dev *dev = hw->priv;
-   struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;
-   int idx = msta->wcid.idx;
-   int i;
+   struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+   int idx = wcid->idx;
 
-   rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
-   synchronize_rcu();
+   mt76_sta_remove(>mt76, vif, sta);
 
mutex_lock(>mt76.mutex);
-   mt76_tx_status_check(>mt76, >wcid, true);
-   for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
-   mt76_txq_remove(>mt76, sta->txq[i]);
mt76x02_mac_wcid_set_drop(dev, idx, true);
-   mt76_wcid_free(dev->mt76.wcid_mask, idx);
mt76x02_mac_wcid_setup(dev, idx, 0, NULL);
mutex_unlock(>mt76.mutex);
 
-- 
2.17.0



[PATCH v2 2/7] mt76: do not wake tx queues during flush

2018-11-16 Thread Felix Fietkau
While the queue is being cleaned up, the stack must not attempt to add
any extra packets

Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/dma.c 
b/drivers/net/wireless/mediatek/mt76/dma.c
index d62f8d9f2ea1..e2ba26378575 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -168,7 +168,7 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, enum mt76_txq_id 
qid, bool flush)
 
if (entry.txwi) {
mt76_put_txwi(dev, entry.txwi);
-   wake = true;
+   wake = !flush;
}
 
if (!flush && q->tail == last)
-- 
2.17.0



[PATCH v2 7/7] mt76: replace sta_add/remove ops with common sta_state function

2018-11-16 Thread Felix Fietkau
Allows adding unassociated stations from mac80211

Signed-off-by: Felix Fietkau 
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 61 ++-
 drivers/net/wireless/mediatek/mt76/mt76.h | 12 +++-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  5 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  5 +-
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  8 +--
 .../net/wireless/mediatek/mt76/mt76x02_util.c | 40 +++-
 .../wireless/mediatek/mt76/mt76x2/pci_init.c  |  2 +
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  3 +-
 .../wireless/mediatek/mt76/mt76x2/usb_init.c  |  2 +
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  3 +-
 10 files changed, 92 insertions(+), 49 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c 
b/drivers/net/wireless/mediatek/mt76/mac80211.c
index 1098919f5498..d3f94163ef8e 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -631,8 +631,40 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum 
mt76_rxq_id q,
 }
 EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
 
-void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
-struct ieee80211_sta *sta)
+static int
+mt76_sta_add(struct mt76_dev *dev, struct ieee80211_vif *vif,
+struct ieee80211_sta *sta)
+{
+   struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+   int ret;
+   int i;
+
+   mutex_lock(>mutex);
+
+   ret = dev->drv->sta_add(dev, vif, sta);
+   if (ret)
+   goto out;
+
+   for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
+   struct mt76_txq *mtxq;
+
+   mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
+   mtxq->wcid = wcid;
+
+   mt76_txq_init(dev, sta->txq[i]);
+   }
+
+   rcu_assign_pointer(dev->wcid[wcid->idx], wcid);
+
+out:
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+
+static void
+mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
+   struct ieee80211_sta *sta)
 {
struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
int idx = wcid->idx;
@@ -642,10 +674,33 @@ void mt76_sta_remove(struct mt76_dev *dev, struct 
ieee80211_vif *vif,
synchronize_rcu();
 
mutex_lock(>mutex);
+
+   if (dev->drv->sta_remove)
+   dev->drv->sta_remove(dev, vif, sta);
+
mt76_tx_status_check(dev, wcid, true);
for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
mt76_txq_remove(dev, sta->txq[i]);
mt76_wcid_free(dev->wcid_mask, idx);
+
mutex_unlock(>mutex);
 }
-EXPORT_SYMBOL_GPL(mt76_sta_remove);
+
+int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta,
+  enum ieee80211_sta_state old_state,
+  enum ieee80211_sta_state new_state)
+{
+   struct mt76_dev *dev = hw->priv;
+
+   if (old_state == IEEE80211_STA_NOTEXIST &&
+   new_state == IEEE80211_STA_NONE)
+   return mt76_sta_add(dev, vif, sta);
+
+   if (old_state == IEEE80211_STA_NONE &&
+new_state == IEEE80211_STA_NOTEXIST)
+   mt76_sta_remove(dev, vif, sta);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(mt76_sta_state);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index 878836fe80d3..5cd508a68609 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -288,6 +288,12 @@ struct mt76_driver_ops {
 
void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,
   bool ps);
+
+   int (*sta_add)(struct mt76_dev *dev, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta);
+
+   void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta);
 };
 
 struct mt76_channel_state {
@@ -664,8 +670,10 @@ void mt76_tx_status_skb_done(struct mt76_dev *dev, struct 
sk_buff *skb,
 void mt76_tx_complete_skb(struct mt76_dev *dev, struct sk_buff *skb);
 void mt76_tx_status_check(struct mt76_dev *dev, struct mt76_wcid *wcid,
  bool flush);
-void mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
-struct ieee80211_sta *sta);
+int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+  struct ieee80211_sta *sta,
+  enum ieee80211_sta_state old_state,
+  enum ieee80211_sta_state new_state);
 
 struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb);
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c 
b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
index 757816d2b1ab..d895b6f3dc44 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
@@ -90,8 +90,7 @@ static const struct ieee80211_ops 

Re: [PATCH 3/4] mt76: fix race condition in station removal

2018-11-16 Thread Felix Fietkau
On 2018-11-13 20:41, Felix Fietkau wrote:
> If there are still pending packets in the tx queue when removing a station,
> it could possibly lead to a call to further attempts to pull packets from
> the mac80211 tx queue after it has already been removed from the scheduling
> list.
> Prevent this from happening by calling synchronize_rcu after deleting the
> wcid pointer before further cleaning up the tx queues.
> To be extra careful, ensure that mtxq->list is always initialized properly.
> 
> Also drop the useless call to mt76x02_mac_wcid_setup, which only re-assigns
> the bss index of the wcid entry, but does not help with the cleanup in any
> way.
I misread the code and the call to mt76x02_mac_wcid_setup matters after
all. Will send a v2 of this series with further improvements.

- Felix


Re: wiki: tree labels in patches

2018-11-16 Thread Rafał Miłecki

On 2018-11-16 09:46, Kalle Valo wrote:

(changing subject for better visibility and trimming Cc)

Rafał Miłecki  writes:


On 2018-11-09 15:05, Kalle Valo wrote:

Rafał Miłecki  writes:


From: Rafał Miłecki 

Driver can report IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ so it's
important to provide valid & complete info about supported bands for
each channel. By default no support for 160 MHz should be assumed
unless
firmware reports it for a given channel later.

This fixes info passed to the userspace. Without that change 
userspace

could try to use invalid channel and fail to start an interface.

Signed-off-by: Rafał Miłecki 
Cc: sta...@vger.kernel.org


Should this be queued to 4.20?


That's my suggestion.

I try to mark fixes (patches for currently developed release) with an
extra FIX tag in a subject. Do you have any other method in mind that
would be preferred by you?


Yes, I do see your FIX tag in patchwork:

 [ 31] [FIX] brcmfmac: fix reporting support for 160 MHz channels   
2018-11-08


But "FIX" is a bit ambigous as not all fixes not go to 
wireless-drivers,
they can also go to wireless-drivers-next. So I prefer using the 
release

number (or name of the tree) like this:

[PATCH 4.20] brcmfmac: fix reporting support for 160 MHz channels

After seeing your question I added something about this to the wiki
which hopefully helps others:

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#tree_labels


Got it, thanks!


Re: wiki: tree labels in patches

2018-11-16 Thread Kalle Valo
Johannes Berg  writes:

> On Fri, 2018-11-16 at 10:46 +0200, Kalle Valo wrote:
>
>> Yes, I do see your FIX tag in patchwork:
>> 
>>  [ 31] [FIX] brcmfmac: fix reporting support for 160 MHz channels   
>> 2018-11-08 
>> 
>> But "FIX" is a bit ambigous as not all fixes not go to wireless-drivers,
>> they can also go to wireless-drivers-next. So I prefer using the release
>> number (or name of the tree) like this:
>> 
>> [PATCH 4.20] brcmfmac: fix reporting support for 160 MHz channels
>
> FWIW, davem/networking just use 
>
> [PATCH net]
> [PATCH net-next]
>
> which puts a bit more effort on the submitter but is a bit easier on the
> maintainer I suppose. Also, not really a problem here, but it would help
> disambiguate different trees on the same mailing list. I don't really
> mind either way.

Actually I already added that to the wiki[1] but made it optional just
bacause it's harder for patch submitters who are not so familiar with
our tree structure. But yes, I also like using the full tree name as the
label, even more so as it would help me to automatically assign patches
to correct maintainers in patchwork.

[1] 
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#tree_labels

-- 
Kalle Valo


Re: wiki: tree labels in patches

2018-11-16 Thread Johannes Berg
On Fri, 2018-11-16 at 10:46 +0200, Kalle Valo wrote:

> Yes, I do see your FIX tag in patchwork:
> 
>  [ 31] [FIX] brcmfmac: fix reporting support for 160 MHz channels   
> 2018-11-08 
> 
> But "FIX" is a bit ambigous as not all fixes not go to wireless-drivers,
> they can also go to wireless-drivers-next. So I prefer using the release
> number (or name of the tree) like this:
> 
> [PATCH 4.20] brcmfmac: fix reporting support for 160 MHz channels

FWIW, davem/networking just use 

[PATCH net]
[PATCH net-next]

which puts a bit more effort on the submitter but is a bit easier on the
maintainer I suppose. Also, not really a problem here, but it would help
disambiguate different trees on the same mailing list. I don't really
mind either way.

johannes



wiki: tree labels in patches

2018-11-16 Thread Kalle Valo
(changing subject for better visibility and trimming Cc)

Rafał Miłecki  writes:

> On 2018-11-09 15:05, Kalle Valo wrote:
>> Rafał Miłecki  writes:
>>
>>> From: Rafał Miłecki 
>>>
>>> Driver can report IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ so it's
>>> important to provide valid & complete info about supported bands for
>>> each channel. By default no support for 160 MHz should be assumed
>>> unless
>>> firmware reports it for a given channel later.
>>>
>>> This fixes info passed to the userspace. Without that change userspace
>>> could try to use invalid channel and fail to start an interface.
>>>
>>> Signed-off-by: Rafał Miłecki 
>>> Cc: sta...@vger.kernel.org
>>
>> Should this be queued to 4.20?
>
> That's my suggestion.
>
> I try to mark fixes (patches for currently developed release) with an
> extra FIX tag in a subject. Do you have any other method in mind that
> would be preferred by you?

Yes, I do see your FIX tag in patchwork:

 [ 31] [FIX] brcmfmac: fix reporting support for 160 MHz channels   2018-11-08 

But "FIX" is a bit ambigous as not all fixes not go to wireless-drivers,
they can also go to wireless-drivers-next. So I prefer using the release
number (or name of the tree) like this:

[PATCH 4.20] brcmfmac: fix reporting support for 160 MHz channels

After seeing your question I added something about this to the wiki
which hopefully helps others:

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#tree_labels

-- 
Kalle Valo


Re: [PATCH FIX] brcmfmac: fix reporting support for 160 MHz channels

2018-11-16 Thread Kalle Valo
Rafał Miłecki  writes:

> On 2018-11-09 15:05, Kalle Valo wrote:
>> Rafał Miłecki  writes:
>>
>>> From: Rafał Miłecki 
>>>
>>> Driver can report IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ so it's
>>> important to provide valid & complete info about supported bands for
>>> each channel. By default no support for 160 MHz should be assumed
>>> unless
>>> firmware reports it for a given channel later.
>>>
>>> This fixes info passed to the userspace. Without that change userspace
>>> could try to use invalid channel and fail to start an interface.
>>>
>>> Signed-off-by: Rafał Miłecki 
>>> Cc: sta...@vger.kernel.org
>>
>> Should this be queued to 4.20?
>
> That's my suggestion.

Ok, I'll queue this for 4.20.

-- 
Kalle Valo