Re: [RFC v4 08/13] rtw88: debug files

2018-10-13 Thread Joe Perches
On Sat, 2018-10-13 at 18:23 +0300, Kalle Valo wrote:
> Joe Perches  writes:
> 
> > On Sat, 2018-10-13 at 17:00 +0800, yhchu...@realtek.com wrote:
> > > From: Yan-Hsuan Chuang 
> > []
> > > diff --git a/drivers/net/wireless/realtek/rtw88/debug.c
> > > b/drivers/net/wireless/realtek/rtw88/debug.c
> > []
> > > +#ifdef CONFIG_RTW88_DEBUG
> > > +
> > > +void __rtw_dbg(struct rtw_dev *rtwdev, const char *fmt, ...)
> > > +{
> > > + struct va_format vaf = {
> > > + .fmt = fmt,
> > > + };
> > > + va_list args;
> > > +
> > > + va_start(args, fmt);
> > > + vaf.va = 
> > > +
> > > + if (net_ratelimit())
> > > + dev_dbg(rtwdev->dev, "%pV", );
> > > +
> > > + va_end(args);
> > > +}
> > > +EXPORT_SYMBOL(__rtw_dbg);
> > > +
> > > +#define __rtw_fn(fn) 
> > > \
> > > +void __rtw_ ##fn(struct rtw_dev *rtwdev, const char *fmt, ...)   
> > > \
> > > +{
> > > \
> > > + struct va_format vaf = {\
> > > + .fmt = fmt, \
> > > + };  \
> > > + va_list args;   \
> > > + \
> > > + va_start(args, fmt);\
> > > + vaf.va =  \
> > > + dev_ ##fn(rtwdev->dev, "%pV", );\
> > > + va_end(args);   \
> > > +}
> > > \
> > > +EXPORT_SYMBOL(__rtw_ ##fn);
> > > +
> > > +__rtw_fn(info)
> > > +__rtw_fn(warn)
> > > +__rtw_fn(err)
> > 
> > It's very unusual to have _all_ the logging under a CONFIG__DEBUG
> > config guard flag.
> 
> For wireless drivers that is actually quite typical.

No, it isn't.

> IIRC at least ath6kl, ath9k and ath10k do that, most likely also others.

No, they don't.  Check again.

> > Typical debugging would dynamic debugging on a per-line instance andl
> > this uses a single dev_dbg for all debugging.
> 
> I don't recall seeing anyone using per-line dynamic debugging with
> wireless drivers. The drivers are so complex that enabling one message
> at a time doesn't really get you anywhere, that's why we mostly group
> messages into similar groups (or levels) to make it easier to enable
> certain debug messages.

You should look harder.  

> > This seems unnecessarily complexity for a negative gain.
> 
> I haven't reviewed the driver yet but from a quick look I don't see this
> as a problem.
  
It is unnecessarily complex.
This saves one dereference per call, but is it really worth it?




Re: [RFC v3 01/12] rtw88: main files

2018-10-13 Thread Kalle Valo
Tony Chuang  writes:

>> > +static void rtw_watch_dog_work(struct work_struct *work)
>> > +{
>> > +  struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
>> > +watch_dog_work.work);
>> > +  struct rtw_vif *rtwvif;
>> > +
>> > +  if (!rtw_flag_check(rtwdev, RTW_FLAG_RUNNING))
>> > +  return;
>> > +
>> > +  ieee80211_queue_delayed_work(rtwdev->hw,
>> >watch_dog_work,
>> > +   RTW_WATCH_DOG_DELAY_TIME);
>> 
>> You're aware of the power cost of waking up every 2 seconds? That's a
>> really bad idea, in general, at the very least you should use a more
>> power efficient scheduling here to combine with other wakeups
>> (round_jiffies_relative, or so).
>
> Yeah I knew it, but so far we can only work like this...
> Will use round_jiffies_relative to combine the CPU wakeups.

Can you elaborate more why this horrible timer is needed? And it
definitely needs a comment in the code explaining the reason.

-- 
Kalle Valo


Re: [PATCH 1/5] qtnfmac: use 'help' in Kconfig

2018-10-13 Thread Kalle Valo
Sergey Matyukevich  wrote:

> Fix checkpatch warning: use preferred 'help' option in Kconfig.
> 
> Signed-off-by: Sergey Matyukevich 

3 patches applied to wireless-drivers-next.git, thanks.

db62abe51853 qtnfmac: use 'help' in Kconfig
b458a033ca2f qtnfmac: use SPDX identifier for pcie bus layer files
4cb5054957b2 qtnfmac_pcie: cleanup Pearl platform headers

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

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



Re: [PATCH v4] brcmsmac: AP mode: update beacon when TIM changes

2018-10-13 Thread Kalle Valo
Ali MJ Al-Nasrawy  wrote:

> Beacons are not updated to reflect TIM changes. This is not compliant with
> power-saving client stations as the beacons do not have valid TIM and can
> cause the network to stall at random occasions and to have highly variable
> latencies.
> Fix it by updating beacon templates on mac80211 set_tim callback.
> 
> Addresses an issue described in:
> https://marc.info/?i=20180911163534.21312d08%20()%20manjaro
> 
> Signed-off-by: Ali MJ Al-Nasrawy 

Patch applied to wireless-drivers-next.git, thanks.

2258ee58baa5 brcmsmac: AP mode: update beacon when TIM changes

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

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



pull request: mt76 2018-10-13 v2

2018-10-13 Thread Felix Fietkau
Hi Kalle,

Here's another large batch of mt76 code cleanup / deduplication / fixes
v2: add missing S-o-b.

- Felix

The following changes since commit c894696188d5c2af1e636e458190e80c53fb893d:

  rtlwifi: rtl8821ae: replace _rtl8821ae_mrate_idx_to_arfr_id with generic 
version (2018-10-13 15:00:37 +0300)

are available in the Git repository at:

  https://github.com/nbd168/wireless tags/mt76-for-kvalo-2018-10-13

for you to fetch changes up to f27a058199ee6da50d724302d42fff94a00851c7:

  mt76x0: phy: do not run calibration during channel switch (2018-10-13 
16:35:16 +0200)


mt76 patches for 4.20

* mt76x0 fixes
* mt76x0e improvements (should be usable now)
* usb support improvements
* more mt76x0/mt76x2 unification work
* minor fix for aggregation + powersave clients


Felix Fietkau (2):
  mt76: do not store aggregation sequence number for null-data frames
  mt76: mt76x0e: another fix for the external PA current setting

Lorenzo Bianconi (26):
  mt76x0: phy: fix bank check in mt76x0_rf_csr_{wr,rr}
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_phy.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_util.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_usb_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mac.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_txrx.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_eeprom.c
  mt76x0: pci: report firmware version using ethtool
  mt76x0: pci: add missing mac80211 callbacks
  mt76: disable ldpc coding for mt76x0 devices
  mt76x0: pci: add mt76x0_register_device in mt76x0e_register_device
  mt76x0: phy: fix restore phase in mt76x0_phy_recalibrate_after_assoc
  mt76x0: phy: remove channel parameter from mt76x0_phy_set_chan_bbp_params
  mt76: move mt76x02_phy_set_bw in mt76x02-lib module
  mt76: move mt76x02_phy_set_band in mt76x02-lib module
  mt76x0: pci: rename mt76x0_phy_calibrate
  mt76x0: pci: introduce mt76x0_phy_calirate routine
  mt76x0: phy: update set_channel for mt76x0e devices
  mt76x0: eeprom: introduce mt76x0_tssi_enabled routine
  mt76x0: phy: add phy/vco temperature compensation
  mt76: move rssi_gain_thresh routines in mt76x02-lib module
  mt76: move mt76x02_phy_adjust_vga_gain in mt76/mt76x02_phy.c
  mt76: introduce mt76x02_init_agc_gain routine
  mt76x0: phy: align channel gain logic to mt76x2 one
  mt76x0: phy: do not run calibration during channel switch

Stanislaw Gruszka (7):
  mt76x0: print BBP version only for debug
  mt76x0: correct RF access via RF_CSR register.
  mt76: allow to identify bus
  mt76x0: correct RF reg pairs write for PCIe
  mt76x0: use bus helper to identify rf access method
  mt76: reserve enough room for USB tx skbs
  mt76x0: remove dma.h

YueHaibing (1):
  mt76x0: pci: fix set external PA I/O current

 drivers/net/wireless/mediatek/mt76/mmio.c |   1 +
 drivers/net/wireless/mediatek/mt76/mt76.h |   9 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h   | 126 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c|  55 -
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h|   6 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c  |   9 ++-
 drivers/net/wireless/mediatek/mt76/mt76x0/main.c  |  22 ---
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h   |   3 +
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h|   3 +-
 drivers/net/wireless/mediatek/mt76/mt76x0/pci.c   |  49 ++-
 drivers/net/wireless/mediatek/mt76/mt76x0/pci_mcu.c   |   1 +
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c   | 311 
++--
 drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c   |   7 +--
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  25 +---
 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c   |  33 +--
 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h   |  37 +++-
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c  | 206 
+++
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.h  |  31 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c  |  74 
+++
 drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h  |  14 +++--
 drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c |   2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_phy.c  | 167 
+---
 drivers/net/wireless/mediatek/mt76/mt76x02_phy.h  |  39 ++--
 drivers/net/wireless/mediatek/mt76/mt76x02_regs.h |   4 +-

Re: pull request: mt76 2018-10-13

2018-10-13 Thread Kalle Valo
Felix Fietkau  writes:

> Hi Kalle,
>
> Here's another batch of mt76 code cleanup / deduplication / fixes
>
> - Felix
>
> The following changes since commit c894696188d5c2af1e636e458190e80c53fb893d:
>
>   rtlwifi: rtl8821ae: replace _rtl8821ae_mrate_idx_to_arfr_id with generic 
> version (2018-10-13 15:00:37 +0300)
>
> are available in the Git repository at:
>
>   https://github.com/nbd168/wireless tags/mt76-for-kvalo-2018-10-13
>
> for you to fetch changes up to f27a058199ee6da50d724302d42fff94a00851c7:
>
>   mt76x0: phy: do not run calibration during channel switch (2018-10-13 
> 16:35:16 +0200)
>
> 
> mt76 patches for 4.20
>
> * mt76x0 fixes
> * mt76x0e improvements (should be usable now)
> * usb support improvements
> * more mt76x0/mt76x2 unification work
> * minor fix for aggregation + powersave clients
>
> 

Your s-o-b is missing from some of the patches, I can't pull this.

-- 
Kalle Valo


Re: [RFC v4 08/13] rtw88: debug files

2018-10-13 Thread Kalle Valo
Joe Perches  writes:

> On Sat, 2018-10-13 at 17:00 +0800, yhchu...@realtek.com wrote:
>> From: Yan-Hsuan Chuang 
> []
>> diff --git a/drivers/net/wireless/realtek/rtw88/debug.c
>> b/drivers/net/wireless/realtek/rtw88/debug.c
> []
>> +#ifdef CONFIG_RTW88_DEBUG
>> +
>> +void __rtw_dbg(struct rtw_dev *rtwdev, const char *fmt, ...)
>> +{
>> +struct va_format vaf = {
>> +.fmt = fmt,
>> +};
>> +va_list args;
>> +
>> +va_start(args, fmt);
>> +vaf.va = 
>> +
>> +if (net_ratelimit())
>> +dev_dbg(rtwdev->dev, "%pV", );
>> +
>> +va_end(args);
>> +}
>> +EXPORT_SYMBOL(__rtw_dbg);
>> +
>> +#define __rtw_fn(fn)
>> \
>> +void __rtw_ ##fn(struct rtw_dev *rtwdev, const char *fmt, ...)  
>> \
>> +{   \
>> +struct va_format vaf = {\
>> +.fmt = fmt, \
>> +};  \
>> +va_list args;   \
>> +\
>> +va_start(args, fmt);\
>> +vaf.va =  \
>> +dev_ ##fn(rtwdev->dev, "%pV", );\
>> +va_end(args);   \
>> +}   \
>> +EXPORT_SYMBOL(__rtw_ ##fn);
>> +
>> +__rtw_fn(info)
>> +__rtw_fn(warn)
>> +__rtw_fn(err)
>
> It's very unusual to have _all_ the logging under a CONFIG__DEBUG
> config guard flag.

For wireless drivers that is actually quite typical. IIRC at least
ath6kl, ath9k and ath10k do that, most likely also others.

> Typical debugging would dynamic debugging on a per-line instance and
> this uses a single dev_dbg for all debugging.

I don't recall seeing anyone using per-line dynamic debugging with
wireless drivers. The drivers are so complex that enabling one message
at a time doesn't really get you anywhere, that's why we mostly group
messages into similar groups (or levels) to make it easier to enable
certain debug messages.

> This seems unnecessarily complexity for a negative gain.

I haven't reviewed the driver yet but from a quick look I don't see this
as a problem.

> Also, many callers of the rtw_ logging function do not include
> a terminating newline.
>
> Please consistently use a newline for each format.

But with this I do agree.

-- 
Kalle Valo


pull request: mt76 2018-10-13

2018-10-13 Thread Felix Fietkau
Hi Kalle,

Here's another batch of mt76 code cleanup / deduplication / fixes

- Felix

The following changes since commit c894696188d5c2af1e636e458190e80c53fb893d:

  rtlwifi: rtl8821ae: replace _rtl8821ae_mrate_idx_to_arfr_id with generic 
version (2018-10-13 15:00:37 +0300)

are available in the Git repository at:

  https://github.com/nbd168/wireless tags/mt76-for-kvalo-2018-10-13

for you to fetch changes up to f27a058199ee6da50d724302d42fff94a00851c7:

  mt76x0: phy: do not run calibration during channel switch (2018-10-13 
16:35:16 +0200)


mt76 patches for 4.20

* mt76x0 fixes
* mt76x0e improvements (should be usable now)
* usb support improvements
* more mt76x0/mt76x2 unification work
* minor fix for aggregation + powersave clients


Felix Fietkau (2):
  mt76: do not store aggregation sequence number for null-data frames
  mt76: mt76x0e: another fix for the external PA current setting

Lorenzo Bianconi (26):
  mt76x0: phy: fix bank check in mt76x0_rf_csr_{wr,rr}
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_phy.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_util.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_usb_mcu.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mac.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_txrx.c
  mt76: use mt76x02_dev instead of mt76_dev in mt76x02_eeprom.c
  mt76x0: pci: report firmware version using ethtool
  mt76x0: pci: add missing mac80211 callbacks
  mt76: disable ldpc coding for mt76x0 devices
  mt76x0: pci: add mt76x0_register_device in mt76x0e_register_device
  mt76x0: phy: fix restore phase in mt76x0_phy_recalibrate_after_assoc
  mt76x0: phy: remove channel parameter from mt76x0_phy_set_chan_bbp_params
  mt76: move mt76x02_phy_set_bw in mt76x02-lib module
  mt76: move mt76x02_phy_set_band in mt76x02-lib module
  mt76x0: pci: rename mt76x0_phy_calibrate
  mt76x0: pci: introduce mt76x0_phy_calirate routine
  mt76x0: phy: update set_channel for mt76x0e devices
  mt76x0: eeprom: introduce mt76x0_tssi_enabled routine
  mt76x0: phy: add phy/vco temperature compensation
  mt76: move rssi_gain_thresh routines in mt76x02-lib module
  mt76: move mt76x02_phy_adjust_vga_gain in mt76/mt76x02_phy.c
  mt76: introduce mt76x02_init_agc_gain routine
  mt76x0: phy: align channel gain logic to mt76x2 one
  mt76x0: phy: do not run calibration during channel switch

Stanislaw Gruszka (7):
  mt76x0: print BBP version only for debug
  mt76x0: correct RF access via RF_CSR register.
  mt76: allow to identify bus
  mt76x0: correct RF reg pairs write for PCIe
  mt76x0: use bus helper to identify rf access method
  mt76: reserve enough room for USB tx skbs
  mt76x0: remove dma.h

YueHaibing (1):
  mt76x0: pci: fix set external PA I/O current

 drivers/net/wireless/mediatek/mt76/mmio.c |   1 +
 drivers/net/wireless/mediatek/mt76/mt76.h |   9 +++
 drivers/net/wireless/mediatek/mt76/mt76x0/dma.h   | 126 
---
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c|  55 -
 drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h|   6 ++
 drivers/net/wireless/mediatek/mt76/mt76x0/init.c  |   9 ++-
 drivers/net/wireless/mediatek/mt76/mt76x0/main.c  |  22 ---
 drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h   |   3 +
 drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h|   3 +-
 drivers/net/wireless/mediatek/mt76/mt76x0/pci.c   |  49 ++-
 drivers/net/wireless/mediatek/mt76/mt76x0/pci_mcu.c   |   1 +
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c   | 311 
++--
 drivers/net/wireless/mediatek/mt76/mt76x0/usb_mcu.c   |   7 +--
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  25 +---
 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c   |  33 +--
 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h   |  37 +++-
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c  | 206 
+++
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.h  |  31 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c  |  74 
+++
 drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h  |  14 +++--
 drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c |   2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_phy.c  | 167 
+---
 drivers/net/wireless/mediatek/mt76/mt76x02_phy.h  |  39 ++--
 drivers/net/wireless/mediatek/mt76/mt76x02_regs.h |   4 +-
 

Re: [RFC v4 08/13] rtw88: debug files

2018-10-13 Thread Joe Perches
On Sat, 2018-10-13 at 17:00 +0800, yhchu...@realtek.com wrote:
> From: Yan-Hsuan Chuang 
[]
> diff --git a/drivers/net/wireless/realtek/rtw88/debug.c 
> b/drivers/net/wireless/realtek/rtw88/debug.c
[]
> +#ifdef CONFIG_RTW88_DEBUG
> +
> +void __rtw_dbg(struct rtw_dev *rtwdev, const char *fmt, ...)
> +{
> + struct va_format vaf = {
> + .fmt = fmt,
> + };
> + va_list args;
> +
> + va_start(args, fmt);
> + vaf.va = 
> +
> + if (net_ratelimit())
> + dev_dbg(rtwdev->dev, "%pV", );
> +
> + va_end(args);
> +}
> +EXPORT_SYMBOL(__rtw_dbg);
> +
> +#define __rtw_fn(fn) \
> +void __rtw_ ##fn(struct rtw_dev *rtwdev, const char *fmt, ...)   
> \
> +{\
> + struct va_format vaf = {\
> + .fmt = fmt, \
> + };  \
> + va_list args;   \
> + \
> + va_start(args, fmt);\
> + vaf.va =  \
> + dev_ ##fn(rtwdev->dev, "%pV", );\
> + va_end(args);   \
> +}\
> +EXPORT_SYMBOL(__rtw_ ##fn);
> +
> +__rtw_fn(info)
> +__rtw_fn(warn)
> +__rtw_fn(err)

It's very unusual to have _all_ the logging under a CONFIG__DEBUG
config guard flag.  Typical debugging would dynamic debugging on a
per-line instance and this uses a single dev_dbg for all debugging.

This seems unnecessarily complexity for a negative gain.

Also, many callers of the rtw_ logging function do not include
a terminating newline.

Please consistently use a newline for each format.



Re: [PATCH 5/5] qtnfmac: add support for Topaz chipsets

2018-10-13 Thread Kalle Valo
Sergey Matyukevich  writes:

> This patch adds support for QSR1000/QSR2000 family of chipsets
> to qtnfmac_pcie platform driver.
>
> QSR1000/QSR2000 (aka Topaz) is a family of 80MHz, 11ac Wave2,
> 4x4/2x4/2x2 chips, including single and dual band devices.
> Depending on specific chip model and firmware in use, either
> STA or both STA and AP modes are supported.
>
> Patch adds Topaz support to qtnfmac_pcie driver. It is possible
> to enable both Topaz and Pearl support in kernel configuration.
> In that case proper platform bus will be selected on probing
> based on chip ID.
>
> Signed-off-by: Igor Mitsyanko 
> Signed-off-by: Sergey Matyukevich 
> Signed-off-by: Andrey Shevchenko 

[...]

> +config QTNFMAC_TOPAZ_PCIE
> + tristate "Quantenna QSR1000/QSR2000 PCIe support"
> + default n
> + depends on PCI && CFG80211
> + select QTNFMAC
> + select FW_LOADER
> + select CRC32
> + help
> +   This option adds support for wireless adapters based on Quantenna
> +   802.11ac QSR1000/QSR2000 (aka Topaz) FullMAC chipset
> +   running over PCIe.
> +
> +   If you choose to build it as a module, two modules will be built:
> +   qtnfmac.ko and qtnfmac_pcie.ko.

I'm not really fond of adding a Kconfig option for every supported
hardware version unless there are very good reasons (memory savings
etc). So is this really needed?

A much better approach would be to have a generic QTNFMAC_PCIE option
which can be used to include or exclude all PCI code.

-- 
Kalle Valo


Re: [PATCH] iwlwifi: mvm: check return value of rs_rate_from_ucode_rate()

2018-10-13 Thread Kalle Valo
Luca Coelho  wrote:

> From: Luca Coelho 
> 
> The rs_rate_from_ucode_rate() function may return -EINVAL if the rate
> is invalid, but none of the callsites check for the error, potentially
> making us access arrays with index IWL_RATE_INVALID, which is larger
> than the arrays, causing an out-of-bounds access.  This will trigger
> KASAN warnings, such as the one reported in the bugzilla issue
> mentioned below.
> 
> This fixes https://bugzilla.kernel.org/show_bug.cgi?id=200659
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Luca Coelho 

Patch applied to wireless-drivers-next.git, thanks.

3d71c3f1f50c iwlwifi: mvm: check return value of rs_rate_from_ucode_rate()

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

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



Re: pull-request: iwlwifi-next 2018-10-12

2018-10-13 Thread Kalle Valo
Luca Coelho  writes:

> Hi Kalle,
>
> This is the fourth batch of patches intended for v4.20.  This includes
> only the last patchset I sent.  Usual development work, mostly queue
> handling cleanups.  More details about the contents in the tag
> description.
>
> I have sent this out before and kbuildbot reported success.
>
> Please let me know if there are any issues.
>
> Cheers,
> Luca.
>
>
> The following changes since commit abf1a08ff3237a27188ff8cc2904f2cea893af55:
>
>   net: vhost: remove bad code line (2018-10-07 21:31:32 -0700)
>
> are available in the Git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-next.git 
> tags/iwlwifi-next-for-kalle-2018-10-12
>
> for you to fetch changes up to 724fe7710ac5f4289886b90060ed67e3a4bdd584:
>
>   iwlwifi: mvm: kill INACTIVE queue state (2018-10-08 10:49:22 +0300)
>
> 
> Fourth set of iwlwifi patches intended for 4.20
>
> * Support for a new scan type;
> * Clean-up in the queue handling code;
> * A few bug fixes;
>
> 

Pulled, thanks.

-- 
Kalle Valo


Re: [RFC v3] cfg80211: add peer measurement with FTM API

2018-10-13 Thread Kalle Valo
Johannes Berg  writes:

> From: Johannes Berg 
>
> Add a new "peer measurement" API, that can be used to measure
> certain things related to a peer. Right now, only implement
> FTM (flight time measurement) over it, but the idea is that
> it'll be extensible to also support measuring the necessary
> things to calculate e.g. angle-of-arrival for WiGig.
>
> The API is structured to have a generic list of peers and
> channels to measure with/on, and then for each of those a
> set of measurements (again, only FTM right now) to perform.
>
> Results are sent to the requesting socket, including a final
> complete message.
>
> Closing the controlling netlink socket will abort a running
> measurement.
>
> Signed-off-by: Johannes Berg 
> ---
> v3:
>  - add a bit to report "final" for partial results
>  - remove list keeping etc. and just unicast out the results
>to the requester (big code reduction ...)
>  - also send complete message unicast, and as a result
>remove the multicast group
>  - separate out struct cfg80211_pmsr_ftm_request_peer
>from struct cfg80211_pmsr_request_peer
>  - document timeout == 0 if no timeout
>  - disallow setting timeout nl80211 attribute to 0,
>must not include attribute for no timeout
>  - make MAC address randomization optional
>  - change num bursts exponent default to 0 (1 burst, rather
>rather than the old default of 15==don't care)

[...]

> @@ -3176,6 +3361,8 @@ struct cfg80211_ftm_responder_stats {
>   *
>   * @get_ftm_responder_stats: Retrieve FTM responder statistics, if available.
>   *   Statistics should be cumulative, currently no way to reset is provided.
> + * @start_pmsr: start peer measurement (e.g. FTM)
> + * @abort_pmsr: abort peer measurement
>   */
>  struct cfg80211_ops {
>   int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);

It would be nice to document if these ops can sleep or not.

-- 
Kalle Valo


Re: [PATCH v4 4/8] rt2800: fix registers init for MT7620

2018-10-13 Thread Kalle Valo
Stanislaw Gruszka  writes:

> There is duplicated 'if (rt2x00_rt(rt2x00dev, RT6352))' entry that
> causes we do not perform register initialization for RT6352 (MT7620
> SOCs) in correct branch. Fix this and disable registers initialization
> that is specific to particular MT7620 revision.
>
> Signed-off-by: Stanislaw Gruszka 

[...]

> @@ -5466,6 +5465,10 @@ static int rt2800_init_registers(struct rt2x00_dev 
> *rt2x00dev)
>   rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x0401);
>   rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x000C);
>   rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x000C0408);
> + /* TODO add chip version support and init registers
> +  * according to the version.
> +  */
> +#if 0
>   rt2800_register_write(rt2x00dev, MIMO_PS_CFG, 0x0002);
>   rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0x00150F0F);
>   rt2800_register_write(rt2x00dev, TX_ALC_VGA3, 0x06060606);
> @@ -5480,6 +5483,7 @@ static int rt2800_init_registers(struct rt2x00_dev 
> *rt2x00dev)
>   reg = rt2800_register_read(rt2x00dev, TX_ALC_CFG_1);
>   rt2x00_set_field32(, TX_ALC_CFG_1_ROS_BUSY_EN, 0);
>   rt2800_register_write(rt2x00dev, TX_ALC_CFG_1, reg);
> +#endif

No '#if 0', please. If the code is not needed you can remove it, it's
available from git history anyway if it's needed later.

-- 
Kalle Valo


[PATCH] linux-firmware: add firmware for mt7610e

2018-10-13 Thread Lorenzo Bianconi
Add binary firmware for mt7610e based devices

Signed-off-by: Lorenzo Bianconi 
---
 WHENCE   |   3 ++-
 mediatek/mt7610e.bin | Bin 0 -> 80680 bytes
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 mediatek/mt7610e.bin

diff --git a/WHENCE b/WHENCE
index b480062..b493364 100644
--- a/WHENCE
+++ b/WHENCE
@@ -3968,9 +3968,10 @@ Licence: Redistributable. See LICENCE.rockchip for 
details.
 
 --
 
-Driver: mt76x0 - MediaTek MT76x0u Wireless MACs
+Driver: mt76x0 - MediaTek MT76x0 Wireless MACs
 
 File: mediatek/mt7610u.bin
+File: mediatek/mt7610e.bin
 Version: 2.6
 
 Licence: Redistributable. See LICENCE.mediatek for details.
diff --git a/mediatek/mt7610e.bin b/mediatek/mt7610e.bin
new file mode 100644
index 
..76600842a70c374aefeb1bf36ae5a88f35651ecb
GIT binary patch
literal 80680
zcmcG%4R}=5wLiSi$4t&-CgdaxFd!0ud5K*=HCg0V56=b?D`-5m0ICtwE@A
z@3l93CMRKn6A3YdU;|Dhgy5wC>KN(2-0Og}jjgw0bu3m=BO)d(mGEJu)@%O1eP$+!
zz1sWU_j%qt%ToA8W6@_S$Q@$3dacKtyzT7$B6KlDhYG)3kvfK^9u^{3ySW;
zUnwD*@wpzK$@omd$AQmyeC+sS;-lg-2A>7^q~fFCW5!3uM{FecPa4UB^pB3MTO*6>
z9!b1?=wfA+k4h{)l`ZVe8p$ys2W4f{l~7kgT?w%Cb%6gr
z!~EYuY$ST>I*~{oA`>4G7wXP#XX2T-)q90b4VW<>A;LPjPtx%}D(PgMm?L>?1T~1b
zP9jptAlbiaXd6kCCBTCD)F9DmOnly7rdAChC*UKtKIClise1lMPATye>8$f-2ZT;f
zr{2wa_cW4QhCV-b@$-oD_=NCrop!$3J++&5`T?WHM^aaZ0}-JNtr+dOEMa;E`6;M^24AJ@5?cJCVV}k#a_Q3eu-1(oXZbsFSFB_*gvsss7
zo(V%ke@g5kh({`EI!$f9%k*J~4dd9eyt8G(t!$FFc3ZiLiVenas?$_vH)i
z^P*$+2nXlcUm#+*_`pxPrbGZA29R7Z|us7Sjm|D{KPXF>Pj)O
zbD=*s@~Wo+Z8mLPUAAs07U_6f2^VfvfE)3B>Oa{#d%+`zf$@Sz+R<0`zFYl61}Y
z-am#)`n~Si%Rm6@~~A2`y(@lWx6%KCa|cg~HO@s=391&_2O=-+be;x!iarZXA27L?uGJ3Bn5
zM~qqa2%U2nuY=S8?VZh{gF>QA2yf;KN*szY{#WBL*!!cPJj%?iOFJJmMxMh^duNY^
zaKRSm0?fZ-iSe$C*Y(42y-J}ThLO;vlLs!d++^w7`<#MzV=eV~(esso
zhS2HvE+z8Vmmt;nHU=6JkWPICBo>Fndg73_P!0)rC1_;uH|A`FxV?|5jp}KI!f
z%|*P{C?6rk_i44SceYOO98gp0IW_sWgjUVIwZa8ABpK$T8S}BIHy3XiiMP_;T-1u^
z`0y+wp4S_tCMMoC_vXf*YSy8y18)Xr>M|%5pDPVW!RS_Fq(D3Lcq>maA*B>}MRlS|
zPn97>_I+BbVEl5u(o@UzQu|tVBU1VJv~yUp>LUs{pnIJ8B)piaLAi7B==pl^*vD^q
zU-m03>UW_X3n+Wk?IbF*`ltHk+xsR9ESJA~)BO(P?FPI#*%Y)P_&(io3N24@s{*GJ
z-h)r@cQ%tPW$W2{i8N>L>_5#~@W??>KQ5b)j#*f9ctq+nljhPLqI*tS#jdPfQ%M1#
zJErO3;tV^{#0HY#AY}Kqmw@7BzN$~3X{yt`D~Y2xgOZ63BHSSkeeQJ;XR%->6GbMR
z`P@SVGj+-qpUXyCnwlDS$`SFk>t8jM7qIkNHMUUqmt|6gzcrm%l0K9ko2v)-8
zL0DOmJ~$McK?@Em?kVX*u^V5tdF~ua=Ouiu^dVXhRVY!#*wk8~%t5U@-7{qn>8BJf
z>tf^d03fCD^pbR5zE4@D;G0m)LXSFxltH5;C9+6~P3{)sa@UYW6^h10-E+?xVp_eH
z2!7&{lpKE+xTO}W!YeHTn+p2XswKhalHYm@`Rpoey6vZ
zm>FMnIUfDGr#{QbQFyEM=Ca12E4mO%+5MLf9vYB#ABnxE6W$>3bC?YS!iTX~ob
zxgK!jly4_P;H1T_b-|50qj8?MMt2?7oy_bvmH_d6R)^o}#qp~i=Qgw4#C6#qK
zX3}p!nn@Q`iBNYwQPsIbV|hu6Ff&`+JDng;pISzule{O1!#fvvs@@lfWBG50h2=3x
zFYTSqtZY^+h0Pj%%QI3_*$n21^J#5Se1(gkCkq}qdhBA~PG|XHHpF|-eEQ@{w2;qC
z`n0nAD665Y*?j>gfaSABp{*Q{eQsw=Be5h$7|Z;?Y=PN0D14y})W_>w*N8!}{Xe
z`-+4fXUDC27IN*U1o@;vLHrR$AV~q>t2r623Nq7Bf&%>G-GC+xC>*
z-d89@Z|Nv*73=7(YvudM5PuG)zF*P*YAoHrZ4Ps?+l_h4sd}_`_D4DW*?uc4Ws4Hj
z4<{&{QuRZ41u?j(wM8(Zr22`amv`PCM2VVo*K2c(b?6EVt8PzAK9ar!N>clcO`
zkMWUiCawxc!mTre9T8i7Ed)KCG?+q`)LW|E9)Jnb9C7lPmCQOQ*f_y^r&)9
zHpX@D>2%~3>7`zYsKyMCFvfP0ub1+-xU@I;ya}UnqWm!UjfljbWk19wCNNmnJG@c0=J;dZI6PbmT
zu}_B{`y1ms}dAnGV==BPTLYAg*SuNvipsL>WL8-yH0yXCwr`m!R?2Fe@S10Su;
z;J}AR=F;I~e@;cI8nPwyx-N9(>rz*NPP*n`CAqI_u79mx-`UgLuslFyUBn1o-
zo)9{9T)gX-D$6ktpQ+7OyV8*JBg%xjdIBuaARu6gG_9FSeaW{FAAQHMY(U%lUS@K2
zB>Cd4oSNu?+*C+ayXt*FhR6pdq9zR!sFtpI$mb@}aGIKsb4O7
zmu0+<$W8Z-V|*kE_=xay=_l$ql|JU^mgBSscaU?X*!n_iCKmB6$Y1&=9RYJ
z+Q1{81XdL%j1uAXfhU`F1C9s$Uo@Lou{zoR^9+byyp!HM@3a0*
z#yjK!&(U4X(woOD-mz8B>#h+@@RZxHiEh*bTr(?bMqFyPpdiPd!C2DYO
zp#l8f6nHI3J(kMnQjWl767WxDH^kqUOXOF?vyPe#XpN-%zprPN6OvNzh9q+*A}yw$6aQ|vq5sa5;D
zcls+v?kW@Ll;Ik==n=Gpc%9H}UWa{$J-M6fN6FcELz0>t8;+HCN}Rfh{$sz=
zb6>}wJLYo@fP$-*)*v3qn0YYyieb4-IIt=rQ-HavTxBWjS+*mO-!Yc_k
zs-h+|tXkr6g8#Ctm0Xf}@AFrVOJ}R*q*1Q@JHgwJJdMuX4XhK3(V*K7l8E{4|
zG$yoXHAYJzv;E(1beCuGosCXA9%m1+pdrUmGS~+x?4*R5xg`G66QgCs#Xfc%lGD%}

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

2018-10-13 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 

v4

 - remove vis_list and sta_list, use mac80211 iterator
 - use kernel helpers such as bitmap, bcd2bin, lockdep
 - move debugfs into wiphy->debugfsdir
 - use spin_lock in interrupt handler
 - remove unnecessary depends on lines in Kconfig
 - make port config constant
 - avoid watchdog timer spreading
 - return -EOPNOTSUPP for PMF key error message suppression
 - do not replace regd in wiphy for now
 - use host- fix- endian transfer in linux/bitfield.h to
   replace/get bits to/from card

v3

 - missing rcu list traverse for vif_list

v2

 - rename from rtwlan to rtw88
 - remove lots of magic numbers
 - add pci null entry for auto load on boot
 - add rtwdev->mutex to protect against mac80211 callbacks
 - add rcu lock protection for vif_list and sta_list
 - refine bits & endian macros to use helper functions provided by kernel
   instead of create new ones
 - ieee80211_free_txskb for tx path dropped packets
 - not register iface_combination since now only one vif is allowed
 - some fixes suggested by Stanislaw


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 |   652 +
 drivers/net/wireless/realtek/rtw88/debug.h |43 +
 drivers/net/wireless/realtek/rtw88/efuse.c |   150 +
 drivers/net/wireless/realtek/rtw88/efuse.h |53 +
 drivers/net/wireless/realtek/rtw88/fw.c|   655 +
 drivers/net/wireless/realtek/rtw88/fw.h|   182 +
 drivers/net/wireless/realtek/rtw88/hci.h   |   211 +
 drivers/net/wireless/realtek/rtw88/mac.c   |  1045 +
 drivers/net/wireless/realtek/rtw88/mac.h   |35 +
 drivers/net/wireless/realtek/rtw88/mac80211.c  |   478 +
 drivers/net/wireless/realtek/rtw88/main.c  |  1168 ++
 drivers/net/wireless/realtek/rtw88/main.h  |  1092 +
 drivers/net/wireless/realtek/rtw88/pci.c   |  1208 ++
 drivers/net/wireless/realtek/rtw88/pci.h   |   229 +
 drivers/net/wireless/realtek/rtw88/phy.c   |  1679 ++
 drivers/net/wireless/realtek/rtw88/phy.h   |   125 +
 drivers/net/wireless/realtek/rtw88/ps.c|   168 +
 drivers/net/wireless/realtek/rtw88/ps.h|20 +
 drivers/net/wireless/realtek/rtw88/reg.h   |   404 +
 drivers/net/wireless/realtek/rtw88/regd.c  |   328 +
 drivers/net/wireless/realtek/rtw88/regd.h  |40 +
 drivers/net/wireless/realtek/rtw88/rtw8822b.c  |  1588 ++
 drivers/net/wireless/realtek/rtw88/rtw8822b.h  |   155 +
 .../net/wireless/realtek/rtw88/rtw8822b_table.c| 20783 +++
 .../net/wireless/realtek/rtw88/rtw8822b_table.h|18 

[RFC v4 13/13] rtw88: add support for Realtek 802.11ac wireless chips

2018-10-13 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



[RFC v4 05/13] rtw88: mac files

2018-10-13 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 | 1045 ++
 drivers/net/wireless/realtek/rtw88/mac.h |   35 +
 2 files changed, 1080 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..53dd062
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/mac.c
@@ -0,0 +1,1045 @@
+// 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;
+   }
+

[RFC v4 06/13] rtw88: fw and efuse files

2018-10-13 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| 655 +
 drivers/net/wireless/realtek/rtw88/fw.h| 182 
 4 files changed, 1040 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, 

[RFC v4 01/13] rtw88: main files

2018-10-13 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 |  478 ++
 drivers/net/wireless/realtek/rtw88/main.c | 1168 +
 drivers/net/wireless/realtek/rtw88/main.h | 1092 +++
 drivers/net/wireless/realtek/rtw88/reg.h  |  404 +
 4 files changed, 3142 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..0afcfad
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/mac80211.c
@@ -0,0 +1,478 @@
+// 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) {
+   

[RFC v4 03/13] rtw88: hci files

2018-10-13 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..6774c8e
--- /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, 

[RFC v4 08/13] rtw88: debug files

2018-10-13 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 | 652 +
 drivers/net/wireless/realtek/rtw88/debug.h |  43 ++
 2 files changed, 695 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..4876a3b
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/debug.c
@@ -0,0 +1,652 @@
+// 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,
+   

[RFC v4 11/13] rtw88: 8822C init table

2018-10-13 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,
+   

[RFC v4 07/13] rtw88: phy files

2018-10-13 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 | 1679 ++
 drivers/net/wireless/realtek/rtw88/phy.h |  125 +++
 2 files changed, 1804 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..8277eb0
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/phy.c
@@ -0,0 +1,1679 @@
+// 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 

[RFC v4 09/13] rtw88: chip files

2018-10-13 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  | 1588 
 drivers/net/wireless/realtek/rtw88/rtw8822b.h  |  155 ++
 .../net/wireless/realtek/rtw88/rtw8822b_table.h|   18 +
 drivers/net/wireless/realtek/rtw88/rtw8822c.c  | 1167 ++
 drivers/net/wireless/realtek/rtw88/rtw8822c.h  |  171 +++
 .../net/wireless/realtek/rtw88/rtw8822c_table.h|   16 +
 6 files changed, 3115 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..8435860
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
@@ -0,0 +1,1588 @@
+// 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->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);
+   rtw_write32_mask(rtwdev, 0xcbc, 0x8, 0x0);
+   /* SW control */
+   rtw_write8(rtwdev, 0xcb4, 0x77);

[RFC v4 04/13] rtw88: trx files

2018-10-13 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 | 153 ++
 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, 548 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..e68ef1a
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/rx.c
@@ -0,0 +1,153 @@
+// 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);
+   ieee80211_iterate_active_interfaces_atomic(rtwdev->hw,
+  IEEE80211_IFACE_ITER_NORMAL,
+  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 &&
+  

[RFC v4 12/13] rtw88: Kconfig & Makefile

2018-10-13 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



[RFC v4 02/13] rtw88: core files

2018-10-13 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   | 168 +++
 drivers/net/wireless/realtek/rtw88/ps.h   |  20 ++
 drivers/net/wireless/realtek/rtw88/regd.c | 328 ++
 drivers/net/wireless/realtek/rtw88/regd.h |  40 
 drivers/net/wireless/realtek/rtw88/sec.c  | 120 +++
 drivers/net/wireless/realtek/rtw88/sec.h  |  39 
 6 files changed, 715 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..28b7204
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw88/ps.c
@@ -0,0 +1,168 @@
+// 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, "fail to leave ips state");
+   return ret;
+   }
+
+   ieee80211_iterate_active_interfaces_atomic(rtwdev->hw,
+   IEEE80211_IFACE_ITER_NORMAL,
+   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)
+ 

Re: [Make-wifi-fast] [PATCH RFC v5 3/4] mac80211: Add airtime accounting and scheduling to TXQs

2018-10-13 Thread Dave Taht
On Fri, Oct 12, 2018 at 12:38 AM Rajkumar Manoharan
 wrote:
>
> On 2018-10-11 03:38, Toke Høiland-Jørgensen wrote:
> > Rajkumar Manoharan  writes:
> >
> >> Hmm... mine is bit different. txqs are refilled only once for all
> >> txqs.
> >> It will give more opportunity for non-served txqs. drv_wake_tx_queue
> >> won't be
> >> called from may_tx as the driver anyway will not push packets in
> >> pull-mode.
> >
> > So, as far as I can tell, this requires the hardware to "keep trying"?
> > I.e., if it just stops scheduling a TXQ after may_transmit() returns
> > false, there is no guarantee that that TXQ will ever get re-awoken
> > unless a new packet arrives for it?
> >
> That is true and even now ath10k operates the same way in pull mode. Not
> just packet arrival, even napi poll routine tries to pushes the packets.
> One more thing, fetch indication may pull ~4ms/8ms of packets from each
> tid.
> This makes deficit too low and so refilling txqs by just airtime_weight
> becomes
> cumbersome. In may_transmit, the deficit are incremented by 20 *
> airtime_weight.
> In future this will be also replaced by station specific quantum. we can
> revisit
> this once BQL in place. Performance issue is resolved by this approach.
> Do you foresee any issues?

I'll have some time in the coming weeks to be able to test this stuff.
I'm mostly interested
in algorithmic correctness more than the API changes...

Is there a version of these patches that is stable enough on ath9 or ath10k?

Do I foresee any issues? Jeeze, no, we *never* have any issues with wifi.

"fetch indication may pull ~4ms/8ms of packets from each tid"

made me really twitchy.
>
> #define IEEE80211_TXQ_MAY_TX_QUANTUM  20
> bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
>  struct ieee80211_txq *txq)
> {
>  struct ieee80211_local *local = hw_to_local(hw);
>  struct txq_info *txqi = to_txq_info(txq);
>  struct sta_info *sta;
>  u8 ac = txq->ac;
>
>  lockdep_assert_held(>active_txq_lock[ac]);
>
>  if (!txqi->txq.sta)
>  goto out;
>
>  sta = container_of(txqi->txq.sta, struct sta_info, sta);
>  if (sta->airtime[ac].deficit >= 0)
>  goto out;
>
>  list_for_each_entry(txqi, >active_txqs[ac],
> schedule_order) {
>  if (!txqi->txq.sta)
>  continue;
>  sta = container_of(txqi->txq.sta, struct sta_info, sta);
>  sta->airtime[ac].deficit +=
>  (IEEE80211_TXQ_MAY_TX_QUANTUM *
> sta->airtime_weight);
>  }
>
>  return false;
>
>   out:
>  list_del_init(>schedule_order);
>  return true;
> }
>
> -Rajkumar
> ___
> Make-wifi-fast mailing list
> make-wifi-f...@lists.bufferbloat.net
> https://lists.bufferbloat.net/listinfo/make-wifi-fast



-- 

Dave Täht
CTO, TekLibre, LLC
http://www.teklibre.com
Tel: 1-831-205-9740


Re: [PATCH] iwlwifi: mvm: check return value of rs_rate_from_ucode_rate()

2018-10-13 Thread Luciano Coelho
On Sat, 2018-10-13 at 09:46 +0300, Luca Coelho wrote:
> From: Luca Coelho 
> 
> The rs_rate_from_ucode_rate() function may return -EINVAL if the rate
> is invalid, but none of the callsites check for the error,
> potentially
> making us access arrays with index IWL_RATE_INVALID, which is larger
> than the arrays, causing an out-of-bounds access.  This will trigger
> KASAN warnings, such as the one reported in the bugzilla issue
> mentioned below.
> 
> This fixes https://bugzilla.kernel.org/show_bug.cgi?id=200659
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Luca Coelho 
> ---

Kalle,

Just for the record, as we discussed on IRC, please take this patch
directly to wireless-drivers-next for 4.20 so I don't need to send a
pull-req just for it.

--
Cheers,
Luca.



[PATCH] iwlwifi: mvm: check return value of rs_rate_from_ucode_rate()

2018-10-13 Thread Luca Coelho
From: Luca Coelho 

The rs_rate_from_ucode_rate() function may return -EINVAL if the rate
is invalid, but none of the callsites check for the error, potentially
making us access arrays with index IWL_RATE_INVALID, which is larger
than the arrays, causing an out-of-bounds access.  This will trigger
KASAN warnings, such as the one reported in the bugzilla issue
mentioned below.

This fixes https://bugzilla.kernel.org/show_bug.cgi?id=200659

Cc: sta...@vger.kernel.org
Signed-off-by: Luca Coelho 
---
 drivers/net/wireless/intel/iwlwifi/mvm/rs.c | 24 -
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
index 2c75f51a04e4..089972280daa 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
@@ -1239,7 +1239,11 @@ void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct 
ieee80211_sta *sta,
!(info->flags & IEEE80211_TX_STAT_AMPDU))
return;
 
-   rs_rate_from_ucode_rate(tx_resp_hwrate, info->band, _resp_rate);
+   if (rs_rate_from_ucode_rate(tx_resp_hwrate, info->band,
+   _resp_rate)) {
+   WARN_ON_ONCE(1);
+   return;
+   }
 
 #ifdef CONFIG_MAC80211_DEBUGFS
/* Disable last tx check if we are debugging with fixed rate but
@@ -1290,7 +1294,10 @@ void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct 
ieee80211_sta *sta,
 */
table = _sta->lq;
lq_hwrate = le32_to_cpu(table->rs_table[0]);
-   rs_rate_from_ucode_rate(lq_hwrate, info->band, _rate);
+   if (rs_rate_from_ucode_rate(lq_hwrate, info->band, _rate)) {
+   WARN_ON_ONCE(1);
+   return;
+   }
 
/* Here we actually compare this rate to the latest LQ command */
if (lq_color != LQ_FLAG_COLOR_GET(table->flags)) {
@@ -1392,8 +1399,12 @@ void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct 
ieee80211_sta *sta,
/* Collect data for each rate used during failed TX attempts */
for (i = 0; i <= retries; ++i) {
lq_hwrate = le32_to_cpu(table->rs_table[i]);
-   rs_rate_from_ucode_rate(lq_hwrate, info->band,
-   _rate);
+   if (rs_rate_from_ucode_rate(lq_hwrate, info->band,
+   _rate)) {
+   WARN_ON_ONCE(1);
+   return;
+   }
+
/*
 * Only collect stats if retried rate is in the same RS
 * table as active/search.
@@ -3260,7 +3271,10 @@ static void rs_build_rates_table_from_fixed(struct 
iwl_mvm *mvm,
for (i = 0; i < num_rates; i++)
lq_cmd->rs_table[i] = ucode_rate_le32;
 
-   rs_rate_from_ucode_rate(ucode_rate, band, );
+   if (rs_rate_from_ucode_rate(ucode_rate, band, )) {
+   WARN_ON_ONCE(1);
+   return;
+   }
 
if (is_mimo())
lq_cmd->mimo_delim = num_rates - 1;
-- 
2.19.1