Re: [PATCH] rtlwifi: rtl8192de: Fix misleading REG_MCUFWDL information

2018-11-05 Thread Pkshih
On Mon, 2018-11-05 at 19:25 +0800, Shaokun Zhang wrote:
> RT_TRACE shows REG_MCUFWDL value as a decimal value with a '0x'
> prefix, which is somewhat misleading.
> 
> Fix it to print hexadecimal, as was intended.
> 
> Cc: Ping-Ke Shih 
> Cc: Kalle Valo 
> Signed-off-by: Shaokun Zhang 
> ---
>  drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
> b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
> index 85cedd0..75bfa9d 100644
> --- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
> @@ -173,7 +173,7 @@ static int _rtl92d_fw_init(struct ieee80211_hw *hw)
>    rtl_read_byte(rtlpriv, FW_MAC1_READY));
>   }
>   RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG,
> -  "Polling FW ready fail!! REG_MCUFWDL:0x%08ul\n",
> +  "Polling FW ready fail!! REG_MCUFWDL:0x%08x\n",
>    rtl_read_dword(rtlpriv, REG_MCUFWDL));
>   return -1;
>  }

Acked-by: Ping-Ke Shih 

Thanks for your fix.



[PATCH v2] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread pkshih
From: Ping-Ke Shih 

The following:
 bool efuse_re_pg_sec1flag;
 u8 efuse_re_pg_data[8];
are not referenced anywhere in the rtlwifi code.

This patch is originally created by Rick Veens ,
and Joe Perches  reminded to apply it to rtlwifi.

Signed-off-by: Ping-Ke Shih 
---
v2: change author to me
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 0f3b98c5227f..87bc21bb5e8b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -1905,10 +1905,6 @@ struct rtl_efuse {
u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
u16 efuse_usedbytes;
u8 efuse_usedpercentage;
-#ifdef EFUSE_REPG_WORKAROUND
-   bool efuse_re_pg_sec1flag;
-   u8 efuse_re_pg_data[8];
-#endif
 
u8 autoload_failflag;
u8 autoload_status;
-- 
2.15.1



Re: [PATCH] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread Pkshih
On Mon, 2018-10-01 at 12:10 +0300, Kalle Valo wrote:
>  writes:
> 
> > From: Rick Veens 
> >
> > The following:
> >  bool efuse_re_pg_sec1flag;
> >  u8 efuse_re_pg_data[8];
> > are not referenced anywhere in the rtlwifi code.
> >
> > This patch is originally created by Rick Veens ,
> > and Joe Perches  reminded to apply it to rtlwifi.
> >
> > Signed-off-by: Ping-Ke Shih 
> 
> Rick's Signed-off-by is missing. Ping, either you need to mark yourself
> as author (which IMHO is correct as you wrote this patch anyway, Rick
> wrote it for the other driver) or Rick needs to give his s-o-b.
> 

Will send v2.
Thanks

--
PK



[PATCH] rtlwifi: Removed unused define and code efuse_re_pg* from wifi.h

2018-10-01 Thread pkshih
From: Rick Veens 

The following:
 bool efuse_re_pg_sec1flag;
 u8 efuse_re_pg_data[8];
are not referenced anywhere in the rtlwifi code.

This patch is originally created by Rick Veens ,
and Joe Perches  reminded to apply it to rtlwifi.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 0f3b98c5227f..87bc21bb5e8b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -1905,10 +1905,6 @@ struct rtl_efuse {
u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
u16 efuse_usedbytes;
u8 efuse_usedpercentage;
-#ifdef EFUSE_REPG_WORKAROUND
-   bool efuse_re_pg_sec1flag;
-   u8 efuse_re_pg_data[8];
-#endif
 
u8 autoload_failflag;
u8 autoload_status;
-- 
2.15.1



Re: [PATCH v2] rtlwifi: remove set but unused variables

2018-09-03 Thread Pkshih
On Mon, 2018-09-03 at 22:57 +0800, Kevin Lo wrote:
> Remove set but unused variables from _rtl88ee_hw_configure() and
> _rtl8723e_hw_configure().
> 
> Signed-off-by: Kevin Lo 

Acked-by: Ping-Ke Shih 



Re: [PATCH] staging: r8822be: Fix RTL8822be can't find any wireless AP

2018-07-08 Thread Pkshih
On Sun, 2018-07-08 at 11:30 -0500, Larry Finger wrote:
> On 07/06/2018 12:44 AM, pks...@realtek.com wrote:
> > From: Ping-Ke Shih 
> > 
> > RTL8822be can't bring up properly on ASUS X530UN, and dmesg says:
> > [ 8.591333] r8822be: module is from the staging directory, the quality
> > is unknown, you have been warned.
> > [ 8.593122] r8822be :02:00.0: enabling device ( -> 0003)
> > [ 8.669163] r8822be: Using firmware rtlwifi/rtl8822befw.bin
> > [ 9.289939] r8822be: rtlwifi: wireless switch is on
> > [ 10.056426] r8822be :02:00.0 wlp2s0: renamed from wlan0
> > ...
> > [ 11.952534] r8822be: halmac_init_hal failed
> > [ 11.955933] r8822be: halmac_init_hal failed
> > [ 11.956227] r8822be: halmac_init_hal failed
> > [ 22.007942] r8822be: halmac_init_hal failed
> > 
> > Jian-Hong reported it works if turn off ASPM with module parameter aspm=0.
> > In order to fix this problem kindly, this commit don't turn off aspm but
> > enlarge ASPM L1 latency to 7.
> > 
> > Reported-by: Jian-Hong Pan 
> > Tested-by: Jian-Hong Pan 
> > Signed-off-by: Ping-Ke Shih 
> 
> This patch definitely needs a Cc for stable. Otherwise I ACK it.
> 

Hi Larry,

This patch had been applied by Greg, and CC'ed to stable.
Thanks for your reminder. 

PK


Re: [PATCH 13/14] rtlwifi: access skb->data to get C2H data by macro

2018-07-03 Thread Pkshih
On Fri, 2018-06-29 at 10:30 +0300, Kalle Valo wrote:
> Pkshih  writes:
> 
> > On Tue, 2018-05-29 at 08:18 +0300, Kalle Valo wrote:
> >>  writes:
> >> 
> >
> > Because C2H data is little endian order, the struct will look like
> > struct foo {
> > #ifdef __LITTLE_ENDIAN
> > u8 bar:4;
> > u8 koo:4;
> > #else
> > u8 koo:4;
> > u8 bar:4;
> > #endif
> > }
> 
> With u8 you don't need endian check, right? I would assume that with
> both little and big endian bar and koo would be in the same place.

I think u8 with bitfield would be different between little and big endian
machines.

> > Is this a linux convention?
> 
> Earlier bitfields were disliked but nowadays they seem to be have become
> more acceptable. But I think the preferred way still is something like
> this (using u32 and 16 bit fields):
> 
> struct foo {
> __le32 koobar;
> }
> 
> #define RTLWIFI_BAR_MASK GENMASK(15, 0)
> #define RTLWIFI_KOO_MASK GENMASK(31, 16)
> 
> bar = FIELD_GET(RTLWIFI_BAR_MASK, __le32_to_cpu(foo->koobar));
> koo = FIELD_GET(RTLWIFI_KOO_MASK, __le32_to_cpu(foo->koobar));
> 
> Of course there can be other good ways to do the same, others can chime
> in about those, but this is how I would do it.
> 

I will rewrite this part by your suggestions.
Thanks
PK



Re: [PATCH v2] rtlwifi: rtl8821ae: fix firmware is not ready to run

2018-06-27 Thread Pkshih
On Wed, 2018-06-27 at 08:36 -0500, Larry Finger wrote:
> On 06/27/2018 03:01 AM, pks...@realtek.com wrote:
> > From: Ping-Ke Shih 
> > 
> > rtl8821ae uses two kinds of firmwares for normal and WoWlan cases, and
> > each firmware has firmware data buffer and size individually. Original
> > code always overwrite size of normal firmware rtlpriv->rtlhal.fwsize, and
> > this mismatch causes firmware checksum error, then firmware can't start.
> > 
> > In this situation, driver gives message "Firmware is not ready to run!".
> > 
> > Fixes: fe89707f0afa ("rtlwifi: rtl8821ae: Simplify loading of WOWLAN 
> > firmware")
> > Signed-off-by: Ping-Ke Shih 
> > ---
> > v2: fix commit log typo.
> > ---
> >   drivers/net/wireless/realtek/rtlwifi/core.c | 1 -
> >   1 file changed, 1 deletion(-)
> 
> This change is a good one, and I approve of it. The only change is that it 
> should have a Cc to stable as this code was added in kernel 4.0!
> 
I'll Cc to stable in v3.

Thanks
PK



[PATCH v2] rtlwifi: rtl8821ae: fix firmware is not ready to run

2018-06-27 Thread pkshih
From: Ping-Ke Shih 

rtl8821ae uses two kinds of firmwares for normal and WoWlan cases, and
each firmware has firmware data buffer and size individually. Original
code always overwrite size of normal firmware rtlpriv->rtlhal.fwsize, and
this mismatch causes firmware checksum error, then firmware can't start.

In this situation, driver gives message "Firmware is not ready to run!".

Fixes: fe89707f0afa ("rtlwifi: rtl8821ae: Simplify loading of WOWLAN firmware")
Signed-off-by: Ping-Ke Shih 
---
v2: fix commit log typo.
---
 drivers/net/wireless/realtek/rtlwifi/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c 
b/drivers/net/wireless/realtek/rtlwifi/core.c
index a3f46203ee7a..4bf7967590ca 100644
--- a/drivers/net/wireless/realtek/rtlwifi/core.c
+++ b/drivers/net/wireless/realtek/rtlwifi/core.c
@@ -130,7 +130,6 @@ static void rtl_fw_do_work(const struct firmware *firmware, 
void *context,
   firmware->size);
rtlpriv->rtlhal.wowlan_fwsize = firmware->size;
}
-   rtlpriv->rtlhal.fwsize = firmware->size;
release_firmware(firmware);
 }
 
-- 
2.15.1



[PATCH] rtlwifi: rtl8821ae: fix firmware is not ready to run

2018-06-27 Thread pkshih
From: Ping-Ke Shih 

rtl8821ae uses two kinds of firmwares for normal and WoWlan cases, and
each firmware has two firmware data buffer and size individually. Original
code always overwrite size of normal firmware rtlpriv->rtlhal.fwsize, and
this mismatch causes firmware checksum error, then firmware can't start.

In this situation, driver gives message "Firmware is not ready to run!".

Fixes: fe89707f0afa ("rtlwifi: rtl8821ae: Simplify loading of WOWLAN firmware")
Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c 
b/drivers/net/wireless/realtek/rtlwifi/core.c
index a3f46203ee7a..4bf7967590ca 100644
--- a/drivers/net/wireless/realtek/rtlwifi/core.c
+++ b/drivers/net/wireless/realtek/rtlwifi/core.c
@@ -130,7 +130,6 @@ static void rtl_fw_do_work(const struct firmware *firmware, 
void *context,
   firmware->size);
rtlpriv->rtlhal.wowlan_fwsize = firmware->size;
}
-   rtlpriv->rtlhal.fwsize = firmware->size;
release_firmware(firmware);
 }
 
-- 
2.15.1



[PATCH v2] rtlwifi: Fix kernel Oops "Fw download fail!!"

2018-06-21 Thread pkshih
From: Ping-Ke Shih 

When connecting to AP, mac80211 asks driver to enter and leave PS quickly,
but driver deinit doesn't wait for delayed work complete when entering PS,
then driver reinit procedure and delay work are running simultaneously.
This will cause unpredictable kernel oops or crash like

rtl8723be: error H2C cmd because of Fw download fail!!!
WARNING: CPU: 3 PID: 159 at drivers/net/wireless/realtek/rtlwifi/
 rtl8723be/fw.c:227 rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
CPU: 3 PID: 159 Comm: kworker/3:2 Tainted: G   O 4.16.13-2-ARCH #1
Hardware name: ASUSTeK COMPUTER INC. X556UF/X556UF, BIOS X556UF.406
   10/21/2016
Workqueue: rtl8723be_pci rtl_c2hcmd_wq_callback [rtlwifi]
RIP: 0010:rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
RSP: 0018:a6ab01e1bd70 EFLAGS: 00010282
RAX:  RBX: a26069071520 RCX: 0001
RDX: 8001 RSI: 8be70e9c RDI: 
RBP:  R08: 0048 R09: 0348
R10:  R11: 0001 R12: 
R13: a26069071520 R14:  R15: a2607d205f70
FS:  () GS:a26081d8() knlGS:000
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0443b39d3000 CR3: 00037700a005 CR4: 003606e0
Call Trace:
 ? halbtc_send_bt_mp_operation.constprop.17+0xd5/0xe0 [btcoexist]
 ? ex_btc8723b1ant_bt_info_notify+0x3b8/0x820 [btcoexist]
 ? rtl_c2hcmd_launcher+0xab/0x110 [rtlwifi]
 ? process_one_work+0x1d1/0x3b0
 ? worker_thread+0x2b/0x3d0
 ? process_one_work+0x3b0/0x3b0
 ? kthread+0x112/0x130
 ? kthread_create_on_node+0x60/0x60
 ? ret_from_fork+0x35/0x40
Code: 00 76 b4 e9 e2 fe ff ff 4c 89 ee 4c 89 e7 e8 56 22 86 ca e9 5e ...

This patch ensures all delayed works done before entering PS to satisfy
our expectation, so use cancel_delayed_work_sync() instead. An exception
is delayed work ips_nic_off_wq because running task may be itself, so add
a parameter ips_wq to deinit function to handle this case.

This issue is reported and fixed in below threads:
https://github.com/lwfinger/rtlwifi_new/issues/367
https://github.com/lwfinger/rtlwifi_new/issues/366

Tested-by: Evgeny Kapun  # 8723DE
Tested-by: Shivam Kakkar  # 8723BE on 4.18-rc1
Signed-off-by: Ping-Ke Shih 
Fixes: cceb0a597320 ("rtlwifi: Add work queue for c2h cmd.")
Cc: Stable  # 4.11+
Reviewed-by: Larry Finger 
---
v2: Add Fixes, Cc and Reviewed-by tags suggested by Larry and Arend.
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 17 ++---
 drivers/net/wireless/realtek/rtlwifi/base.h |  2 +-
 drivers/net/wireless/realtek/rtlwifi/core.c |  2 +-
 drivers/net/wireless/realtek/rtlwifi/pci.c  |  2 +-
 drivers/net/wireless/realtek/rtlwifi/ps.c   |  4 ++--
 drivers/net/wireless/realtek/rtlwifi/usb.c  |  2 +-
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 39c817eddd78..54c9f6ab0c8c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -484,18 +484,21 @@ static void _rtl_init_deferred_work(struct ieee80211_hw 
*hw)
 
 }
 
-void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
+void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
 
del_timer_sync(>works.watchdog_timer);
 
-   cancel_delayed_work(>works.watchdog_wq);
-   cancel_delayed_work(>works.ips_nic_off_wq);
-   cancel_delayed_work(>works.ps_work);
-   cancel_delayed_work(>works.ps_rfon_wq);
-   cancel_delayed_work(>works.fwevt_wq);
-   cancel_delayed_work(>works.c2hcmd_wq);
+   cancel_delayed_work_sync(>works.watchdog_wq);
+   if (ips_wq)
+   cancel_delayed_work(>works.ips_nic_off_wq);
+   else
+   cancel_delayed_work_sync(>works.ips_nic_off_wq);
+   cancel_delayed_work_sync(>works.ps_work);
+   cancel_delayed_work_sync(>works.ps_rfon_wq);
+   cancel_delayed_work_sync(>works.fwevt_wq);
+   cancel_delayed_work_sync(>works.c2hcmd_wq);
 }
 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/base.h 
b/drivers/net/wireless/realtek/rtlwifi/base.h
index 912f205779c3..a7ae40eaa3cd 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.h
+++ b/drivers/net/wireless/realtek/rtlwifi/base.h
@@ -121,7 +121,7 @@ void rtl_init_rfkill(struct ieee80211_hw *hw);
 void rtl_deinit_rfkill(struct ieee80211_hw *hw);
 
 void rtl_watch_dog_timer_callback(struct timer_list *t);
-void rtl_deinit_deferred_work(struct ieee80211_hw *hw);
+void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq);
 
 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx);
 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht,
diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c 

Re: [PATCH] rtlwifi: Fix kernel Oops "Fw download fail!!"

2018-06-21 Thread Pkshih
On Fri, 2018-06-22 at 07:00 +0200, Arend Van Spriel wrote:
> Op vr 22 jun. 2018 04:27 schreef Pkshih :
> >
> > On Thu, 2018-06-21 at 10:14 -0500, Larry Finger wrote:
> > > On 06/21/2018 02:06 AM, pks...@realtek.com wrote:
> > > > From: Ping-Ke Shih 
> [snip]
> > > > Hi Kalle,
> > > > 
> > > > I'd like to queue this fix to 4.18, because kernel oops in users' 
> > > > laptop.
> > > 
> > > Reviewed by Larry Finger 
> > > 
> > > Is is sufficient for this patch to go to 4.18, or should it be sent to 
> > > stable, 
> > > as well.
> > > 
> >
> > You're right, it should be sent to stable.
> > It had been a potential race condition issue for a long time, but it exposed
> > when delayed work take a long time to process or wait for event.
> > I think this issue would be possibly happened since v4.11 when I move C2H 
> > handler
> > to delayed work.
> Can you provide the commit id for the Fixes: tag?

Sure.

Fixes: cceb0a597320 ("rtlwifi: Add work queue for c2h cmd.")

Thanks for your reminder.
PK



Re: [PATCH] rtlwifi: Fix kernel Oops "Fw download fail!!"

2018-06-21 Thread Pkshih
On Thu, 2018-06-21 at 10:14 -0500, Larry Finger wrote:
> On 06/21/2018 02:06 AM, pks...@realtek.com wrote:
> > From: Ping-Ke Shih 
> > 
> > When connecting to AP, mac80211 asks driver to enter and leave PS quickly,
> > but driver deinit doesn't wait for delayed work complete when entering PS,
> > then driver reinit procedure and delay work are running simultaneously.
> > This will cause unpredictable kernel oops or crash like
> > 
> > rtl8723be: error H2C cmd because of Fw download fail!!!
> > WARNING: CPU: 3 PID: 159 at drivers/net/wireless/realtek/rtlwifi/
> >  rtl8723be/fw.c:227 rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
> > CPU: 3 PID: 159 Comm: kworker/3:2 Tainted: G   O 4.16.13-2-ARCH #1
> > Hardware name: ASUSTeK COMPUTER INC. X556UF/X556UF, BIOS X556UF.406
> >    10/21/2016
> > Workqueue: rtl8723be_pci rtl_c2hcmd_wq_callback [rtlwifi]
> > RIP: 0010:rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
> > RSP: 0018:a6ab01e1bd70 EFLAGS: 00010282
> > RAX:  RBX: a26069071520 RCX: 0001
> > RDX: 8001 RSI: 8be70e9c RDI: 
> > RBP:  R08: 0048 R09: 0348
> > R10:  R11: 0001 R12: 
> > R13: a26069071520 R14:  R15: a2607d205f70
> > FS:  () GS:a26081d8() knlGS:000
> > CS:  0010 DS:  ES:  CR0: 80050033
> > CR2: 0443b39d3000 CR3: 00037700a005 CR4: 003606e0
> > Call Trace:
> >   ? halbtc_send_bt_mp_operation.constprop.17+0xd5/0xe0 [btcoexist]
> >   ? ex_btc8723b1ant_bt_info_notify+0x3b8/0x820 [btcoexist]
> >   ? rtl_c2hcmd_launcher+0xab/0x110 [rtlwifi]
> >   ? process_one_work+0x1d1/0x3b0
> >   ? worker_thread+0x2b/0x3d0
> >   ? process_one_work+0x3b0/0x3b0
> >   ? kthread+0x112/0x130
> >   ? kthread_create_on_node+0x60/0x60
> >   ? ret_from_fork+0x35/0x40
> > Code: 00 76 b4 e9 e2 fe ff ff 4c 89 ee 4c 89 e7 e8 56 22 86 ca e9 5e ...
> > 
> > This patch ensures all delayed works done before entering PS to satisfy
> > our expectation, so use cancel_delayed_work_sync() instead. An exception
> > is delayed work ips_nic_off_wq because running task may be itself, so add
> > a parameter ips_wq to deinit function to handle this case.
> > 
> > This issue is reported and fixed in below threads:
> > https://github.com/lwfinger/rtlwifi_new/issues/367
> > https://github.com/lwfinger/rtlwifi_new/issues/366
> > 
> > Tested-by: Evgeny Kapun  # 8723DE
> > Tested-by: Shivam Kakkar  # 8723BE on 4.18-rc1
> > Signed-off-by: Ping-Ke Shih 
> > ---
> > Hi Kalle,
> > 
> > I'd like to queue this fix to 4.18, because kernel oops in users' laptop.
> 
> Reviewed by Larry Finger 
> 
> Is is sufficient for this patch to go to 4.18, or should it be sent to 
> stable, 
> as well.
> 

You're right, it should be sent to stable.
It had been a potential race condition issue for a long time, but it exposed
when delayed work take a long time to process or wait for event.
I think this issue would be possibly happened since v4.11 when I move C2H 
handler
to delayed work.

Cc: Stable  # 4.11+

PK



[PATCH] rtlwifi: Fix kernel Oops "Fw download fail!!"

2018-06-21 Thread pkshih
From: Ping-Ke Shih 

When connecting to AP, mac80211 asks driver to enter and leave PS quickly,
but driver deinit doesn't wait for delayed work complete when entering PS,
then driver reinit procedure and delay work are running simultaneously.
This will cause unpredictable kernel oops or crash like

rtl8723be: error H2C cmd because of Fw download fail!!!
WARNING: CPU: 3 PID: 159 at drivers/net/wireless/realtek/rtlwifi/
 rtl8723be/fw.c:227 rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
CPU: 3 PID: 159 Comm: kworker/3:2 Tainted: G   O 4.16.13-2-ARCH #1
Hardware name: ASUSTeK COMPUTER INC. X556UF/X556UF, BIOS X556UF.406
   10/21/2016
Workqueue: rtl8723be_pci rtl_c2hcmd_wq_callback [rtlwifi]
RIP: 0010:rtl8723be_fill_h2c_cmd+0x182/0x510 [rtl8723be]
RSP: 0018:a6ab01e1bd70 EFLAGS: 00010282
RAX:  RBX: a26069071520 RCX: 0001
RDX: 8001 RSI: 8be70e9c RDI: 
RBP:  R08: 0048 R09: 0348
R10:  R11: 0001 R12: 
R13: a26069071520 R14:  R15: a2607d205f70
FS:  () GS:a26081d8() knlGS:000
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0443b39d3000 CR3: 00037700a005 CR4: 003606e0
Call Trace:
 ? halbtc_send_bt_mp_operation.constprop.17+0xd5/0xe0 [btcoexist]
 ? ex_btc8723b1ant_bt_info_notify+0x3b8/0x820 [btcoexist]
 ? rtl_c2hcmd_launcher+0xab/0x110 [rtlwifi]
 ? process_one_work+0x1d1/0x3b0
 ? worker_thread+0x2b/0x3d0
 ? process_one_work+0x3b0/0x3b0
 ? kthread+0x112/0x130
 ? kthread_create_on_node+0x60/0x60
 ? ret_from_fork+0x35/0x40
Code: 00 76 b4 e9 e2 fe ff ff 4c 89 ee 4c 89 e7 e8 56 22 86 ca e9 5e ...

This patch ensures all delayed works done before entering PS to satisfy
our expectation, so use cancel_delayed_work_sync() instead. An exception
is delayed work ips_nic_off_wq because running task may be itself, so add
a parameter ips_wq to deinit function to handle this case.

This issue is reported and fixed in below threads:
https://github.com/lwfinger/rtlwifi_new/issues/367
https://github.com/lwfinger/rtlwifi_new/issues/366

Tested-by: Evgeny Kapun  # 8723DE
Tested-by: Shivam Kakkar  # 8723BE on 4.18-rc1
Signed-off-by: Ping-Ke Shih 
---
Hi Kalle,

I'd like to queue this fix to 4.18, because kernel oops in users' laptop.

Thanks
PK

---
 drivers/net/wireless/realtek/rtlwifi/base.c | 17 ++---
 drivers/net/wireless/realtek/rtlwifi/base.h |  2 +-
 drivers/net/wireless/realtek/rtlwifi/core.c |  2 +-
 drivers/net/wireless/realtek/rtlwifi/pci.c  |  2 +-
 drivers/net/wireless/realtek/rtlwifi/ps.c   |  4 ++--
 drivers/net/wireless/realtek/rtlwifi/usb.c  |  2 +-
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 39c817eddd78..54c9f6ab0c8c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -484,18 +484,21 @@ static void _rtl_init_deferred_work(struct ieee80211_hw 
*hw)
 
 }
 
-void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
+void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
 
del_timer_sync(>works.watchdog_timer);
 
-   cancel_delayed_work(>works.watchdog_wq);
-   cancel_delayed_work(>works.ips_nic_off_wq);
-   cancel_delayed_work(>works.ps_work);
-   cancel_delayed_work(>works.ps_rfon_wq);
-   cancel_delayed_work(>works.fwevt_wq);
-   cancel_delayed_work(>works.c2hcmd_wq);
+   cancel_delayed_work_sync(>works.watchdog_wq);
+   if (ips_wq)
+   cancel_delayed_work(>works.ips_nic_off_wq);
+   else
+   cancel_delayed_work_sync(>works.ips_nic_off_wq);
+   cancel_delayed_work_sync(>works.ps_work);
+   cancel_delayed_work_sync(>works.ps_rfon_wq);
+   cancel_delayed_work_sync(>works.fwevt_wq);
+   cancel_delayed_work_sync(>works.c2hcmd_wq);
 }
 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/base.h 
b/drivers/net/wireless/realtek/rtlwifi/base.h
index 912f205779c3..a7ae40eaa3cd 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.h
+++ b/drivers/net/wireless/realtek/rtlwifi/base.h
@@ -121,7 +121,7 @@ void rtl_init_rfkill(struct ieee80211_hw *hw);
 void rtl_deinit_rfkill(struct ieee80211_hw *hw);
 
 void rtl_watch_dog_timer_callback(struct timer_list *t);
-void rtl_deinit_deferred_work(struct ieee80211_hw *hw);
+void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq);
 
 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx);
 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht,
diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c 
b/drivers/net/wireless/realtek/rtlwifi/core.c
index cfea57efa7f4..a3f46203ee7a 100644
--- 

Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-06-04 Thread Pkshih
On Thu, 2018-05-24 at 11:27 +0300, Kalle Valo wrote:
> 
> You are missing my point: I don't even have time to review huge rtlwifi
> patches when they are not even ready for upstream. I cannot start
> working on cleaning up rtlwifi code and doing multiple iterations of
> reviews on these kind of huge patchsets. Either you need to
> significantly scale down the size of patchsets (especially LOC) or you
> need to get review help from someone else. But the current way of
> working is not doable for me.
> 

Is there a proper way to look for "someone else" you mentioned?

We plan to rewrite a new driver excluding agnostic OS layer to support 
new generation 11AC chips, because they're very different from the chips
existed in rtlwifi and rtl8xxxu. 

If we have a "someone" to review our driver, where is the proper place to
put developing driver repository? Staging or public git repository 
(e.g. GitHub)?

Finally, the driver is done. Are there explicit criteria to accept the
driver as a mainline driver? 

Thanks
PK



Re: [PATCH v4 0/9] rtlwifi: btcoex: Add 8822b btcoex support

2018-05-30 Thread Pkshih
On Fri, 2018-04-13 at 14:16 +0800, pks...@realtek.com wrote:
> From: Ping-Ke Shih 
> 
> v4: swap the order of patch 4/9 and 5/9, because kbuild test robot reports
> undefined reference. No source code change.
> v3: forget to CC wireless mailing list, so resend again. No any change.
> v2: fix misspelling and boolean expression in patch 1/9
> 
> Patches 1-2 are revised by patches 12 of previous patchset. 8822b coex
> files are split into two patches, and I remove some comments and apply
> 'static const' to version related variables.
> Patches 3-4 aren't changed. (identical to patches 13-15 of previous patchset)
> Patches 6-7 remove comments and apply 'static const' to existing files.
> Patches 8-9 remove global variables, and use local variables instead.
> 
> Ping-Ke Shih (9):
>   rtlwifi: btcoex: Add 8822b1ant coex files
>   rtlwifi: btcoex: Add 8822b2ant coex files
>   rtlwifi: btcoex: Add 8822b header files to precomp.h
>   rtlwifi: btcoex: Add 8822b to Makefile
>   rtlwifi: btcoex: Add 8822b routine to btc interfaces
>   rtlwifi: btcoex: remove comments that are not meaningful
>   rtlwifi: btcoex: Add modifier const to version related variables
>   rtlwifi: btcoex: Add struct members to replace global varaibles
>   rtlwifi: btcoex: Remove global variables of chip specific context
> 

Hi Kalle,

I would like to send v5 to change the order of this patchset like:
  rtlwifi: btcoex: remove comments that are not meaningful
  rtlwifi: btcoex: Add modifier const to version related variables
  rtlwifi: btcoex: Add struct members to replace global varaibles
  rtlwifi: btcoex: Remove global variables of chip specific context

  rtlwifi: btcoex: Add 8822b1ant coex files
  rtlwifi: btcoex: Add 8822b2ant coex files
  rtlwifi: btcoex: Add 8822b header files to precomp.h
  rtlwifi: btcoex: Add 8822b to Makefile
  rtlwifi: btcoex: Add 8822b routine to btc interfaces

Then, you can review patches 1/9 - 4/9 that refine btcoex, and
the remaining 8822b's btcoex can review later.
Does it work for you?

Thanks
PK


Re: [PATCH 13/14] rtlwifi: access skb->data to get C2H data by macro

2018-05-30 Thread Pkshih
On Tue, 2018-05-29 at 08:18 +0300, Kalle Valo wrote:
>  writes:
> 
> > From: Ping-Ke Shih 
> >
> > The format of C2H data is ID(1 byte) + Length(1 byte) + value, and it is
> > more readable to use macros to access C2H data.
> >
> > Signed-off-by: Ping-Ke Shih 
> 
> [...]
> 
> > --- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
> > +++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
> > @@ -177,6 +177,11 @@ enum rtl_c2h_evt_v2 {
> >     C2H_V2_CCX_RPT = 0x0F,
> >  };
> >  
> > +#define GET_C2H_CMD_ID(c2h)({u8 *__c2h = c2h; __c2h[0]; })
> > +#define GET_C2H_SEQ(c2h)   ({u8 *__c2h = c2h; __c2h[1]; })
> > +#define C2H_DATA_OFFSET2
> > +#define GET_C2H_DATA_PTR(c2h)  ({u8 *__c2h = c2h; 
> > &__c2h[C2H_DATA_OFFSET]; })
> 
> These macros are not really pretty, a proper static inline function
> would be a much better choise. But I'm planning to apply this patch
> anyway, I don't think it's a blocker but a good idea to cleanup later.
> 
> And rtlwifi really should get away with this foo[0] and foo[1] style of
> buffers and switch to proper structs (foo->bar and foo->koo).

Thanks for your review and suggestion.

Because C2H data is little endian order, the struct will look like
struct foo {
#ifdef __LITTLE_ENDIAN
u8 bar:4;
u8 koo:4;
#else
u8 koo:4;
u8 bar:4;
#endif
}

Is this a linux convention?

Regards
PK



Re: rtl8723be signal strength loss, and possibly a OOPS/BUG

2018-05-21 Thread Pkshih
On Sat, 2018-05-19 at 20:43 +, Mattias Jernberg wrote:
> Hi
> 
> With kernel 4.16 I experience a loss in signal strength on rtl8723be,
> it is very similar to having the ant_sel parameter wrong (or missing),
> iw scan shows only my own access point next to me and with a signal
> strength of under -60 rather than above -30.
> 
> I bisected this down to 874e837d67d0db179c9771f38fd21df07c703e93 being
> the offending commit.
> 
The commit 874e837d67d0 ("rtlwifi: fill FW version and subversion") set
correct firmware version that is used by btcoex to collaborate with 
firmware properly.

> I have also seen three BUGs that might be related. They appear when
> setting ant_sel=1
> 
> * The first one occurred (both on Debians 4.16.5 kernel and on
> mainline 4.17-rc5) when I did modprobe rtl8723be ant_sel=1, after a
> modprobe -r rtl8723be.
> * The second one when booting with ant_sel=1 in /etc/modprobe.d.
> * The third one is when booting
> 874e837d67d0db179c9771f38fd21df07c703e93 and having ant_sel=1.
> 
> Correct (at least on 4.15.0) for this laptop is ant_sel=2.
> 

With ant_sel=1, it will run into ex_btc8723b1ant_bt_info_notify() of 
btcoexist/halbtc8723b1ant.c, and cause the bugs you reported.
With ant_sel=2, another function corresponding to 2ant is executed, so
there is no bug message.
I have sent a patchset to linux-wireless that will also fix this bug.
If you want to fix it locally, please try below patch based on 
commit bf516e7d8b1c ("rtlwifi: remove duplicate definition of antenna 
number for btcoex") of wireless-drivers-next tree.

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
index 4b963fd27d64..868e78870029 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
@@ -762,10 +762,10 @@ void rtl8723be_c2h_packet_handler(struct ieee80211_hw 
*hw, u8 *buffer, u8 len)
 
switch (c2h_cmd_id) {
case C2H_8723B_BT_INFO:
-   case C2H_8723B_BT_MP:
rtl_c2hcmd_enqueue(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
break;
 
+   case C2H_8723B_BT_MP:
default:
rtl8723be_c2h_content_parsing(hw, c2h_cmd_id, c2h_cmd_len,
  tmp_buf);


Regards
PK



Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-05-18 Thread Pkshih
On Wed, 2018-05-16 at 15:36 +0300, Kalle Valo wrote:
> Pkshih <pks...@realtek.com> writes:
> 
> > On Mon, 2018-04-30 at 14:03 +0530, Krishna Chaitanya wrote:
> >> On Mon, Apr 30, 2018 at 8:10 AM, Pkshih <pks...@realtek.com> wrote:
> >> >
> >> >
> >> > > -Original Message-
> >> > > From: Barry Day [mailto:brise...@gmail.com]
> >> > > Sent: Saturday, April 28, 2018 6:42 AM
> >> > > To: Pkshih
> >> > > Cc: Kalle Valo; larry.fin...@lwfinger.net; 
> >> > > linux-wireless@vger.kernel.org
> >> > > Subject: Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac
> >> > >
> >> > > On Fri, Apr 27, 2018 at 05:44:16AM +, Pkshih wrote:
> >> > > >
> >> > > > The registers reside in driver causes error frequently, because MAC 
> >> > > > register
> >> > > > is maintained by Realtek's MAC team so they create this module to 
> >> > > > avoid mistakes.
> >> > > > Another benefit is to make it possible to become a thin driver, 
> >> > > > because many
> >> > > > common functions are provided, so duplicate code will be reduced.
> >> > >
> >> > > How is it possible to create a thin driver by adding lots more code 
> >> > > and layers
> >> > > of indirection ??? and writing it in a way that it won't compile 
> >> > > without the
> >> > > code for every type of bus interface even though most modules only use 
> >> > > one ?
> >> > >
> >> > As I mentioned in first paragraph "(I use 'driver' in this mail 
> >> > indicates part of
> >> > rtlwifi excluded from this module.)". If this module was seen as a 
> >> > 'lib', rtl8822be
> >> > would be a "thin driver". For bus interface code, I need to add a way to 
> >> > compile
> >> > type of bus interface according to selected chip.
> >> >
> >> > > It's a horrible pile of garbage slapped together by an inexperienced
> >> > > programmer. Its a major deterrent for anyone looking at working on one 
> >> > > of
> >> > > the latest realtek drivers.
> >> > >
> >> > This module is designed to support multiple OS including Windows and 
> >> > Linux, and
> >> > many products have used this module and worked well. We hope Linux user 
> >> > can also
> >> > use Realtek's WiFi without additional installation if driver was built.
> >> > In order to submit this module to kernel upstream, we take a lot of 
> >> > effort
> >> > to fit Linux coding conventions (e.g. coding style), and explicit
> >> > suggestions will be helpful for us to continuously improve this module.
> >> 
> >> IMHO, this is a common use case for most organizations. I understand
> >> that Linux cannot
> >> accommodate other OSes requirements but is there an approved/recommended 
> >> way
> >> to upstream an OS agnostic driver? Agnostic drivers are generally
> >> bulkier compared to
> >> Linux-only drivers and also code organization is also different (to
> >> handle other OSes).
> >> 
> >
> > Hi Kalle,
> >
> > The state of this patchset was changed to RFC in patchwork, and I look at 
> > RFC's
> > meaning in wireless wiki. Do you expect that I will send v4?
> 
> Yes, I was expecting that you will submit v4 with proper documentation.
> I was supposed to send an email but forgot, sorry.
> 
> > If so, what do I need to fix in v4? Or, you need more description
> > about this module, please let me know. 
> 
> The biggest problem is that rtlwifi patches are way too big and which I
> don't think are ready for upstream, most of the time code quality is
> closer to the infamous "vendor drivers". This is causing me too much
> burden, even just reviewing and providing initial comments to rtlwifi
> patches take too much of my time. For example, I still haven't been able
> to check the rtlwifi btcoex patches from a month ago.
> 
> In principle I can use a minute or two per patch, anything longer than
> that and I can't keep up with the incoming patch flow. And with huge
> rtlwifi patchsets I usually need something more like an hour than few
> minutes.
> 
> I have said this also before, but more and more I'm thinking that
> rtlwifi is not really a proper upstream driver. I think staging would be
> a much better place for it and maybe a proper upstream realtek driver
> would be something based on rtl8xxxu? I dunno.
> 
> But we really need to find a solution for this as the current way with
> rtlwifi patches won't work in the long run.
> 

If we remove unused code and do proper modification (e.g. remove abstraction 
layer)
and submit to staging, but still remain the directory levels.
Will you accept halmac and submit it into upstream after being reviewed in 
staging?
Or, the only way you can accept is to remove the halmac directory and rearrange
the code and split it into the top level directory?

Regards,
PK


[PATCH 02/14] rtlwifi: remove CONNECTION_MONITOR flag

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

To use keep-alive mechanism in mac80211 stack, since driver supports
reporting accurate nullfunc frame tx ack now.

Signed-off-by: Tzu-En Huang 
Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 6620c6842b91..759a802ccbee 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -396,7 +396,6 @@ static void _rtl_init_mac80211(struct ieee80211_hw *hw)
ieee80211_hw_set(hw, SIGNAL_DBM);
ieee80211_hw_set(hw, RX_INCLUDES_FCS);
ieee80211_hw_set(hw, AMPDU_AGGREGATION);
-   ieee80211_hw_set(hw, CONNECTION_MONITOR);
ieee80211_hw_set(hw, MFP_CAPABLE);
ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
-- 
2.15.1



[PATCH 01/14] rtlwifi: support accurate nullfunc frame tx ack report

2018-05-18 Thread pkshih
From: Tzu-En Huang 

In order to realize the keep-alive mechanism in mac80211 stack, reporting
accurate tx ack status for nullfunc frame is added in this commit.

If current frame is nullfunc frame, we ask firmware to report by filling
TX report bit in TX descriptor. After this frame DMA done, TX interrupt is
triggered but TX status is unknown at this moment, so enqueue this skb
into tx_report->queue. Finally, C2H report will be received if the frame
is transmitted successfully or retried over, and then we report to mac80211
with IEEE80211_TX_STAT_ACK flag only if it's successful. Otherwise, if
failure or timeout (one second), we report to mac80211 without this flag.

Signed-off-by: Tzu-En Huang 
Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c| 84 +++---
 drivers/net/wireless/realtek/rtlwifi/base.h|  5 +-
 drivers/net/wireless/realtek/rtlwifi/pci.c | 13 ++--
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.c   |  5 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.c   |  5 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.c   |  5 +-
 drivers/net/wireless/realtek/rtlwifi/wifi.h| 16 +
 7 files changed, 112 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 762a29cdf7ad..6620c6842b91 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -574,6 +574,7 @@ int rtl_init_core(struct ieee80211_hw *hw)
INIT_LIST_HEAD(>entry_list);
INIT_LIST_HEAD(>c2hcmd_list);
INIT_LIST_HEAD(>scan_list.list);
+   skb_queue_head_init(>tx_report.queue);
 
rtlmac->link_state = MAC80211_NOLINK;
 
@@ -585,11 +586,14 @@ int rtl_init_core(struct ieee80211_hw *hw)
 EXPORT_SYMBOL_GPL(rtl_init_core);
 
 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
+static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw,
+   bool timeout);
 
 void rtl_deinit_core(struct ieee80211_hw *hw)
 {
rtl_c2hcmd_launcher(hw, 0);
rtl_free_entries_from_scan_list(hw);
+   rtl_free_entries_from_ack_queue(hw, false);
 }
 EXPORT_SYMBOL_GPL(rtl_deinit_core);
 
@@ -1575,22 +1579,52 @@ u8 rtl_is_special_data(struct ieee80211_hw *hw, struct 
sk_buff *skb, u8 is_tx,
 }
 EXPORT_SYMBOL_GPL(rtl_is_special_data);
 
+void rtl_tx_ackqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+   struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct rtl_tx_report *tx_report = >tx_report;
+
+   __skb_queue_tail(_report->queue, skb);
+}
+EXPORT_SYMBOL_GPL(rtl_tx_ackqueue);
+
+static void rtl_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
+ bool ack)
+{
+   struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct ieee80211_tx_info *info;
+
+   info = IEEE80211_SKB_CB(skb);
+   ieee80211_tx_info_clear_status(info);
+   if (ack) {
+   RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
+"tx report: ack\n");
+   info->flags |= IEEE80211_TX_STAT_ACK;
+   } else {
+   RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_LOUD,
+"tx report: not ack\n");
+   info->flags &= ~IEEE80211_TX_STAT_ACK;
+   }
+   ieee80211_tx_status_irqsafe(hw, skb);
+}
+
 bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
u16 ether_type;
const u8 *ether_type_ptr;
+   __le16 fc = rtl_get_fc(skb);
 
ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
 
-   /* EAPOL */
-   if (ether_type == ETH_P_PAE)
+   if (ether_type == ETH_P_PAE || ieee80211_is_nullfunc(fc))
return true;
 
return false;
 }
 
-static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
+static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw,
+   struct rtlwifi_tx_info *tx_info)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_tx_report *tx_report = >tx_report;
@@ -1604,29 +1638,33 @@ static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
 
tx_report->last_sent_sn = sn;
tx_report->last_sent_time = jiffies;
-
+   tx_info->sn = sn;
+   tx_info->send_time = tx_report->last_sent_time;
RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
 "Send TX-Report sn=0x%X\n", sn);
 
return sn;
 }
 
-void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
-  struct ieee80211_hw *hw)
+void rtl_set_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
+  struct ieee80211_hw *hw, struct rtlwifi_tx_info *tx_info)
 {
if (ptcb_desc->use_spe_rpt) {
-   u16 sn = rtl_get_tx_report_sn(hw);
+   u16 sn 

[PATCH 07/14] rtlwifi: remove dummy hal_op rx_command_packet from rtl8188ee and rtl8723ae

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

The caller of hal_op rx_command_packet will assert function pointer
before calling, so we can remove dummy functions safely.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c  | 2 --
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 7 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.h | 4 
 drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c  | 1 -
 drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c | 7 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.h | 3 ---
 6 files changed, 24 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
index 82681b96ef93..8c15ffd3568b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
@@ -263,8 +263,6 @@ static struct rtl_hal_ops rtl8188ee_hal_ops = {
.get_rfreg = rtl88e_phy_query_rf_reg,
.set_rfreg = rtl88e_phy_set_rf_reg,
.get_btc_status = rtl88e_get_btc_status,
-   .rx_command_packet = rtl88ee_rx_command_packet,
-
 };
 
 static struct rtl_mod_params rtl88ee_mod_params = {
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c
index 9670732b2bc6..4c1f8b08fc10 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c
@@ -850,10 +850,3 @@ void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 
hw_queue)
   BIT(0) << (hw_queue));
}
 }
-
-u32 rtl88ee_rx_command_packet(struct ieee80211_hw *hw,
- const struct rtl_stats *status,
- struct sk_buff *skb)
-{
-   return 0;
-}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.h
index f902d6769aa8..127ba977206f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.h
@@ -790,8 +790,4 @@ void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 
hw_queue);
 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
 bool firstseg, bool lastseg,
 struct sk_buff *skb);
-u32 rtl88ee_rx_command_packet(struct ieee80211_hw *hw,
- const struct rtl_stats *status,
- struct sk_buff *skb);
-
 #endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
index a545ea317323..07b82700d1de 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
@@ -260,7 +260,6 @@ static struct rtl_hal_ops rtl8723e_hal_ops = {
.bt_coex_off_before_lps =
rtl8723e_dm_bt_turn_off_bt_coexist_before_enter_lps,
.get_btc_status = rtl8723e_get_btc_status,
-   .rx_command_packet = rtl8723e_rx_command_packet,
.is_fw_header = is_fw_header,
 };
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c
index 23485602a9a1..d461d0c9631f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.c
@@ -709,10 +709,3 @@ void rtl8723e_tx_polling(struct ieee80211_hw *hw, u8 
hw_queue)
   BIT(0) << (hw_queue));
}
 }
-
-u32 rtl8723e_rx_command_packet(struct ieee80211_hw *hw,
-  const struct rtl_stats *status,
-  struct sk_buff *skb)
-{
-   return 0;
-}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.h
index 985ce0b77ea5..d592b08d4ac8 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/trx.h
@@ -716,7 +716,4 @@ void rtl8723e_tx_polling(struct ieee80211_hw *hw, u8 
hw_queue);
 void rtl8723e_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
  bool firstseg, bool lastseg,
  struct sk_buff *skb);
-u32 rtl8723e_rx_command_packet(struct ieee80211_hw *hw,
-  const struct rtl_stats *status,
-  struct sk_buff *skb);
 #endif
-- 
2.15.1



[PATCH 09/14] rtlwifi: remove duplicate C2H handler

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Merge duplicate C2H handler and implement the handler in base.c.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c| 72 +
 drivers/net/wireless/realtek/rtlwifi/base.h|  3 +
 .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.c| 75 --
 .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.h|  3 -
 .../net/wireless/realtek/rtlwifi/rtl8192ee/sw.c|  2 +-
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.c   |  2 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/fw.c| 69 
 .../net/wireless/realtek/rtlwifi/rtl8723be/fw.h|  3 -
 .../net/wireless/realtek/rtlwifi/rtl8723be/sw.c|  2 +-
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.c   |  3 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.c| 68 
 .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.h|  5 --
 .../net/wireless/realtek/rtlwifi/rtl8821ae/sw.c|  2 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.c   |  2 +-
 14 files changed, 81 insertions(+), 230 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 759a802ccbee..0d03e98f9cb4 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -2306,6 +2306,78 @@ void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, 
u8 len, u8 *val)
 }
 EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
 
+void rtl_c2h_content_parsing(struct ieee80211_hw *hw, u8 cmd_id,
+u8 cmd_len, u8 *cmd_buf)
+{
+   struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
+   const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
+
+   switch (cmd_id) {
+   case C2H_DBG:
+   RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "[C2H], C2H_DBG!!\n");
+   break;
+   case C2H_TXBF:
+   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
+"[C2H], C2H_TXBF!!\n");
+   break;
+   case C2H_TX_REPORT:
+   rtl_tx_report_handler(hw, cmd_buf, cmd_len);
+   break;
+   case C2H_RA_RPT:
+   if (hal_ops->c2h_ra_report_handler)
+   hal_ops->c2h_ra_report_handler(hw, cmd_buf, cmd_len);
+   break;
+   case C2H_BT_INFO:
+   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
+"[C2H], C2H_BT_INFO!!\n");
+   if (rtlpriv->cfg->ops->get_btc_status())
+   btc_ops->btc_btinfo_notify(rtlpriv, cmd_buf, cmd_len);
+   break;
+   case C2H_BT_MP:
+   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
+"[C2H], C2H_BT_MP!!\n");
+   if (rtlpriv->cfg->ops->get_btc_status())
+   btc_ops->btc_btmpinfo_notify(rtlpriv, cmd_buf, cmd_len);
+   break;
+   default:
+   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
+"[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id);
+   break;
+   }
+}
+EXPORT_SYMBOL_GPL(rtl_c2h_content_parsing);
+
+void rtl_c2h_packet_handler(struct ieee80211_hw *hw, u8 *buffer, u8 len)
+{
+   struct rtl_priv *rtlpriv = rtl_priv(hw);
+   u8 c2h_cmd_id = 0, c2h_cmd_seq = 0, c2h_cmd_len = 0;
+   u8 *tmp_buf = NULL;
+
+   c2h_cmd_id = buffer[0];
+   c2h_cmd_seq = buffer[1];
+   c2h_cmd_len = len - 2;
+   tmp_buf = buffer + 2;
+
+   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
+"[C2H packet], c2hCmdId=0x%x, c2hCmdSeq=0x%x, c2hCmdLen=%d\n",
+c2h_cmd_id, c2h_cmd_seq, c2h_cmd_len);
+
+   RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_TRACE,
+ "[C2H packet], Content Hex:\n", tmp_buf, c2h_cmd_len);
+
+   switch (c2h_cmd_id) {
+   case C2H_BT_INFO:
+   case C2H_BT_MP:
+   rtl_c2hcmd_enqueue(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
+   break;
+   default:
+   rtl_c2h_content_parsing(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
+   break;
+   }
+}
+EXPORT_SYMBOL_GPL(rtl_c2h_packet_handler);
+
 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
diff --git a/drivers/net/wireless/realtek/rtlwifi/base.h 
b/drivers/net/wireless/realtek/rtlwifi/base.h
index 19e7477839e4..3bf174e5b07e 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.h
+++ b/drivers/net/wireless/realtek/rtlwifi/base.h
@@ -162,6 +162,9 @@ void rtl_fwevt_wq_callback(void *data);
 void rtl_c2hcmd_wq_callback(void *data);
 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec);
 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val);
+void rtl_c2h_content_parsing(struct ieee80211_hw *hw, u8 c2h_cmd_id,
+u8 c2h_cmd_len, u8 *tmp_buf);
+void rtl_c2h_packet_handler(struct ieee80211_hw 

[PATCH 10/14] rtlwifi: remove hal_op rx_command_packet

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Because the hal_op rx_command_packet does C2H handler if rx packet type
is C2H, and the handler have been moved to base.c so we can call the
handler directly.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/pci.c |  4 ++--
 .../net/wireless/realtek/rtlwifi/rtl8192ee/sw.c|  1 -
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.c   | 24 
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.h   |  3 ---
 .../net/wireless/realtek/rtlwifi/rtl8723be/sw.c|  1 -
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.c   | 24 
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.h   |  3 ---
 .../net/wireless/realtek/rtlwifi/rtl8821ae/sw.c|  1 -
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.c   | 26 --
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.h   |  3 ---
 drivers/net/wireless/realtek/rtlwifi/wifi.h|  2 --
 11 files changed, 2 insertions(+), 90 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/pci.c 
b/drivers/net/wireless/realtek/rtlwifi/pci.c
index d0c509ef790e..dd51c67c09fa 100644
--- a/drivers/net/wireless/realtek/rtlwifi/pci.c
+++ b/drivers/net/wireless/realtek/rtlwifi/pci.c
@@ -830,8 +830,8 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
goto new_trx_end;
}
/* handle command packet here */
-   if (rtlpriv->cfg->ops->rx_command_packet &&
-   rtlpriv->cfg->ops->rx_command_packet(hw, , skb)) {
+   if (stats.packet_report_type == C2H_PACKET) {
+   rtl_c2h_packet_handler(hw, skb->data, (u8)skb->len);
dev_kfree_skb_any(skb);
goto new_trx_end;
}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
index fd028274c593..5b67ad748d67 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
@@ -250,7 +250,6 @@ static struct rtl_hal_ops rtl8192ee_hal_ops = {
.set_rfreg = rtl92ee_phy_set_rf_reg,
.fill_h2c_cmd = rtl92ee_fill_h2c_cmd,
.get_btc_status = rtl92ee_get_btc_status,
-   .rx_command_packet = rtl92ee_rx_command_packet,
.c2h_content_parsing = rtl_c2h_content_parsing,
.c2h_ra_report_handler = rtl92ee_c2h_ra_report_handler,
 };
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c
index e525c2bb4457..14d6e3fc5767 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.c
@@ -1072,27 +1072,3 @@ bool rtl92ee_is_tx_desc_closed(struct ieee80211_hw *hw, 
u8 hw_queue, u16 index)
 void rtl92ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
 {
 }
-
-u32 rtl92ee_rx_command_packet(struct ieee80211_hw *hw,
- const struct rtl_stats *status,
- struct sk_buff *skb)
-{
-   u32 result = 0;
-   struct rtl_priv *rtlpriv = rtl_priv(hw);
-
-   switch (status->packet_report_type) {
-   case NORMAL_RX:
-   result = 0;
-   break;
-   case C2H_PACKET:
-   rtl_c2h_packet_handler(hw, skb->data, (u8)skb->len);
-   result = 1;
-   break;
-   default:
-   RT_TRACE(rtlpriv, COMP_RECV, DBG_TRACE,
-"Unknown packet type %d\n", 
status->packet_report_type);
-   break;
-   }
-
-   return result;
-}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.h
index 48c16fff20c6..45df3e79f490 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/trx.h
@@ -762,7 +762,4 @@ void rtl92ee_tx_polling(struct ieee80211_hw *hw, u8 
hw_queue);
 void rtl92ee_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
 bool firstseg, bool lastseg,
 struct sk_buff *skb);
-u32 rtl92ee_rx_command_packet(struct ieee80211_hw *hw,
- const struct rtl_stats *status,
- struct sk_buff *skb);
 #endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
index 9df994965c4a..a41e67b3f38b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
@@ -261,7 +261,6 @@ static struct rtl_hal_ops rtl8723be_hal_ops = {
.set_rfreg = rtl8723be_phy_set_rf_reg,
.fill_h2c_cmd = rtl8723be_fill_h2c_cmd,
.get_btc_status = rtl8723be_get_btc_status,
-   .rx_command_packet = rtl8723be_rx_command_packet,
.is_fw_header = is_fw_header,

[PATCH 06/14] rtlwifi: remove unused fw C2H command ID

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

The IDs are defined by driver and map to the fw C2H IDs, but they aren't
used now result in removal.

Signed-off-by: Ping-Ke Shih 
---
 .../net/wireless/realtek/rtlwifi/rtl8188ee/def.h   | 25 --
 .../net/wireless/realtek/rtlwifi/rtl8192ce/def.h   | 25 --
 .../net/wireless/realtek/rtlwifi/rtl8723ae/def.h   | 25 --
 .../net/wireless/realtek/rtlwifi/rtl8821ae/def.h   | 25 --
 4 files changed, 100 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
index 32492d64d685..45c866d3ca88 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
@@ -176,31 +176,6 @@ enum interface_select_pci {
INTF_SEL3_RSV = 3,
 };
 
-enum hal_fw_c2h_cmd_id {
-   HAL_FW_C2H_CMD_READ_MACREG = 0,
-   HAL_FW_C2H_CMD_READ_BBREG = 1,
-   HAL_FW_C2H_CMD_READ_RFREG = 2,
-   HAL_FW_C2H_CMD_READ_EEPROM = 3,
-   HAL_FW_C2H_CMD_READ_EFUSE = 4,
-   HAL_FW_C2H_CMD_READ_CAM = 5,
-   HAL_FW_C2H_CMD_GET_BASICRATE = 6,
-   HAL_FW_C2H_CMD_GET_DATARATE = 7,
-   HAL_FW_C2H_CMD_SURVEY = 8,
-   HAL_FW_C2H_CMD_SURVEYDONE = 9,
-   HAL_FW_C2H_CMD_JOINBSS = 10,
-   HAL_FW_C2H_CMD_ADDSTA = 11,
-   HAL_FW_C2H_CMD_DELSTA = 12,
-   HAL_FW_C2H_CMD_ATIMDONE = 13,
-   HAL_FW_C2H_CMD_TX_REPORT = 14,
-   HAL_FW_C2H_CMD_CCX_REPORT = 15,
-   HAL_FW_C2H_CMD_DTM_REPORT = 16,
-   HAL_FW_C2H_CMD_TX_RATE_STATISTICS = 17,
-   HAL_FW_C2H_CMD_C2HLBK = 18,
-   HAL_FW_C2H_CMD_C2HDBG = 19,
-   HAL_FW_C2H_CMD_C2HFEEDBACK = 20,
-   HAL_FW_C2H_CMD_MAX
-};
-
 enum rtl_desc_qsel {
QSLT_BK = 0x2,
QSLT_BE = 0x0,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/def.h
index b90aaf128072..d2005d7e9ad2 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/def.h
@@ -142,31 +142,6 @@ enum interface_select_pci {
INTF_SEL3_RSV = 3,
 };
 
-enum hal_fw_c2h_cmd_id {
-   HAL_FW_C2H_CMD_Read_MACREG = 0,
-   HAL_FW_C2H_CMD_Read_BBREG = 1,
-   HAL_FW_C2H_CMD_Read_RFREG = 2,
-   HAL_FW_C2H_CMD_Read_EEPROM = 3,
-   HAL_FW_C2H_CMD_Read_EFUSE = 4,
-   HAL_FW_C2H_CMD_Read_CAM = 5,
-   HAL_FW_C2H_CMD_Get_BasicRate = 6,
-   HAL_FW_C2H_CMD_Get_DataRate = 7,
-   HAL_FW_C2H_CMD_Survey = 8,
-   HAL_FW_C2H_CMD_SurveyDone = 9,
-   HAL_FW_C2H_CMD_JoinBss = 10,
-   HAL_FW_C2H_CMD_AddSTA = 11,
-   HAL_FW_C2H_CMD_DelSTA = 12,
-   HAL_FW_C2H_CMD_AtimDone = 13,
-   HAL_FW_C2H_CMD_TX_Report = 14,
-   HAL_FW_C2H_CMD_CCX_Report = 15,
-   HAL_FW_C2H_CMD_DTM_Report = 16,
-   HAL_FW_C2H_CMD_TX_Rate_Statistics = 17,
-   HAL_FW_C2H_CMD_C2HLBK = 18,
-   HAL_FW_C2H_CMD_C2HDBG = 19,
-   HAL_FW_C2H_CMD_C2HFEEDBACK = 20,
-   HAL_FW_C2H_CMD_MAX
-};
-
 enum rtl_desc_qsel {
QSLT_BK = 0x2,
QSLT_BE = 0x0,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/def.h
index bcdf2273688e..847544817549 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/def.h
@@ -152,31 +152,6 @@ enum interface_select_pci {
INTF_SEL3_RSV = 3,
 };
 
-enum hal_fw_c2h_cmd_id {
-   HAL_FW_C2H_CMD_Read_MACREG = 0,
-   HAL_FW_C2H_CMD_Read_BBREG = 1,
-   HAL_FW_C2H_CMD_Read_RFREG = 2,
-   HAL_FW_C2H_CMD_Read_EEPROM = 3,
-   HAL_FW_C2H_CMD_Read_EFUSE = 4,
-   HAL_FW_C2H_CMD_Read_CAM = 5,
-   HAL_FW_C2H_CMD_Get_BasicRate = 6,
-   HAL_FW_C2H_CMD_Get_DataRate = 7,
-   HAL_FW_C2H_CMD_Survey = 8,
-   HAL_FW_C2H_CMD_SurveyDone = 9,
-   HAL_FW_C2H_CMD_JoinBss = 10,
-   HAL_FW_C2H_CMD_AddSTA = 11,
-   HAL_FW_C2H_CMD_DelSTA = 12,
-   HAL_FW_C2H_CMD_AtimDone = 13,
-   HAL_FW_C2H_CMD_TX_Report = 14,
-   HAL_FW_C2H_CMD_CCX_Report = 15,
-   HAL_FW_C2H_CMD_DTM_Report = 16,
-   HAL_FW_C2H_CMD_TX_Rate_Statistics = 17,
-   HAL_FW_C2H_CMD_C2HLBK = 18,
-   HAL_FW_C2H_CMD_C2HDBG = 19,
-   HAL_FW_C2H_CMD_C2HFEEDBACK = 20,
-   HAL_FW_C2H_CMD_MAX
-};
-
 enum rtl_desc_qsel {
QSLT_BK = 0x2,
QSLT_BE = 0x0,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
index 498f716bfc73..3fe3aaa5fe3c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
@@ -296,31 +296,6 @@ enum interface_select_pci {
INTF_SEL3_RSV = 3,
 };
 
-enum hal_fw_c2h_cmd_id {
-   HAL_FW_C2H_CMD_READ_MACREG = 0,
-   HAL_FW_C2H_CMD_READ_BBREG = 1,
-   HAL_FW_C2H_CMD_READ_RFREG = 2,
-   

[PATCH 08/14] rtlwifi: Add hal_op c2h_ra_report_handler for special process

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

We're going to merge C2H handler into one, but one special case is to
handle RA_REPORT that implements in individual IC folder. So this commit
adds a hal_op for caller in common code.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c | 7 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h | 2 ++
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 1 +
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c | 5 +++--
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.h | 2 ++
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 1 +
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 2 ++
 7 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
index 25d6c32f66c3..a2d9e217bc65 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
@@ -876,8 +876,8 @@ void rtl92ee_set_p2p_ps_offload_cmd(struct ieee80211_hw 
*hw, u8 p2p_ps_state)
 (u8 *)p2p_ps_offload);
 }
 
-static void _rtl92ee_c2h_ra_report_handler(struct ieee80211_hw *hw,
-  u8 *cmd_buf, u8 cmd_len)
+void rtl92ee_c2h_ra_report_handler(struct ieee80211_hw *hw,
+  u8 *cmd_buf, u8 cmd_len)
 {
u8 rate = cmd_buf[0] & 0x3F;
bool collision_state = cmd_buf[3] & BIT(0);
@@ -889,6 +889,7 @@ void rtl92ee_c2h_content_parsing(struct ieee80211_hw *hw, 
u8 c2h_cmd_id,
 u8 c2h_cmd_len, u8 *tmp_buf)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
 
switch (c2h_cmd_id) {
@@ -920,7 +921,7 @@ void rtl92ee_c2h_content_parsing(struct ieee80211_hw *hw, 
u8 c2h_cmd_id,
 c2h_cmd_len);
break;
case C2H_RA_RPT:
-   _rtl92ee_c2h_ra_report_handler(hw, tmp_buf, c2h_cmd_len);
+   hal_ops->c2h_ra_report_handler(hw, tmp_buf, c2h_cmd_len);
break;
default:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
index 8325adaa9663..e5fae0a86a27 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
@@ -182,4 +182,6 @@ void rtl92ee_set_p2p_ps_offload_cmd(struct ieee80211_hw 
*hw, u8 p2p_ps_state);
 void rtl92ee_c2h_packet_handler(struct ieee80211_hw *hw, u8 *buffer, u8 len);
 void rtl92ee_c2h_content_parsing(struct ieee80211_hw *hw, u8 c2h_cmd_id,
 u8 c2h_cmd_len, u8 *tmp_buf);
+void rtl92ee_c2h_ra_report_handler(struct ieee80211_hw *hw,
+  u8 *cmd_buf, u8 cmd_len);
 #endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
index ef92a789871d..c5c26b537cd2 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
@@ -252,6 +252,7 @@ static struct rtl_hal_ops rtl8192ee_hal_ops = {
.get_btc_status = rtl92ee_get_btc_status,
.rx_command_packet = rtl92ee_rx_command_packet,
.c2h_content_parsing = rtl92ee_c2h_content_parsing,
+   .c2h_ra_report_handler = rtl92ee_c2h_ra_report_handler,
 };
 
 static struct rtl_mod_params rtl92ee_mod_params = {
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c
index 5c7e58fbc07e..bf37c428c682 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c
@@ -1907,7 +1907,7 @@ void rtl8821ae_set_p2p_ps_offload_cmd(struct ieee80211_hw 
*hw, u8 p2p_ps_state)
H2C_8821AE_P2P_PS_OFFLOAD, 1, (u8 *)p2p_ps_offload);
 }
 
-static void rtl8821ae_c2h_ra_report_handler(struct ieee80211_hw *hw,
+void rtl8821ae_c2h_ra_report_handler(struct ieee80211_hw *hw,
 u8 *cmd_buf, u8 cmd_len)
 {
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
@@ -1923,6 +1923,7 @@ void rtl8821ae_c2h_content_parsing(struct ieee80211_hw 
*hw,
   u8 *tmp_buf)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
 
switch (c2h_cmd_id) {
@@ -1933,7 +1934,7 @@ void rtl8821ae_c2h_content_parsing(struct ieee80211_hw 
*hw,
rtl_tx_report_handler(hw, tmp_buf, c2h_cmd_len);
break;
case C2H_RA_RPT:
-   

[PATCH 05/14] rtlwifi: remove duplicate C2H definition

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Move C2H definition to wifi.h, because the definitions of 8192ee, 8723be
and 8821ae are the same.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c | 16 
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h | 11 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c | 12 ++--
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.h | 10 --
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.c | 12 ++--
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/fw.h | 14 --
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 19 +++
 7 files changed, 39 insertions(+), 55 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
index f9563ae301ad..25d6c32f66c3 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.c
@@ -892,34 +892,34 @@ void rtl92ee_c2h_content_parsing(struct ieee80211_hw *hw, 
u8 c2h_cmd_id,
struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
 
switch (c2h_cmd_id) {
-   case C2H_8192E_DBG:
+   case C2H_DBG:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8723BE_DBG!!\n");
break;
-   case C2H_8192E_TXBF:
+   case C2H_TXBF:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8192E_TXBF!!\n");
break;
-   case C2H_8192E_TX_REPORT:
+   case C2H_TX_REPORT:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE ,
 "[C2H], C2H_8723BE_TX_REPORT!\n");
rtl_tx_report_handler(hw, tmp_buf, c2h_cmd_len);
break;
-   case C2H_8192E_BT_INFO:
+   case C2H_BT_INFO:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8723BE_BT_INFO!!\n");
if (rtlpriv->cfg->ops->get_btc_status())
btc_ops->btc_btinfo_notify(rtlpriv, tmp_buf,
   c2h_cmd_len);
break;
-   case C2H_8192E_BT_MP:
+   case C2H_BT_MP:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8723BE_BT_MP!!\n");
if (rtlpriv->cfg->ops->get_btc_status())
btc_ops->btc_btmpinfo_notify(rtlpriv, tmp_buf,
 c2h_cmd_len);
break;
-   case C2H_8192E_RA_RPT:
+   case C2H_RA_RPT:
_rtl92ee_c2h_ra_report_handler(hw, tmp_buf, c2h_cmd_len);
break;
default:
@@ -948,8 +948,8 @@ void rtl92ee_c2h_packet_handler(struct ieee80211_hw *hw, u8 
*buffer, u8 len)
  "[C2H packet], Content Hex:\n", tmp_buf, c2h_cmd_len);
 
switch (c2h_cmd_id) {
-   case C2H_8192E_BT_INFO:
-   case C2H_8192E_BT_MP:
+   case C2H_BT_INFO:
+   case C2H_BT_MP:
rtl_c2hcmd_enqueue(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
break;
default:
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
index b770f722daa6..8325adaa9663 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/fw.h
@@ -128,17 +128,6 @@ enum rtl8192e_h2c_cmd {
MAX_92E_H2CCMD
 };
 
-enum rtl8192e_c2h_evt {
-   C2H_8192E_DBG = 0,
-   C2H_8192E_LB = 1,
-   C2H_8192E_TXBF = 2,
-   C2H_8192E_TX_REPORT = 3,
-   C2H_8192E_BT_INFO = 9,
-   C2H_8192E_BT_MP = 11,
-   C2H_8192E_RA_RPT = 12,
-   MAX_8192E_C2HEVENT
-};
-
 #define pagenum_128(_len)  \
(u32)(((_len) >> 7) + ((_len) & 0x7F ? 1 : 0))
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
index 4b963fd27d64..34703b9cf5e8 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/fw.c
@@ -712,23 +712,23 @@ void rtl8723be_c2h_content_parsing(struct ieee80211_hw 
*hw,
struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
 
switch (c2h_cmd_id) {
-   case C2H_8723B_DBG:
+   case C2H_DBG:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8723BE_DBG!!\n");
break;
-   case C2H_8723B_TX_REPORT:
+   case C2H_TX_REPORT:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], C2H_8723BE_TX_REPORT!\n");
rtl_tx_report_handler(hw, tmp_buf, c2h_cmd_len);
break;
-   case C2H_8723B_BT_INFO:
+   case C2H_BT_INFO:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
 "[C2H], 

[PATCH 11/14] rtlwifi: remove hal_op c2h_content_parsing

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Similar to rx_command_packet, we can call rtl_c2h_content_parsing so the
hal_op isn't necessary.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 7 +++
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c | 1 -
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c | 1 -
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c | 1 -
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 2 --
 5 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 0d03e98f9cb4..927b7d231576 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -2346,7 +2346,6 @@ void rtl_c2h_content_parsing(struct ieee80211_hw *hw, u8 
cmd_id,
break;
}
 }
-EXPORT_SYMBOL_GPL(rtl_c2h_content_parsing);
 
 void rtl_c2h_packet_handler(struct ieee80211_hw *hw, u8 *buffer, u8 len)
 {
@@ -2401,9 +2400,9 @@ void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int 
exec)
if (!c2hcmd)
break;
 
-   if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
-   rtlpriv->cfg->ops->c2h_content_parsing(hw,
-   c2hcmd->tag, c2hcmd->len, c2hcmd->val);
+   if (exec)
+   rtl_c2h_content_parsing(hw, c2hcmd->tag,
+   c2hcmd->len, c2hcmd->val);
 
/* free */
kfree(c2hcmd->val);
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
index 5b67ad748d67..9ea62599ecbb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
@@ -250,7 +250,6 @@ static struct rtl_hal_ops rtl8192ee_hal_ops = {
.set_rfreg = rtl92ee_phy_set_rf_reg,
.fill_h2c_cmd = rtl92ee_fill_h2c_cmd,
.get_btc_status = rtl92ee_get_btc_status,
-   .c2h_content_parsing = rtl_c2h_content_parsing,
.c2h_ra_report_handler = rtl92ee_c2h_ra_report_handler,
 };
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
index a41e67b3f38b..c9f7b042d9c6 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
@@ -262,7 +262,6 @@ static struct rtl_hal_ops rtl8723be_hal_ops = {
.fill_h2c_cmd = rtl8723be_fill_h2c_cmd,
.get_btc_status = rtl8723be_get_btc_status,
.is_fw_header = is_fw_header,
-   .c2h_content_parsing = rtl_c2h_content_parsing,
 };
 
 static struct rtl_mod_params rtl8723be_mod_params = {
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
index 8ff8a406db52..77f6401021c9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
@@ -303,7 +303,6 @@ static struct rtl_hal_ops rtl8821ae_hal_ops = {
.set_rfreg = rtl8821ae_phy_set_rf_reg,
.fill_h2c_cmd = rtl8821ae_fill_h2c_cmd,
.get_btc_status = rtl8821ae_get_btc_status,
-   .c2h_content_parsing = rtl_c2h_content_parsing,
.c2h_ra_report_handler = rtl8821ae_c2h_ra_report_handler,
.add_wowlan_pattern = rtl8821ae_add_wowlan_pattern,
 };
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index b40d8f5bbdce..930e1ec2280f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2344,8 +2344,6 @@ struct rtl_hal_ops {
   struct rtl_wow_pattern *rtl_pattern,
   u8 index);
u16 (*get_available_desc)(struct ieee80211_hw *hw, u8 q_idx);
-   void (*c2h_content_parsing)(struct ieee80211_hw *hw, u8 tag, u8 len,
-   u8 *val);
void (*c2h_ra_report_handler)(struct ieee80211_hw *hw,
  u8 *cmd_buf, u8 cmd_len);
 };
-- 
2.15.1



[PATCH 00/14] rtlwifi: remove duplicate C2H handlers

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

The goal of patch 1/14 and 2/14 is to use keep-alive mechanism in mac80211
stack that needs accurate TX ack status for null frame reported by firmware
through C2H.
The remaining patches are step by step to remove duplicate C2H handlers
that widely distributed in IC specific files. An example of calling flow
before this patchset is:
_rtl_pci_rx_interrupt() -> 
rtlpriv->cfg->ops->rx_command_packet() =
rtl8723be_rx_command_packet() -->
rtl8723be_c2h_packet_handler() -->
case 1: rtl_c2hcmd_enqueue()
case 2: rtl8723be_c2h_content_parsing()

if case 1:
rtl_c2hcmd_launcher() ->
rtlpriv->cfg->ops->c2h_content_parsing() =
rtl8723be_c2h_content_parsing()

This patchset remove two ops:
rtlpriv->cfg->ops->rx_command_packet()
rtlpriv->cfg->ops->c2h_content_parsing()

But a special C2H is still existing, so add one op for RA report:
rtlpriv->cfg->ops->c2h_ra_report_handler()

Finally, calling flow becomes:
_rtl_pci_rx_interrupt() -->
rtl_c2hcmd_enqueue() -->
case 1: enqueue
case 2: rtl_c2h_content_parsing() if fast_cmd

if case 1:
rtl_c2hcmd_launcher() ->
rtl_c2h_content_parsing() ->
hal_ops->c2h_ra_report_handler() =
rtl8821ae_c2h_ra_report_handler() if C2H_RA_RPT


Ping-Ke Shih (13):
  rtlwifi: remove CONNECTION_MONITOR flag
  rtlwifi: remove duplicate rx_packet_type definition
  rtlwifi: rename register-based C2H command IDs to V0
  rtlwifi: remove duplicate C2H definition
  rtlwifi: remove unused fw C2H command ID
  rtlwifi: remove dummy hal_op rx_command_packet from rtl8188ee and
rtl8723ae
  rtlwifi: Add hal_op c2h_ra_report_handler for special process
  rtlwifi: remove duplicate C2H handler
  rtlwifi: remove hal_op rx_command_packet
  rtlwifi: remove hal_op c2h_content_parsing
  rtlwifi: use sk_buff to queue C2H commands
  rtlwifi: access skb->data to get C2H data by macro
  rtlwifi: fix btmpinfo timeout while processing C2H_BT_INFO

Tzu-En Huang (1):
  rtlwifi: support accurate nullfunc frame tx ack report

 drivers/net/wireless/realtek/rtlwifi/base.c| 208 -
 drivers/net/wireless/realtek/rtlwifi/base.h|   7 +-
 drivers/net/wireless/realtek/rtlwifi/pci.c |  18 +-
 .../net/wireless/realtek/rtlwifi/rtl8188ee/def.h   |  32 
 .../net/wireless/realtek/rtlwifi/rtl8188ee/sw.c|   2 -
 .../net/wireless/realtek/rtlwifi/rtl8188ee/trx.c   |   7 -
 .../net/wireless/realtek/rtlwifi/rtl8188ee/trx.h   |   4 -
 .../net/wireless/realtek/rtlwifi/rtl8192ce/def.h   |  25 ---
 .../net/wireless/realtek/rtlwifi/rtl8192ee/def.h   |   8 -
 .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.c|  78 +---
 .../net/wireless/realtek/rtlwifi/rtl8192ee/fw.h|  16 +-
 .../net/wireless/realtek/rtlwifi/rtl8192ee/sw.c|   3 +-
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.c   |  29 +--
 .../net/wireless/realtek/rtlwifi/rtl8192ee/trx.h   |   3 -
 .../net/wireless/realtek/rtlwifi/rtl8723ae/def.h   |  25 ---
 .../wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c   |   6 +-
 .../wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h   |  20 +-
 .../net/wireless/realtek/rtlwifi/rtl8723ae/sw.c|   1 -
 .../net/wireless/realtek/rtlwifi/rtl8723ae/trx.c   |   7 -
 .../net/wireless/realtek/rtlwifi/rtl8723ae/trx.h   |   3 -
 .../net/wireless/realtek/rtlwifi/rtl8723be/def.h   |   8 -
 .../net/wireless/realtek/rtlwifi/rtl8723be/fw.c|  69 ---
 .../net/wireless/realtek/rtlwifi/rtl8723be/fw.h|  13 --
 .../net/wireless/realtek/rtlwifi/rtl8723be/sw.c|   2 -
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.c   |  30 +--
 .../net/wireless/realtek/rtlwifi/rtl8723be/trx.h   |   3 -
 .../net/wireless/realtek/rtlwifi/rtl8821ae/def.h   |  33 
 .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.c|  69 +--
 .../net/wireless/realtek/rtlwifi/rtl8821ae/fw.h|  21 +--
 .../net/wireless/realtek/rtlwifi/rtl8821ae/sw.c|   3 +-
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.c   |  31 +--
 .../net/wireless/realtek/rtlwifi/rtl8821ae/trx.h   |   3 -
 drivers/net/wireless/realtek/rtlwifi/wifi.h|  56 +-
 33 files changed, 254 insertions(+), 589 deletions(-)

-- 
2.15.1



[PATCH 12/14] rtlwifi: use sk_buff to queue C2H commands

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

We use 'struct rtl_c2hcmd' to store C2H commands originally, and the code
is slightly complex to enqueue and dequeue and also wastes time to
allocate and memcpy data. Since C2H commands are asynchronous events,
they can be processed in work queue, so RX ISR enqueues C2H result in
removal of rtl_c2h_packet_handler().

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 96 +++--
 drivers/net/wireless/realtek/rtlwifi/base.h |  5 +-
 drivers/net/wireless/realtek/rtlwifi/pci.c  |  3 +-
 drivers/net/wireless/realtek/rtlwifi/wifi.h |  2 +-
 4 files changed, 25 insertions(+), 81 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 927b7d231576..61f12f86fcd4 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -571,9 +571,9 @@ int rtl_init_core(struct ieee80211_hw *hw)
spin_lock_init(>locks.iqk_lock);
/* <5> init list */
INIT_LIST_HEAD(>entry_list);
-   INIT_LIST_HEAD(>c2hcmd_list);
INIT_LIST_HEAD(>scan_list.list);
skb_queue_head_init(>tx_report.queue);
+   skb_queue_head_init(>c2hcmd_queue);
 
rtlmac->link_state = MAC80211_NOLINK;
 
@@ -2262,56 +2262,36 @@ void rtl_fwevt_wq_callback(void *data)
rtlpriv->cfg->ops->c2h_command_handle(hw);
 }
 
-void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
+void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
unsigned long flags;
-   struct rtl_c2hcmd *c2hcmd;
-
-   c2hcmd = kmalloc(sizeof(*c2hcmd),
-in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
-
-   if (!c2hcmd)
-   goto label_err;
-
-   c2hcmd->val = kmalloc(len,
- in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
-
-   if (!c2hcmd->val)
-   goto label_err2;
-
-   /* fill data */
-   c2hcmd->tag = tag;
-   c2hcmd->len = len;
-   memcpy(c2hcmd->val, val, len);
 
/* enqueue */
spin_lock_irqsave(>locks.c2hcmd_lock, flags);
 
-   list_add_tail(>list, >c2hcmd_list);
+   __skb_queue_tail(>c2hcmd_queue, skb);
 
spin_unlock_irqrestore(>locks.c2hcmd_lock, flags);
 
/* wake up wq */
queue_delayed_work(rtlpriv->works.rtl_wq, >works.c2hcmd_wq, 0);
-
-   return;
-
-label_err2:
-   kfree(c2hcmd);
-
-label_err:
-   RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
-"C2H cmd enqueue fail.\n");
 }
 EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
 
-void rtl_c2h_content_parsing(struct ieee80211_hw *hw, u8 cmd_id,
-u8 cmd_len, u8 *cmd_buf)
+static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
+   struct sk_buff *skb)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops;
const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
+   u8 cmd_id, cmd_seq, cmd_len;
+   u8 *cmd_buf = NULL;
+
+   cmd_id = skb->data[0];
+   cmd_seq = skb->data[1];
+   cmd_len = skb->len - 2;
+   cmd_buf = skb->data + 2;
 
switch (cmd_id) {
case C2H_DBG:
@@ -2347,67 +2327,35 @@ void rtl_c2h_content_parsing(struct ieee80211_hw *hw, 
u8 cmd_id,
}
 }
 
-void rtl_c2h_packet_handler(struct ieee80211_hw *hw, u8 *buffer, u8 len)
-{
-   struct rtl_priv *rtlpriv = rtl_priv(hw);
-   u8 c2h_cmd_id = 0, c2h_cmd_seq = 0, c2h_cmd_len = 0;
-   u8 *tmp_buf = NULL;
-
-   c2h_cmd_id = buffer[0];
-   c2h_cmd_seq = buffer[1];
-   c2h_cmd_len = len - 2;
-   tmp_buf = buffer + 2;
-
-   RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
-"[C2H packet], c2hCmdId=0x%x, c2hCmdSeq=0x%x, c2hCmdLen=%d\n",
-c2h_cmd_id, c2h_cmd_seq, c2h_cmd_len);
-
-   RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_TRACE,
- "[C2H packet], Content Hex:\n", tmp_buf, c2h_cmd_len);
-
-   switch (c2h_cmd_id) {
-   case C2H_BT_INFO:
-   case C2H_BT_MP:
-   rtl_c2hcmd_enqueue(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
-   break;
-   default:
-   rtl_c2h_content_parsing(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
-   break;
-   }
-}
-EXPORT_SYMBOL_GPL(rtl_c2h_packet_handler);
-
 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
+   struct sk_buff *skb;
unsigned long flags;
-   struct rtl_c2hcmd *c2hcmd;
int i;
 
for (i = 0; i < 200; i++) {
/* dequeue a task */
spin_lock_irqsave(>locks.c2hcmd_lock, flags);
 
-   c2hcmd = list_first_entry_or_null(>c2hcmd_list,
- struct rtl_c2hcmd, list);
-
- 

[PATCH 03/14] rtlwifi: remove duplicate rx_packet_type definition

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Move duplicate definitions from def.h of ic folder to wifi.h

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h | 7 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/def.h | 8 
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/def.h | 8 
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h | 8 
 drivers/net/wireless/realtek/rtlwifi/wifi.h  | 8 
 5 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
index 0532b9852444..32492d64d685 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/def.h
@@ -137,13 +137,6 @@ enum version_8188e {
VERSION_UNKNOWN = 0xFF,
 };
 
-enum rx_packet_type {
-   NORMAL_RX,
-   TX_REPORT1,
-   TX_REPORT2,
-   HIS_REPORT,
-};
-
 enum rtl819x_loopback_e {
RTL819X_NO_LOOPBACK = 0,
RTL819X_MAC_LOOPBACK = 1,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/def.h
index 60f5728b4e2d..9f7e7bb8610b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/def.h
@@ -47,14 +47,6 @@ enum version_8192e {
VERSION_UNKNOWN = 0xFF,
 };
 
-enum rx_packet_type {
-   NORMAL_RX,
-   TX_REPORT1,
-   TX_REPORT2,
-   HIS_REPORT,
-   C2H_PACKET,
-};
-
 enum rtl_desc_qsel {
QSLT_BK = 0x2,
QSLT_BE = 0x0,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/def.h
index 025ea5c0f3f6..5e5403d69220 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/def.h
@@ -38,14 +38,6 @@
 /* Currently only for RTL8723B */
 #define EXT_VENDOR_ID  (BIT(18) | BIT(19))
 
-enum rx_packet_type {
-   NORMAL_RX,
-   TX_REPORT1,
-   TX_REPORT2,
-   HIS_REPORT,
-   C2H_PACKET,
-};
-
 enum rtl_desc_qsel {
QSLT_BK = 0x2,
QSLT_BE = 0x0,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
index dfbdf539de1a..498f716bfc73 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/def.h
@@ -332,14 +332,6 @@ enum rtl_desc_qsel {
QSLT_CMD = 0x13,
 };
 
-enum rx_packet_type {
-   NORMAL_RX,
-   TX_REPORT1,
-   TX_REPORT2,
-   HIS_REPORT,
-   C2H_PACKET,
-};
-
 struct phy_sts_cck_8821ae_t {
u8 adc_pwdb_X[4];
u8 sq_rpt;
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 1259d2b66d17..81ac036760fc 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -1010,6 +1010,14 @@ enum dm_info_query {
DM_INFO_SIZE,
 };
 
+enum rx_packet_type {
+   NORMAL_RX,
+   TX_REPORT1,
+   TX_REPORT2,
+   HIS_REPORT,
+   C2H_PACKET,
+};
+
 struct rtlwifi_tx_info {
int sn;
unsigned long send_time;
-- 
2.15.1



[PATCH 13/14] rtlwifi: access skb->data to get C2H data by macro

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

The format of C2H data is ID(1 byte) + Length(1 byte) + value, and it is
more readable to use macros to access C2H data.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 8 
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 5 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index 61f12f86fcd4..a5939ddfa9cb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -2288,10 +2288,10 @@ static void rtl_c2h_content_parsing(struct ieee80211_hw 
*hw,
u8 cmd_id, cmd_seq, cmd_len;
u8 *cmd_buf = NULL;
 
-   cmd_id = skb->data[0];
-   cmd_seq = skb->data[1];
-   cmd_len = skb->len - 2;
-   cmd_buf = skb->data + 2;
+   cmd_id = GET_C2H_CMD_ID(skb->data);
+   cmd_seq = GET_C2H_SEQ(skb->data);
+   cmd_len = skb->len - C2H_DATA_OFFSET;
+   cmd_buf = GET_C2H_DATA_PTR(skb->data);
 
switch (cmd_id) {
case C2H_DBG:
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 9e620b943f8c..0f3b98c5227f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -177,6 +177,11 @@ enum rtl_c2h_evt_v2 {
C2H_V2_CCX_RPT = 0x0F,
 };
 
+#define GET_C2H_CMD_ID(c2h)({u8 *__c2h = c2h; __c2h[0]; })
+#define GET_C2H_SEQ(c2h)   ({u8 *__c2h = c2h; __c2h[1]; })
+#define C2H_DATA_OFFSET2
+#define GET_C2H_DATA_PTR(c2h)  ({u8 *__c2h = c2h; &__c2h[C2H_DATA_OFFSET]; })
+
 #define GET_TX_REPORT_SN_V1(c2h)   (c2h[6])
 #define GET_TX_REPORT_ST_V1(c2h)   (c2h[0] & 0xC0)
 #define GET_TX_REPORT_RETRY_V1(c2h)(c2h[2] & 0x3F)
-- 
2.15.1



[PATCH 04/14] rtlwifi: rename register-based C2H command IDs to V0

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

Current chips use packet-based C2H commands whose IDs differ from old
ones, so this commit simply gives C2H_V0_ as prefix of command IDs.

Signed-off-by: Ping-Ke Shih 
---
 .../net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c |  6 +++---
 .../net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h | 20 ++--
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c
index ec9bcf32f0ab..788de88ab1ee 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.c
@@ -1749,13 +1749,13 @@ void rtl_8723e_c2h_command_handle(struct ieee80211_hw 
*hw)
 
 
switch (c2h_event.cmd_id) {
-   case C2H_BT_RSSI:
+   case C2H_V0_BT_RSSI:
break;
 
-   case C2H_BT_OP_MODE:
+   case C2H_V0_BT_OP_MODE:
break;
 
-   case BT_INFO:
+   case C2H_V0_BT_INFO:
RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE,
"BT info Byte[0] (ID) is 0x%x\n",
c2h_event.cmd_id);
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h
index 3723d7476717..756868897d8b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hal_btc.h
@@ -130,17 +130,17 @@ enum bt_state {
BT_INFO_STATE_MAX = 7
 };
 
-enum rtl8723e_c2h_evt {
-   C2H_DBG = 0,
-   C2H_TSF = 1,
-   C2H_AP_RPT_RSP = 2,
+enum rtl8723e_c2h_evt_v0 {
+   C2H_V0_DBG = 0,
+   C2H_V0_TSF = 1,
+   C2H_V0_AP_RPT_RSP = 2,
/* The FW notify the report of the specific tx packet. */
-   C2H_CCX_TX_RPT = 3,
-   C2H_BT_RSSI = 4,
-   C2H_BT_OP_MODE = 5,
-   C2H_HW_INFO_EXCH = 10,
-   C2H_C2H_H2C_TEST = 11,
-   BT_INFO = 12,
+   C2H_V0_CCX_TX_RPT = 3,
+   C2H_V0_BT_RSSI = 4,
+   C2H_V0_BT_OP_MODE = 5,
+   C2H_V0_HW_INFO_EXCH = 10,
+   C2H_V0_C2H_H2C_TEST = 11,
+   C2H_V0_BT_INFO = 12,
MAX_C2HEVENT
 };
 
-- 
2.15.1



[PATCH 14/14] rtlwifi: fix btmpinfo timeout while processing C2H_BT_INFO

2018-05-18 Thread pkshih
From: Ping-Ke Shih 

In former patch, I enqueu all C2H commands and processed by a workqueue.
In case C2H_BT_INFO will issue a H2C command to set BT reg, and wait for
a C2H ack. But it is totally impossible that C2H workqueue waits for a
C2H command, so kernel log warn
rtlwifi: :<0> btmpinfo wait (req_num=0) timeout

Since the C2H ack command C2H_BT_MP can be safely processed in interrupt
context, add a fast command path to deal with the command.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c 
b/drivers/net/wireless/realtek/rtlwifi/base.c
index a5939ddfa9cb..39c817eddd78 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -2262,11 +2262,33 @@ void rtl_fwevt_wq_callback(void *data)
rtlpriv->cfg->ops->c2h_command_handle(hw);
 }
 
+static void rtl_c2h_content_parsing(struct ieee80211_hw *hw,
+   struct sk_buff *skb);
+
+static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+   u8 cmd_id = GET_C2H_CMD_ID(skb->data);
+
+   switch (cmd_id) {
+   case C2H_BT_MP:
+   return true;
+   default:
+   break;
+   }
+
+   return false;
+}
+
 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
unsigned long flags;
 
+   if (rtl_c2h_fast_cmd(hw, skb)) {
+   rtl_c2h_content_parsing(hw, skb);
+   return;
+   }
+
/* enqueue */
spin_lock_irqsave(>locks.c2hcmd_lock, flags);
 
-- 
2.15.1



Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-05-15 Thread Pkshih
On Mon, 2018-04-30 at 14:03 +0530, Krishna Chaitanya wrote:
> On Mon, Apr 30, 2018 at 8:10 AM, Pkshih <pks...@realtek.com> wrote:
> >
> >
> > > -Original Message-
> > > From: Barry Day [mailto:brise...@gmail.com]
> > > Sent: Saturday, April 28, 2018 6:42 AM
> > > To: Pkshih
> > > Cc: Kalle Valo; larry.fin...@lwfinger.net; linux-wireless@vger.kernel.org
> > > Subject: Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac
> > >
> > > On Fri, Apr 27, 2018 at 05:44:16AM +, Pkshih wrote:
> > > >
> > > > The registers reside in driver causes error frequently, because MAC 
> > > > register
> > > > is maintained by Realtek's MAC team so they create this module to avoid 
> > > > mistakes.
> > > > Another benefit is to make it possible to become a thin driver, because 
> > > > many
> > > > common functions are provided, so duplicate code will be reduced.
> > >
> > > How is it possible to create a thin driver by adding lots more code and 
> > > layers
> > > of indirection ??? and writing it in a way that it won't compile without 
> > > the
> > > code for every type of bus interface even though most modules only use 
> > > one ?
> > >
> > As I mentioned in first paragraph "(I use 'driver' in this mail indicates 
> > part of
> > rtlwifi excluded from this module.)". If this module was seen as a 'lib', 
> > rtl8822be
> > would be a "thin driver". For bus interface code, I need to add a way to 
> > compile
> > type of bus interface according to selected chip.
> >
> > > It's a horrible pile of garbage slapped together by an inexperienced
> > > programmer. Its a major deterrent for anyone looking at working on one of
> > > the latest realtek drivers.
> > >
> > This module is designed to support multiple OS including Windows and Linux, 
> > and
> > many products have used this module and worked well. We hope Linux user can 
> > also
> > use Realtek's WiFi without additional installation if driver was built.
> > In order to submit this module to kernel upstream, we take a lot of effort
> > to fit Linux coding conventions (e.g. coding style), and explicit
> > suggestions will be helpful for us to continuously improve this module.
> 
> IMHO, this is a common use case for most organizations. I understand
> that Linux cannot
> accommodate other OSes requirements but is there an approved/recommended way
> to upstream an OS agnostic driver? Agnostic drivers are generally
> bulkier compared to
> Linux-only drivers and also code organization is also different (to
> handle other OSes).
> 

Hi Kalle,

The state of this patchset was changed to RFC in patchwork, and I look at RFC's
meaning in wireless wiki. Do you expect that I will send v4? If so, what do I
need to fix in v4? Or, you need more description about this module, please let
me know. 

Thanks
PK



Re: RTL8723BE performance regression

2018-05-13 Thread Pkshih
On Wed, 2018-05-09 at 13:33 -0700, João Paulo Rechi Vita wrote:
> On Tue, May 8, 2018 at 1:37 AM, Pkshih <pks...@realtek.com> wrote:
> > On Mon, 2018-05-07 at 14:49 -0700, João Paulo Rechi Vita wrote:
> >> On Tue, May 1, 2018 at 10:58 PM, Pkshih <pks...@realtek.com> wrote:
> >> > On Wed, 2018-05-02 at 05:44 +, Pkshih wrote:
> >> >>
> >> >> > -Original Message-
> >> >> > From: João Paulo Rechi Vita [mailto:jprv...@gmail.com]
> >> >> > Sent: Wednesday, May 02, 2018 6:41 AM
> >> >> > To: Larry Finger
> >> >> > Cc: Steve deRosier; 莊彥宣; Pkshih; Birming Chiu; Shaofu; Steven Ting; 
> >> >> > Chaoming_Li; Kalle
> Valo;
> >> >> > linux-wireless; Network Development; LKML; Daniel Drake; João Paulo 
> >> >> > Rechi Vita; linux@endl
> ess
> >> m.c
> >> >> om
> >> >> > Subject: Re: RTL8723BE performance regression
> >> >> >
> >> >> > On Tue, Apr 3, 2018 at 7:51 PM, Larry Finger 
> >> >> > <larry.fin...@lwfinger.net> wrote:
> >> >> > > On 04/03/2018 09:37 PM, João Paulo Rechi Vita wrote:
> >> >> > >>
> >> >> > >> On Tue, Apr 3, 2018 at 7:28 PM, Larry Finger 
> >> >> > >> <larry.fin...@lwfinger.net>
> >> >> > >> wrote:
> >> >> > >>
> >> >> > >> (...)
> >> >> > >>
> >> >> > >>> As the antenna selection code changes affected your first 
> >> >> > >>> bisection, do
> >> >> > >>> you
> >> >> > >>> have one of those HP laptops with only one antenna and the 
> >> >> > >>> incorrect
> >> >> > >>> coding
> >> >> > >>> in the FUSE?
> >> >> > >>
> >> >> > >>
> >> >> > >> Yes, that is why I've been passing ant_sel=1 during my tests -- 
> >> >> > >> this
> >> >> > >> was needed to achieve a good performance in the past, before this
> >> >> > >> regression. I've also opened the laptop chassis and confirmed the
> >> >> > >> antenna cable is plugged to the connector labeled with "1" on the
> >> >> > >> card.
> >> >> > >>
> >> >> > >>> If so, please make sure that you still have the same signal
> >> >> > >>> strength for good and bad cases. I have tried to keep the driver 
> >> >> > >>> and the
> >> >> > >>> btcoex code in sync, but there may be some combinations of antenna
> >> >> > >>> configuration and FUSE contents that cause the code to fail.
> >> >> > >>>
> >> >> > >>
> >> >> > >> What is the recommended way to monitor the signal strength?
> >> >> > >
> >> >> > >
> >> >> > > The btcoex code is developed for multiple platforms by a different 
> >> >> > > group
> >> >> > > than the Linux driver. I think they made a change that caused 
> >> >> > > ant_sel to
> >> >> > > switch from 1 to 2. At least numerous comments at
> >> >> > > github.com/lwfinger/rtlwifi_new claimed they needed to make that 
> >> >> > > change.
> >> >> > >
> >> >> > > Mhy recommended method is to verify the wifi device name with "iw 
> >> >> > > dev". Then
> >> >> > > using that device
> >> >> > >
> >> >> > > sudo iw dev  scan | egrep "SSID|signal"
> >> >> > >
> >> >> >
> >> >> > I have confirmed that the performance regression is indeed tied to
> >> >> > signal strength: on the good cases signal was between -16 and -8 dBm,
> >> >> > whereas in bad cases signal was always between -50 to - 40 dBm. I've
> >> >> > also switched to testing bandwidth in controlled LAN environment using
> >> >> > iperf3, as suggested by Steve deRosier, with the DUT being the only
> >> >> > machine connected to the 2.4 GHz radio and the machine running the
> >> >> > i

Re: RTL8723BE performance regression

2018-05-08 Thread Pkshih
On Mon, 2018-05-07 at 14:49 -0700, João Paulo Rechi Vita wrote:
> On Tue, May 1, 2018 at 10:58 PM, Pkshih <pks...@realtek.com> wrote:
> > On Wed, 2018-05-02 at 05:44 +, Pkshih wrote:
> >>
> >> > -Original Message-
> >> > From: João Paulo Rechi Vita [mailto:jprv...@gmail.com]
> >> > Sent: Wednesday, May 02, 2018 6:41 AM
> >> > To: Larry Finger
> >> > Cc: Steve deRosier; 莊彥宣; Pkshih; Birming Chiu; Shaofu; Steven Ting; 
> >> > Chaoming_Li; Kalle Valo;
> >> > linux-wireless; Network Development; LKML; Daniel Drake; João Paulo 
> >> > Rechi Vita; linux@endless
> m.c
> >> om
> >> > Subject: Re: RTL8723BE performance regression
> >> >
> >> > On Tue, Apr 3, 2018 at 7:51 PM, Larry Finger <larry.fin...@lwfinger.net> 
> >> > wrote:
> >> > > On 04/03/2018 09:37 PM, João Paulo Rechi Vita wrote:
> >> > >>
> >> > >> On Tue, Apr 3, 2018 at 7:28 PM, Larry Finger 
> >> > >> <larry.fin...@lwfinger.net>
> >> > >> wrote:
> >> > >>
> >> > >> (...)
> >> > >>
> >> > >>> As the antenna selection code changes affected your first bisection, 
> >> > >>> do
> >> > >>> you
> >> > >>> have one of those HP laptops with only one antenna and the incorrect
> >> > >>> coding
> >> > >>> in the FUSE?
> >> > >>
> >> > >>
> >> > >> Yes, that is why I've been passing ant_sel=1 during my tests -- this
> >> > >> was needed to achieve a good performance in the past, before this
> >> > >> regression. I've also opened the laptop chassis and confirmed the
> >> > >> antenna cable is plugged to the connector labeled with "1" on the
> >> > >> card.
> >> > >>
> >> > >>> If so, please make sure that you still have the same signal
> >> > >>> strength for good and bad cases. I have tried to keep the driver and 
> >> > >>> the
> >> > >>> btcoex code in sync, but there may be some combinations of antenna
> >> > >>> configuration and FUSE contents that cause the code to fail.
> >> > >>>
> >> > >>
> >> > >> What is the recommended way to monitor the signal strength?
> >> > >
> >> > >
> >> > > The btcoex code is developed for multiple platforms by a different 
> >> > > group
> >> > > than the Linux driver. I think they made a change that caused ant_sel 
> >> > > to
> >> > > switch from 1 to 2. At least numerous comments at
> >> > > github.com/lwfinger/rtlwifi_new claimed they needed to make that 
> >> > > change.
> >> > >
> >> > > Mhy recommended method is to verify the wifi device name with "iw 
> >> > > dev". Then
> >> > > using that device
> >> > >
> >> > > sudo iw dev  scan | egrep "SSID|signal"
> >> > >
> >> >
> >> > I have confirmed that the performance regression is indeed tied to
> >> > signal strength: on the good cases signal was between -16 and -8 dBm,
> >> > whereas in bad cases signal was always between -50 to - 40 dBm. I've
> >> > also switched to testing bandwidth in controlled LAN environment using
> >> > iperf3, as suggested by Steve deRosier, with the DUT being the only
> >> > machine connected to the 2.4 GHz radio and the machine running the
> >> > iperf3 server connected via ethernet.
> >> >
> >>
> >> We have new experimental results in commit af8a41cccf8f46 ("rtlwifi: 
> >> cleanup
> >> 8723be ant_sel definition"). You can use the above commit and do the same
> >> experiments (with ant_sel=0, 1 and 2) in your side, and then share your 
> >> results.
> >> Since performance is tied to signal strength, you can only share signal 
> >> strength.
> >>
> >
> > Please pay attention to cold reboot once ant_sel is changed.
> >
> 
> I've tested the commit mentioned above and it fixes the problem on top
> of v4.16 (in addition to the latest wireless-drivers-next also been
> fixed as it already contains such commit). On v4.15, we also need the
> following commits before "af8a41cccf8f rtlwifi: c

[PATCH] rtlwifi: remove duplicate definition of antenna number for btcoex

2018-05-03 Thread pkshih
From: Ping-Ke Shih 

Two enumerations bt_total_ant_num and bt_ant_num are identical, so one
can be removed.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 5 -
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c
index fd7928fdbd1a..3f2295fdb02d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c
@@ -2574,11 +2574,11 @@ void rtl92ee_read_bt_coexist_info_from_hwpg(struct 
ieee80211_hw *hw,
rtlpriv->btcoexist.btc_info.btcoexist = 0;
 
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8192E;
-   rtlpriv->btcoexist.btc_info.ant_num = ANT_TOTAL_X2;
+   rtlpriv->btcoexist.btc_info.ant_num = ANT_X2;
} else {
rtlpriv->btcoexist.btc_info.btcoexist = 1;
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8192E;
-   rtlpriv->btcoexist.btc_info.ant_num = ANT_TOTAL_X1;
+   rtlpriv->btcoexist.btc_info.ant_num = ANT_X1;
}
 }
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index ce1754054a07..208010fcde21 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2842,11 +2842,6 @@ enum bt_co_type {
BT_RTL8812A = 11,
 };
 
-enum bt_total_ant_num {
-   ANT_TOTAL_X2 = 0,
-   ANT_TOTAL_X1 = 1
-};
-
 enum bt_cur_state {
BT_OFF = 0,
BT_ON = 1,
-- 
2.15.1



Re: RTL8723BE performance regression

2018-05-01 Thread Pkshih
On Wed, 2018-05-02 at 05:44 +, Pkshih wrote:
> 
> > -Original Message-
> > From: João Paulo Rechi Vita [mailto:jprv...@gmail.com]
> > Sent: Wednesday, May 02, 2018 6:41 AM
> > To: Larry Finger
> > Cc: Steve deRosier; 莊彥宣; Pkshih; Birming Chiu; Shaofu; Steven Ting; 
> > Chaoming_Li; Kalle Valo;
> > linux-wireless; Network Development; LKML; Daniel Drake; João Paulo Rechi 
> > Vita; linux@endlessm.c
> om
> > Subject: Re: RTL8723BE performance regression
> > 
> > On Tue, Apr 3, 2018 at 7:51 PM, Larry Finger <larry.fin...@lwfinger.net> 
> > wrote:
> > > On 04/03/2018 09:37 PM, João Paulo Rechi Vita wrote:
> > >>
> > >> On Tue, Apr 3, 2018 at 7:28 PM, Larry Finger <larry.fin...@lwfinger.net>
> > >> wrote:
> > >>
> > >> (...)
> > >>
> > >>> As the antenna selection code changes affected your first bisection, do
> > >>> you
> > >>> have one of those HP laptops with only one antenna and the incorrect
> > >>> coding
> > >>> in the FUSE?
> > >>
> > >>
> > >> Yes, that is why I've been passing ant_sel=1 during my tests -- this
> > >> was needed to achieve a good performance in the past, before this
> > >> regression. I've also opened the laptop chassis and confirmed the
> > >> antenna cable is plugged to the connector labeled with "1" on the
> > >> card.
> > >>
> > >>> If so, please make sure that you still have the same signal
> > >>> strength for good and bad cases. I have tried to keep the driver and the
> > >>> btcoex code in sync, but there may be some combinations of antenna
> > >>> configuration and FUSE contents that cause the code to fail.
> > >>>
> > >>
> > >> What is the recommended way to monitor the signal strength?
> > >
> > >
> > > The btcoex code is developed for multiple platforms by a different group
> > > than the Linux driver. I think they made a change that caused ant_sel to
> > > switch from 1 to 2. At least numerous comments at
> > > github.com/lwfinger/rtlwifi_new claimed they needed to make that change.
> > >
> > > Mhy recommended method is to verify the wifi device name with "iw dev". 
> > > Then
> > > using that device
> > >
> > > sudo iw dev  scan | egrep "SSID|signal"
> > >
> > 
> > I have confirmed that the performance regression is indeed tied to
> > signal strength: on the good cases signal was between -16 and -8 dBm,
> > whereas in bad cases signal was always between -50 to - 40 dBm. I've
> > also switched to testing bandwidth in controlled LAN environment using
> > iperf3, as suggested by Steve deRosier, with the DUT being the only
> > machine connected to the 2.4 GHz radio and the machine running the
> > iperf3 server connected via ethernet.
> > 
> 
> We have new experimental results in commit af8a41cccf8f46 ("rtlwifi: cleanup 
> 8723be ant_sel definition"). You can use the above commit and do the same 
> experiments (with ant_sel=0, 1 and 2) in your side, and then share your 
> results.
> Since performance is tied to signal strength, you can only share signal 
> strength.
> 

Please pay attention to cold reboot once ant_sel is changed.



RE: RTL8723BE performance regression

2018-05-01 Thread Pkshih


> -Original Message-
> From: João Paulo Rechi Vita [mailto:jprv...@gmail.com]
> Sent: Wednesday, May 02, 2018 6:41 AM
> To: Larry Finger
> Cc: Steve deRosier; 莊彥宣; Pkshih; Birming Chiu; Shaofu; Steven Ting; 
> Chaoming_Li; Kalle Valo;
> linux-wireless; Network Development; LKML; Daniel Drake; João Paulo Rechi 
> Vita; li...@endlessm.com
> Subject: Re: RTL8723BE performance regression
> 
> On Tue, Apr 3, 2018 at 7:51 PM, Larry Finger <larry.fin...@lwfinger.net> 
> wrote:
> > On 04/03/2018 09:37 PM, João Paulo Rechi Vita wrote:
> >>
> >> On Tue, Apr 3, 2018 at 7:28 PM, Larry Finger <larry.fin...@lwfinger.net>
> >> wrote:
> >>
> >> (...)
> >>
> >>> As the antenna selection code changes affected your first bisection, do
> >>> you
> >>> have one of those HP laptops with only one antenna and the incorrect
> >>> coding
> >>> in the FUSE?
> >>
> >>
> >> Yes, that is why I've been passing ant_sel=1 during my tests -- this
> >> was needed to achieve a good performance in the past, before this
> >> regression. I've also opened the laptop chassis and confirmed the
> >> antenna cable is plugged to the connector labeled with "1" on the
> >> card.
> >>
> >>> If so, please make sure that you still have the same signal
> >>> strength for good and bad cases. I have tried to keep the driver and the
> >>> btcoex code in sync, but there may be some combinations of antenna
> >>> configuration and FUSE contents that cause the code to fail.
> >>>
> >>
> >> What is the recommended way to monitor the signal strength?
> >
> >
> > The btcoex code is developed for multiple platforms by a different group
> > than the Linux driver. I think they made a change that caused ant_sel to
> > switch from 1 to 2. At least numerous comments at
> > github.com/lwfinger/rtlwifi_new claimed they needed to make that change.
> >
> > Mhy recommended method is to verify the wifi device name with "iw dev". Then
> > using that device
> >
> > sudo iw dev  scan | egrep "SSID|signal"
> >
> 
> I have confirmed that the performance regression is indeed tied to
> signal strength: on the good cases signal was between -16 and -8 dBm,
> whereas in bad cases signal was always between -50 to - 40 dBm. I've
> also switched to testing bandwidth in controlled LAN environment using
> iperf3, as suggested by Steve deRosier, with the DUT being the only
> machine connected to the 2.4 GHz radio and the machine running the
> iperf3 server connected via ethernet.
> 

We have new experimental results in commit af8a41cccf8f46 ("rtlwifi: cleanup 
8723be ant_sel definition"). You can use the above commit and do the same 
experiments (with ant_sel=0, 1 and 2) in your side, and then share your results.
Since performance is tied to signal strength, you can only share signal 
strength.

Regards
PK



RE: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-04-29 Thread Pkshih

> -Original Message-
> From: Barry Day [mailto:brise...@gmail.com]
> Sent: Saturday, April 28, 2018 6:42 AM
> To: Pkshih
> Cc: Kalle Valo; larry.fin...@lwfinger.net; linux-wireless@vger.kernel.org
> Subject: Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac
> 
> On Fri, Apr 27, 2018 at 05:44:16AM +, Pkshih wrote:
> >
> > The registers reside in driver causes error frequently, because MAC register
> > is maintained by Realtek's MAC team so they create this module to avoid 
> > mistakes.
> > Another benefit is to make it possible to become a thin driver, because many
> > common functions are provided, so duplicate code will be reduced.
> 
> How is it possible to create a thin driver by adding lots more code and layers
> of indirection ??? and writing it in a way that it won't compile without the
> code for every type of bus interface even though most modules only use one ?
> 
As I mentioned in first paragraph "(I use 'driver' in this mail indicates part 
of
rtlwifi excluded from this module.)". If this module was seen as a 'lib', 
rtl8822be
would be a "thin driver". For bus interface code, I need to add a way to 
compile 
type of bus interface according to selected chip.

> It's a horrible pile of garbage slapped together by an inexperienced
> programmer. Its a major deterrent for anyone looking at working on one of
> the latest realtek drivers.
> 
This module is designed to support multiple OS including Windows and Linux, and 
many products have used this module and worked well. We hope Linux user can also
use Realtek's WiFi without additional installation if driver was built.
In order to submit this module to kernel upstream, we take a lot of effort 
to fit Linux coding conventions (e.g. coding style), and explicit 
suggestions will be helpful for us to continuously improve this module.

Thanks
PK



RE: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-04-26 Thread Pkshih

> -Original Message-
> From: Kalle Valo [mailto:kv...@codeaurora.org]
> Sent: Wednesday, April 25, 2018 3:36 PM
> To: Pkshih
> Cc: larry.fin...@lwfinger.net; linux-wireless@vger.kernel.org
> Subject: Re: [PATCH v3 00/19] rtlwifi: halmac: Add new module halmac
> 
> <pks...@realtek.com> writes:
> 
> > From: Ping-Ke Shih <pks...@realtek.com>
> >
> > v3: patch 06/17 in v2 is too big, so mail server may block the mail.
> > In this patchset, I decompose the patch into three patches 06/19-08/19,
> > so in patchset view v2 and v3 are identical.
> 
> I can confirm, all patches made it to patchwork now.
> 
> > v2: remove indirection to get halmac ops
> > Only patches 1/17 and 11/17 are changed.
> >
> > Patches 1/19-3/19 are added structure to support this module.
> > Patches 4/19-18/19 add new files.
> > Patch 19/19 add this module to Makefile and Kconfig.
> >
> > Ping-Ke Shih (19):
> >   rtlwifi: add halmac structure to wifi.h
> >   rtlwifi: add debug ID COMP_HALMAC
> >   rtlwifi: add dmdef.h to share with driver and other modules
> >   rtlwifi: halmac: add main definition used by halmac
> >   rtlwifi: halmac: describe number and size of chip functions
> >   rtlwifi: halmac: add register definitions
> >   rtlwifi: halmac: add bit field definitions
> >   rtlwifi: halmac: add bit field definitions of rtl8822b
> >   rtlwifi: halmac: add definition of TX/RX descriptor
> >   rtlwifi: halmac: add GPIO pin/pinmux definitions
> >   rtlwifi: halmac: add power sequence to turn on/off wifi card
> >   rtlwifi: halmac: access efuse through halmac helper functions
> >   rtlwifi: halmac: add files to implement halmac ops
> >   rtlwifi: halmac: add halmac init/deinit functions
> >   rtlwifi: halmac: add firmware related functions and definitions
> >   rtlwifi: halmac: add bus interface commands
> >   rtlwifi: halmac: add to control WiFi mac functions and registers
> >   rtlwifi: halmac: add to support BB and RF functions
> >   rtlwifi: add halmac to Makefile and Kconfig
> 
> You are adding a new component to rtlwifi but there's no introduction in
> the cover letter. Why is this needed? For what hardware is it for? What
> new features does it bring?
> 
> >  77 files changed, 64201 insertions(+)
> 
> This is a huge patchset, I'm not even sure if I want to start reviewing
> this. Especially when I have no clue about the big picture (which should
> be described in the cover letter).
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#too_many_patches
> 
I know the number of patches in a patchset should be within 10-12, but I
think that all files are new and full source can give you whole picture
if you want to know code flow between them.

> And I even read all 19 commit logs and there was no mention of why this
> is needed either. I cannot just blindly apply patches without knowing
> what they do.
> 

This new module halmac is an abstract layer for Realtek WiFi MAC to provide
common interfaces to access WiFi MAC and register set. If driver (I use 'driver'
in this mail indicates part of rtlwifi excluded from this module.) uses the API,
it's not necessary to control related register directly. If API isn't 
implemented,
driver can use the registers defined by halmac to manipulate MAC function.

The registers reside in driver causes error frequently, because MAC register
is maintained by Realtek's MAC team so they create this module to avoid 
mistakes.
Another benefit is to make it possible to become a thin driver, because many
common functions are provided, so duplicate code will be reduced.

Currently, this module is aim to rtl8822be, and it will extend to support
more chips so hierarchical directory is adopted. It looks like
   rtlwifi/halmac/halmac_88xx
   rtlwifi/halmac/halmac_88xx/halmac_8822b
   rtlwifi/halmac/halmac_88xx/halmac_8821c (future chip)
The directory halmac_88xx puts common functions of rtl8822b and rtl8821c, and
halmac_88xx/halmac_8822b puts rtl8822b specific functions.
To access API abstractly, it provides hook pointers to specific chip during
initialization.


In order to illustrate the functions, I list *.c files and short description:

   halmac/rtl_halmac.c
 We implement a facade-like (facade is a term in design pattern) by
 halmac_ops in this file, so we can check halmac_ops to know halmac 
functions.
 The functions, for examples, are init/deinit, power on/off, read efuse,
 c2h handler, iqk assistant function etc. Each function may call one or 
more 
 halmac API to achieve.
  
   halmac/halmac_api.c
   halmac/halmac_88xx/halmac_init_88xx.c
   halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
 The init/deinit and mount ho

Re: [PATCH v2 00/17] rtlwifi: halmac: Add new module halmac

2018-04-24 Thread Pkshih
On Tue, 2018-04-24 at 17:12 +, Kalle Valo wrote:
>  writes:
> 
> > From: Ping-Ke Shih 
> >
> > v2: remove indirection to get halmac ops
> > Only patches 1/17 and 11/17 are changed.
> >
> > Patches 1/17-3/17 are added structure to support this module.
> > Patches 4/17-16/17 add new files.
> > Patch 17/17 add this module to Makefile and Kconfig.
> >
> > Ping-Ke Shih (17):
> >   rtlwifi: add halmac structure to wifi.h
> >   rtlwifi: add debug ID COMP_HALMAC
> >   rtlwifi: add dmdef.h to share with driver and other modules
> >   rtlwifi: halmac: add main definition used by halmac
> >   rtlwifi: halmac: describe number and size of chip functions
> >   rtlwifi: halmac: add definitions of registers and bit fields
> >   rtlwifi: halmac: add definition of TX/RX descriptor
> >   rtlwifi: halmac: add GPIO pin/pinmux definitions
> >   rtlwifi: halmac: add power sequence to turn on/off wifi card
> >   rtlwifi: halmac: access efuse through halmac helper functions
> >   rtlwifi: halmac: add files to implement halmac ops
> >   rtlwifi: halmac: add halmac init/deinit functions
> >   rtlwifi: halmac: add firmware related functions and definitions
> >   rtlwifi: halmac: add bus interface commands
> >   rtlwifi: halmac: add to control WiFi mac functions and registers
> >   rtlwifi: halmac: add to support BB and RF functions
> >   rtlwifi: add halmac to Makefile and Kconfig
> 
> BTW, I don't see patch 6 in patchwork. Did it get lost?
> 
>   [v2,01/17] rtlwifi: add halmac structure to wifi.h   2018-04-03 
>Ping-Ke Shih New
>   [v2,02/17] rtlwifi: add debug ID COMP_HALMAC 2018-04-03 
>Ping-Ke Shih New
>   [v2,03/17] rtlwifi: add dmdef.h to share with driver and 2018-04-03 
>Ping-Ke Shih New
>   [v2,04/17] rtlwifi: halmac: add main definition used by h... 2018-04-03 
>Ping-Ke Shih New
>   [v2,05/17] rtlwifi: halmac: describe number and size of c... 2018-04-03 
>Ping-Ke Shih New
>   [v2,07/17] rtlwifi: halmac: add definition of TX/RX descr... 2018-04-03 
>Ping-Ke Shih New
>   [v2,08/17] rtlwifi: halmac: add GPIO pin/pinmux definitions  2018-04-03 
>Ping-Ke Shih New
>   [v2,09/17] rtlwifi: halmac: add power sequence to turn on... 2018-04-03 
>Ping-Ke Shih New
>   [v2,10/17] rtlwifi: halmac: access efuse through halmac h... 2018-04-03 
>Ping-Ke Shih New
>   [v2,11/17] rtlwifi: halmac: add files to implement halmac... 2018-04-03 
>Ping-Ke Shih New
>   [v2,12/17] rtlwifi: halmac: add halmac init/deinit functions 2018-04-03 
>Ping-Ke Shih New
>   [v2,13/17] rtlwifi: halmac: add firmware related function... 2018-04-03 
>Ping-Ke Shih New
>   [v2,14/17] rtlwifi: halmac: add bus interface commands   2018-04-03 
>Ping-Ke Shih New
>   [v2,15/17] rtlwifi: halmac: add to control WiFi mac funct... 2018-04-03 
>Ping-Ke Shih New
>   [v2,16/17] rtlwifi: halmac: add to support BB and RF func... 2018-04-03 
>Ping-Ke Shih New
>   [v2,17/17] rtlwifi: add halmac to Makefile and Kconfig   2018-04-03 
>Ping-Ke Shih New
> 

Patch 06/17 in v2 is too big, so mail server blocks it.
I split the patch into three patches, and resend v3.

Thanks
PK


[PATCH v3 12/19] rtlwifi: halmac: access efuse through halmac helper functions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

This file provides interfaces to read and write efuse contents.

Signed-off-by: Ping-Ke Shih 
---
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c | 1918 
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h |  101 ++
 2 files changed, 2019 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
new file mode 100644
index ..3d51acb5857e
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
@@ -0,0 +1,1918 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_efuse_88xx.h"
+#include "halmac_88xx_cfg.h"
+#include "halmac_common_88xx.h"
+#include "halmac_init_88xx.h"
+
+#define RSVD_EFUSE_SIZE16
+#define RSVD_CS_EFUSE_SIZE 24
+#define PROTECT_EFUSE_SIZE 96
+#define FEATURE_DUMP_PHY_EFUSE HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE
+#define FEATURE_DUMP_LOG_EFUSE HALMAC_FEATURE_DUMP_LOGICAL_EFUSE
+
+static enum halmac_cmd_construct_state
+efuse_cmd_cnstr_state_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+proc_dump_efuse_88xx(struct halmac_adapter *adapter,
+enum halmac_efuse_read_cfg cfg);
+
+static enum halmac_ret_status
+read_hw_efuse_88xx(struct halmac_adapter *adapter, u32 offset, u32 size,
+  u8 *map);
+
+static enum halmac_ret_status
+eeprom_parser_88xx(struct halmac_adapter *adapter, u8 *phy_map, u8 *log_map);
+
+static enum halmac_ret_status
+read_log_efuse_map_88xx(struct halmac_adapter *adapter, u8 *map);
+
+static enum halmac_ret_status
+proc_pg_efuse_by_map_88xx(struct halmac_adapter *adapter,
+ struct halmac_pg_efuse_info *info,
+ enum halmac_efuse_read_cfg cfg);
+
+static enum halmac_ret_status
+dump_efuse_fw_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+dump_efuse_drv_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+proc_write_log_efuse_88xx(struct halmac_adapter *adapter, u32 offset, u8 
value);
+
+static enum halmac_ret_status
+update_eeprom_mask_88xx(struct halmac_adapter *adapter,
+   struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static enum halmac_ret_status
+check_efuse_enough_88xx(struct halmac_adapter *adapter,
+   struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static enum halmac_ret_status
+pg_extend_efuse_88xx(struct halmac_adapter *adapter,
+struct halmac_pg_efuse_info *info, u8 word_en,
+u8 pre_word_en, u32 eeprom_offset);
+
+static enum halmac_ret_status
+proc_pg_efuse_88xx(struct halmac_adapter *adapter,
+  struct halmac_pg_efuse_info *info, u8 word_en,
+  u8 pre_word_en, u32 eeprom_offset);
+
+static enum halmac_ret_status
+program_efuse_88xx(struct halmac_adapter *adapter,
+  struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static void
+mask_eeprom_88xx(struct halmac_adapter *adapter,
+struct halmac_pg_efuse_info *info);
+
+/**
+ * dump_efuse_map_88xx() - dump "physical" efuse map
+ * @adapter : the adapter of halmac
+ * @cfg : dump efuse method
+ * Author : Ivan Lin/KaiYuan Chang
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+dump_efuse_map_88xx(struct halmac_adapter *adapter,
+   enum halmac_efuse_read_cfg cfg)
+{
+   u8 *map = NULL;
+   u8 *efuse_map;
+   u32 efuse_size = adapter->hw_cfg_info.efuse_size;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.efuse_state.proc_status;
+
+   if (cfg == HALMAC_EFUSE_R_FW &&
+   halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+

[PATCH v3 16/19] rtlwifi: halmac: add bus interface commands

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

The halmac supports three buses interfaces, PCI, USB and SDIO, and this
commit makes it possible to change their phy parameters.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.c   | 218 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.h   |  38 +
 .../halmac_88xx/halmac_8822b/halmac_phy_8822b.c| 148 
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.c   | 880 
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.h   |  62 ++
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.c| 161 
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.h|  38 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c  | 538 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h  |  98 +++
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c  | 895 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h  |  75 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c   | 522 
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h   |  83 ++
 .../realtek/rtlwifi/halmac/halmac_intf_phy_cmd.h   |  45 ++
 .../realtek/rtlwifi/halmac/halmac_pcie_reg.h   |  36 +
 .../realtek/rtlwifi/halmac/halmac_sdio_reg.h   |  53 ++
 .../realtek/rtlwifi/halmac/halmac_usb_reg.h|  19 +
 17 files changed, 3909 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_phy_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_sdio_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_sdio_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_usb_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_usb_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_intf_phy_cmd.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_pcie_reg.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_sdio_reg.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_usb_reg.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
new file mode 100644
index ..88a148e528a5
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
@@ -0,0 +1,218 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_pcie_8822b.h"
+#include "halmac_pwr_seq_8822b.h"
+#include "../halmac_init_88xx.h"
+#include "../halmac_common_88xx.h"
+#include "../halmac_pcie_88xx.h"
+#include "../halmac_88xx_cfg.h"
+
+/**
+ * mac_pwr_switch_pcie_8822b() - switch mac power
+ * @adapter : the adapter of halmac
+ * @pwr : power state
+ * Author : KaiYuan Chang
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+mac_pwr_switch_pcie_8822b(struct halmac_adapter *adapter,
+ enum halmac_mac_power pwr)
+{
+   u8 value8;
+   u8 rpwm;
+   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
+   enum halmac_ret_status status;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+   

[PATCH v3 17/19] rtlwifi: halmac: add to control WiFi mac functions and registers

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

This commit provides WiFi mac functions to control wifi easier, and also
provides generic access entries for driver and other modules.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_8822b/halmac_cfg_wmac_8822b.c   |  144 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.h   |   36 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.c |  173 ++
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.h |   32 +
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.c  | 1158 
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.h  |  122 +
 .../halmac/halmac_88xx/halmac_common_88xx.c| 2931 
 .../halmac/halmac_88xx/halmac_common_88xx.h|  151 +
 8 files changed, 4747 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_common_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_common_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_cfg_wmac_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_cfg_wmac_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_common_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_common_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
new file mode 100644
index ..7de83d7bf922
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
@@ -0,0 +1,144 @@
+/**
+ *
+ * Copyright(c) 2017 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_cfg_wmac_8822b.h"
+#include "halmac_8822b_cfg.h"
+
+/**
+ * cfg_drv_info_8822b() - config driver info
+ * @adapter : the adapter of halmac
+ * @drv_info : driver information selection
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+cfg_drv_info_8822b(struct halmac_adapter *adapter,
+  enum halmac_drv_info drv_info)
+{
+   u8 drv_info_size = 0;
+   u8 phy_status_en = 0;
+   u8 sniffer_en = 0;
+   u8 plcp_hdr_en = 0;
+   u8 value8;
+   u32 value32;
+   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG,
+"drv info = %d\n", drv_info);
+
+   switch (drv_info) {
+   case HALMAC_DRV_INFO_NONE:
+   drv_info_size = 0;
+   phy_status_en = 0;
+   sniffer_en = 0;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_STATUS:
+   drv_info_size = 4;
+   phy_status_en = 1;
+   sniffer_en = 0;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_SNIFFER:
+   drv_info_size = 5; /* phy status 4byte, sniffer info 1byte */
+   phy_status_en = 1;
+   sniffer_en = 1;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_PLCP:
+   drv_info_size = 6; /* phy status 4byte, plcp header 2byte */
+   phy_status_en = 1;
+   sniffer_en = 0;
+   plcp_hdr_en = 1;
+   break;
+   default:
+   return HALMAC_RET_SW_CASE_NOT_SUPPORT;
+   }
+
+   if (adapter->txff_alloc.rx_fifo_exp_mode !=
+   HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE)
+   drv_info_size = RX_DESC_DUMMY_SIZE_8822B >> 3;
+
+   HALMAC_REG_W8(REG_RX_DRVINFO_SZ, drv_info_size);
+
+   value8 = HALMAC_REG_R8(REG_TRXFF_BNDY + 1);
+   value8 &= 0xF0;
+   /* For rxdesc len = 0 issue */
+   value8 |= 0xF;
+   

[PATCH v3 09/19] rtlwifi: halmac: add definition of TX/RX descriptor

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

TX/RX descriptor are the headers to describe the packet content.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/halmac/halmac_rx_bd_nic.h  |  36 ++
 .../realtek/rtlwifi/halmac/halmac_rx_desc_chip.h   | 100 +
 .../realtek/rtlwifi/halmac/halmac_rx_desc_nic.h| 123 ++
 .../realtek/rtlwifi/halmac/halmac_tx_bd_nic.h  | 106 +
 .../realtek/rtlwifi/halmac/halmac_tx_desc_chip.h   | 398 +++
 .../realtek/rtlwifi/halmac/halmac_tx_desc_nic.h| 439 +
 6 files changed, 1202 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_bd_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_desc_chip.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_desc_nic.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
new file mode 100644
index ..c03d4d0e4e8a
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
@@ -0,0 +1,36 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_RX_BD_NIC_H_
+#define _HALMAC_RX_BD_NIC_H_
+
+/*TXBD_DW0*/
+
+#define GET_RX_BD_RXFAIL(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 31, 1)
+#define GET_RX_BD_TOTALRXPKTSIZE(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 16, 13)
+#define GET_RX_BD_RXTAG(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 16, 13)
+#define GET_RX_BD_FS(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 15, 1)
+#define GET_RX_BD_LS(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 14, 1)
+#define GET_RX_BD_RXBUFFSIZE(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 0, 14)
+
+/*TXBD_DW1*/
+
+#define GET_RX_BD_PHYSICAL_ADDR_LOW(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x04, 0, 32)
+
+/*TXBD_DW2*/
+
+#define GET_RX_BD_PHYSICAL_ADDR_HIGH(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x08, 0, 32)
+
+#endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
new file mode 100644
index ..3134d3631281
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
@@ -0,0 +1,100 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_RX_DESC_CHIP_H_
+#define _HALMAC_RX_DESC_CHIP_H_
+
+/*RXDESC_WORD0*/
+
+#define GET_RX_DESC_EOR_8822B(rxdesc) GET_RX_DESC_EOR(rxdesc)
+#define GET_RX_DESC_PHYPKTIDC_8822B(rxdesc) GET_RX_DESC_PHYPKTIDC(rxdesc)
+#define GET_RX_DESC_SWDEC_8822B(rxdesc) GET_RX_DESC_SWDEC(rxdesc)
+#define GET_RX_DESC_PHYST_8822B(rxdesc) GET_RX_DESC_PHYST(rxdesc)
+#define GET_RX_DESC_SHIFT_8822B(rxdesc) GET_RX_DESC_SHIFT(rxdesc)
+#define GET_RX_DESC_QOS_8822B(rxdesc) GET_RX_DESC_QOS(rxdesc)
+#define GET_RX_DESC_SECURITY_8822B(rxdesc) GET_RX_DESC_SECURITY(rxdesc)
+#define GET_RX_DESC_DRV_INFO_SIZE_8822B(rxdesc)
\
+   GET_RX_DESC_DRV_INFO_SIZE(rxdesc)
+#define GET_RX_DESC_ICV_ERR_8822B(rxdesc) GET_RX_DESC_ICV_ERR(rxdesc)
+#define GET_RX_DESC_CRC32_8822B(rxdesc) GET_RX_DESC_CRC32(rxdesc)
+#define GET_RX_DESC_PKT_LEN_8822B(rxdesc) GET_RX_DESC_PKT_LEN(rxdesc)
+
+/*RXDESC_WORD1*/
+
+#define GET_RX_DESC_BC_8822B(rxdesc) GET_RX_DESC_BC(rxdesc)
+#define GET_RX_DESC_MC_8822B(rxdesc) GET_RX_DESC_MC(rxdesc)
+#define GET_RX_DESC_TY_PE_8822B(rxdesc) GET_RX_DESC_TY_PE(rxdesc)
+#define GET_RX_DESC_MF_8822B(rxdesc) GET_RX_DESC_MF(rxdesc)
+#define 

[PATCH v3 18/19] rtlwifi: halmac: add to support BB and RF functions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Some BB and RF functions collaborate with firmware or MAC. For instances,
the IQK and PSD functions are implemented in firmware, so use a H2C command
to trigger. For MIMO function, use the helper functions to control related
MAC registers.

Signed-off-by: Ping-Ke Shih 
---
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c | 397 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h |  53 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c  | 869 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h  |  79 ++
 4 files changed, 1398 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
new file mode 100644
index ..06990ee78ebd
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
@@ -0,0 +1,397 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_bb_rf_88xx.h"
+#include "halmac_88xx_cfg.h"
+#include "halmac_common_88xx.h"
+#include "halmac_init_88xx.h"
+
+/**
+ * start_iqk_88xx() -trigger FW IQK
+ * @adapter : the adapter of halmac
+ * @param : IQK parameter
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+start_iqk_88xx(struct halmac_adapter *adapter, struct halmac_iqk_para *param)
+{
+   u8 h2c_buf[H2C_PKT_SIZE_88XX] = { 0 };
+   u16 seq_num = 0;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   struct halmac_h2c_header_info hdr_info;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.iqk_state.proc_status;
+
+   if (halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+
+   if (*proc_status == HALMAC_CMD_PROCESS_SENDING) {
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG,
+"Wait event(iqk)\n");
+   return HALMAC_RET_BUSY_STATE;
+   }
+
+   *proc_status = HALMAC_CMD_PROCESS_SENDING;
+
+   IQK_SET_CLEAR(h2c_buf, param->clear);
+   IQK_SET_SEGMENT_IQK(h2c_buf, param->segment_iqk);
+
+   hdr_info.sub_cmd_id = SUB_CMD_ID_IQK;
+   hdr_info.content_size = 1;
+   hdr_info.ack = 1;
+   set_h2c_pkt_hdr_88xx(adapter, h2c_buf, _info, _num);
+
+   adapter->halmac_state.iqk_state.seq_num = seq_num;
+
+   status = send_h2c_pkt_88xx(adapter, h2c_buf);
+
+   if (status != HALMAC_RET_SUCCESS) {
+   pr_err("send h2c pkt fail!!\n");
+   reset_ofld_feature_88xx(adapter, HALMAC_FEATURE_IQK);
+   return status;
+   }
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s <===\n",
+__func__);
+
+   return HALMAC_RET_SUCCESS;
+}
+
+/**
+ * ctrl_pwr_tracking_88xx() -trigger FW power tracking
+ * @adapter : the adapter of halmac
+ * @opt : power tracking option
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+ctrl_pwr_tracking_88xx(struct halmac_adapter *adapter,
+  struct halmac_pwr_tracking_option *opt)
+{
+   u8 h2c_buf[H2C_PKT_SIZE_88XX] = { 0 };
+   u16 seq_num = 0;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   struct halmac_h2c_header_info hdr_info;
+   struct halmac_pwr_tracking_para *param;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.pwr_trk_state.proc_status;
+
+   if (halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   

[PATCH v3 10/19] rtlwifi: halmac: add GPIO pin/pinmux definitions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

GPIO with pinmux can switch to many functions such as LED, UART, JTAG,
WoWLAN, etc.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.c   | 847 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.h   |  34 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c  | 415 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h  |  55 ++
 .../realtek/rtlwifi/halmac/halmac_gpio_cmd.h   |  84 ++
 5 files changed, 1435 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_gpio_cmd.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
new file mode 100644
index ..3d43de98bb46
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
@@ -0,0 +1,847 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_gpio_8822b.h"
+#include "../halmac_gpio_88xx.h"
+
+/* GPIO0 definition */
+#define GPIO0_BT_GPIO0_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO0_BT_ACT_8822B \
+   {HALMAC_BT_PTA, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x41, BIT(1), 0}
+#define GPIO0_WL_ACT_8822B \
+   {HALMAC_WL_PTA, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO0_WLMAC_DBG_GPIO0_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO0, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO0_WLPHY_DBG_GPIO0_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO0_BT_DBG_GPIO0_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO0, HALMAC_GPIO_OUT, \
+   0x40, BIT(1) | BIT(0), BIT(0) | BIT(1)}
+#define GPIO0_SW_IO_8822B  \
+   {HALMAC_SW_IO, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), 0}
+
+/* GPIO1 definition */
+#define GPIO1_BT_GPIO1_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO1_BT_3DD_SYNC_A_8822B  \
+   {HALMAC_BT_3DDLS_A, HALMAC_GPIO1, HALMAC_GPIO_IN, \
+0x66, BIT(2), BIT(2)}
+#define GPIO1_WL_CK_8822B  \
+   {HALMAC_BT_PTA, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x41, BIT(1), 0}
+#define GPIO1_BT_CK_8822B  \
+   {HALMAC_WL_PTA, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO1_WLMAC_DBG_GPIO1_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO1_WLPHY_DBG_GPIO1_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO1_BT_DBG_GPIO1_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0) | BIT(1)}
+#define GPIO1_SW_IO_8822B  \
+   {HALMAC_SW_IO, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), 0}
+
+/* GPIO2 definition */
+#define GPIO2_BT_GPIO2_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO2, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO2_WL_STATE_8822B   \
+   {HALMAC_BT_PTA, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x41, BIT(1), 0}
+#define GPIO2_BT_STATE_8822B   \
+   {HALMAC_WL_PTA, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO2_WLMAC_DBG_GPIO2_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO2_WLPHY_DBG_GPIO2_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO2, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO2_BT_DBG_GPIO2_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO2, 

[PATCH v3 14/19] rtlwifi: halmac: add halmac init/deinit functions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Add files to initialize and free halmac context. Since halmac is an three
levels hierarchy file structure, so the added files provide interfaces of
halmac, 88xx and 8822b.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.c   |  688 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.h   |   33 +
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c  | 1071 
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h  |   70 ++
 .../wireless/realtek/rtlwifi/halmac/halmac_api.c   |  438 
 .../wireless/realtek/rtlwifi/halmac/halmac_api.h   |   65 ++
 6 files changed, 2365 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_api.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_api.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
new file mode 100644
index ..57509fd5942a
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
@@ -0,0 +1,688 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_init_8822b.h"
+#include "halmac_8822b_cfg.h"
+#include "halmac_pcie_8822b.h"
+#include "halmac_sdio_8822b.h"
+#include "halmac_usb_8822b.h"
+#include "halmac_gpio_8822b.h"
+#include "halmac_common_8822b.h"
+#include "halmac_cfg_wmac_8822b.h"
+#include "../halmac_common_88xx.h"
+#include "../halmac_init_88xx.h"
+
+#define RSVD_PG_DRV_NUM16
+#define RSVD_PG_H2C_EXTRAINFO_NUM  24
+#define RSVD_PG_H2C_STATICINFO_NUM 8
+#define RSVD_PG_H2CQ_NUM   8
+#define RSVD_PG_CPU_INSTRUCTION_NUM0
+#define RSVD_PG_FW_TXBUF_NUM   4
+#define RSVD_PG_CSIBUF_NUM 0
+#define RSVD_PG_DLLB_NUM   (TX_FIFO_SIZE_8822B / 3 >> \
+   TX_PAGE_SIZE_SHIFT_88XX)
+
+#define MAC_TRX_ENABLE (BIT_HCI_TXDMA_EN | BIT_HCI_RXDMA_EN | BIT_TXDMA_EN | \
+   BIT_RXDMA_EN | BIT_PROTOCOL_EN | BIT_SCHEDULE_EN | \
+   BIT_MACTXEN | BIT_MACRXEN)
+
+#define BLK_DESC_NUM   0x3
+
+#define WLAN_AMPDU_MAX_TIME0x70
+#define WLAN_RTS_LEN_TH0xFF
+#define WLAN_RTS_TX_TIME_TH0x08
+#define WLAN_MAX_AGG_PKT_LIMIT 0x20
+#define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x20
+#define WALN_FAST_EDCA_VO_TH   0x06
+#define WLAN_FAST_EDCA_VI_TH   0x06
+#define WLAN_FAST_EDCA_BE_TH   0x06
+#define WLAN_FAST_EDCA_BK_TH   0x06
+#define WLAN_BAR_RETRY_LIMIT   0x01
+#define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08
+
+/*SDIO RQPN Mapping*/
+static struct halmac_rqpn HALMAC_RQPN_SDIO_8822B[] = {
+   /* { mode, vo_map, vi_map, be_map, bk_map, mg_map, hi_map } */
+   {HALMAC_TRX_MODE_NORMAL,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_TRXSHARE,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_WMM,
+HALMAC_MAP2_HQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_NQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_P2P,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_LOOPBACK,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_DELAY_LOOPBACK,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+};
+
+/*PCIE RQPN Mapping*/
+static struct halmac_rqpn HALMAC_RQPN_PCIE_8822B[] 

[PATCH v3 11/19] rtlwifi: halmac: add power sequence to turn on/off wifi card

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Define power sequence command, and fill the sequences of 8822b.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_8822b/halmac_pwr_seq_8822b.c| 396 +
 .../halmac_8822b/halmac_pwr_seq_8822b.h|  26 ++
 .../realtek/rtlwifi/halmac/halmac_pwr_seq_cmd.h|  98 +
 3 files changed, 520 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_pwr_seq_cmd.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
new file mode 100644
index ..5aab588eb094
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
@@ -0,0 +1,396 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_pwr_seq_8822b.h"
+
+static struct halmac_wlan_pwr_cfg TRANS_CARDDIS_TO_CARDEMU_8822B[] = {
+   /* { offset, cut_msk, interface_msk, base|cmd, msk, value } */
+   {0x0086,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_SDIO,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0x0086,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_SDIO,
+HALMAC_PWR_CMD_POLLING, BIT(1), BIT(1)},
+   {0x004A,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0x0005,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(3) | BIT(4) | BIT(7), 0},
+   {0x0300,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x0301,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+0,
+HALMAC_PWR_CMD_END, 0, 0},
+};
+
+static struct halmac_wlan_pwr_cfg TRANS_CARDEMU_TO_ACT_8822B[] = {
+   /* { offset, cut_msk, interface_msk, base|cmd, msk, value } */
+   {0x0012,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(1), 0},
+   {0x0012,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0020,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0001,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_DELAY, 1, HALMAC_PWR_DELAY_MS},
+   {0x,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(5), 0},
+   {0x0005,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0},
+   {0x0075,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0006,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_POLLING, BIT(1), BIT(1)},
+   {0x0075,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0xFF1A,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x0006,
+HALMAC_PWR_CUT_ALL_MSK,
+

[PATCH v3 01/19] rtlwifi: add halmac structure to wifi.h

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Add structure and ops to interact with halmac and other modules.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 58 +
 1 file changed, 58 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index d27e33960e77..c8542b87cc2b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2305,6 +2305,13 @@ struct rtl_hal_ops {
u16 (*get_available_desc)(struct ieee80211_hw *hw, u8 q_idx);
void (*c2h_content_parsing)(struct ieee80211_hw *hw, u8 tag, u8 len,
u8 *val);
+   /* ops for halmac cb */
+   bool (*halmac_cb_init_mac_register)(struct rtl_priv *rtlpriv);
+   bool (*halmac_cb_init_bb_rf_register)(struct rtl_priv *rtlpriv);
+   bool (*halmac_cb_write_data_rsvd_page)(struct rtl_priv *rtlpriv,
+  u8 *buf, u32 size);
+   bool (*halmac_cb_write_data_h2c)(struct rtl_priv *rtlpriv, u8 *buf,
+u32 size);
 };
 
 struct rtl_intf_ops {
@@ -2687,6 +2694,54 @@ struct rtl_btc_ops {
bool (*btc_is_bt_lps_on)(struct rtl_priv *rtlpriv);
 };
 
+struct rtl_halmac_ops {
+   int (*halmac_init_adapter)(struct rtl_priv *rtlpriv);
+   int (*halmac_deinit_adapter)(struct rtl_priv *rtlpriv);
+   int (*halmac_init_hal)(struct rtl_priv *rtlpriv);
+   int (*halmac_deinit_hal)(struct rtl_priv *rtlpriv);
+   int (*halmac_poweron)(struct rtl_priv *rtlpriv);
+   int (*halmac_poweroff)(struct rtl_priv *rtlpriv);
+
+   int (*halmac_phy_power_switch)(struct rtl_priv *rtlpriv, u8 enable);
+   int (*halmac_set_mac_address)(struct rtl_priv *rtlpriv, u8 hwport,
+ u8 *addr);
+   int (*halmac_set_bssid)(struct rtl_priv *rtlpriv, u8 hwport, u8 *addr);
+
+   int (*halmac_get_physical_efuse_size)(struct rtl_priv *rtlpriv,
+ u32 *size);
+   int (*halmac_read_physical_efuse_map)(struct rtl_priv *rtlpriv,
+ u8 *map, u32 size);
+   int (*halmac_get_logical_efuse_size)(struct rtl_priv *rtlpriv,
+u32 *size);
+   int (*halmac_read_logical_efuse_map)(struct rtl_priv *rtlpriv, u8 *map,
+u32 size);
+
+   int (*halmac_set_bandwidth)(struct rtl_priv *rtlpriv, u8 channel,
+   u8 pri_ch_idx, u8 bw);
+
+   int (*halmac_c2h_handle)(struct rtl_priv *rtlpriv, u8 *c2h, u32 size);
+
+   int (*halmac_chk_txdesc)(struct rtl_priv *rtlpriv, u8 *txdesc,
+u32 size);
+   int (*halmac_iqk)(struct rtl_priv *rtlpriv, u8 clear, u8 segment);
+};
+
+struct rtl_halmac_indicator {
+   struct completion *comp;
+   u32 wait_ms;
+
+   u8 *buffer;
+   u32 buf_size;
+   u32 ret_size;
+   u32 status;
+};
+
+struct rtl_halmac {
+   const struct rtl_halmac_ops *ops;
+   void *internal; /* internal context of halmac, i.e. PHALMAC_ADAPTER */
+   struct rtl_halmac_indicator *indicator; /* size=10 */
+};
+
 struct proxim {
bool proxim_on;
 
@@ -2792,6 +2847,9 @@ struct rtl_priv {
/*for bt coexist use*/
struct bt_coexist_info btcoexist;
 
+   /* halmac for newer ICs */
+   struct rtl_halmac halmac;
+
/* separate 92ee from other ICs,
 * 92ee use new trx flow.
 */
-- 
2.15.1



[PATCH v3 06/19] rtlwifi: halmac: add register definitions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

List all MAC registers including rtl8822b.

Signed-off-by: Ping-Ke Shih 
---
 .../wireless/realtek/rtlwifi/halmac/halmac_reg2.h  | 1292 
 .../realtek/rtlwifi/halmac/halmac_reg_8822b.h  |  733 +++
 2 files changed, 2025 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_reg2.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_reg_8822b.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_reg2.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_reg2.h
new file mode 100644
index ..68cda8251d8a
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_reg2.h
@@ -0,0 +1,1292 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef __HALMAC_COM_REG_H__
+#define __HALMAC_COM_REG_H__
+
+#define REG_SYS_ISO_CTRL 0x
+
+#define REG_SDIO_TX_CTRL 0x1025
+
+#define REG_SYS_FUNC_EN 0x0002
+#define REG_SYS_PW_CTRL 0x0004
+
+#define REG_SYS_CLK_CTRL 0x0008
+
+#define REG_SYS_EEPROM_CTRL 0x000A
+#define REG_EE_VPD 0x000C
+
+#define REG_SYS_SWR_CTRL1 0x0010
+#define REG_SYS_SWR_CTRL2 0x0014
+
+#define REG_SDIO_HIMR 0x10250014
+
+#define REG_SYS_SWR_CTRL3 0x0018
+
+#define REG_SDIO_HISR 0x10250018
+
+#define REG_RSV_CTRL 0x001C
+
+#define REG_SDIO_RX_REQ_LEN 0x1025001C
+
+#define REG_RF_CTRL 0x001F
+
+#define REG_SDIO_FREE_TXPG_SEQ_V1 0x1025001F
+
+#define REG_AFE_LDO_CTRL 0x0020
+
+#define REG_SDIO_FREE_TXPG 0x10250020
+
+#define REG_AFE_CTRL1 0x0024
+
+#define REG_SDIO_FREE_TXPG2 0x10250024
+
+#define REG_AFE_CTRL2 0x0028
+
+#define REG_SDIO_OQT_FREE_TXPG_V1 0x10250028
+
+#define REG_AFE_CTRL3 0x002C
+
+#define REG_EFUSE_CTRL 0x0030
+
+#define REG_SDIO_HTSFR_INFO 0x10250030
+
+#define REG_LDO_EFUSE_CTRL 0x0034
+#define REG_PWR_OPTION_CTRL 0x0038
+
+#define REG_SDIO_HCPWM1_V2 0x10250038
+#define REG_SDIO_HCPWM2_V2 0x1025003A
+
+#define REG_CAL_TIMER 0x003C
+#define REG_ACLK_MON 0x003E
+
+#define REG_GPIO_MUXCFG 0x0040
+
+#define REG_SDIO_INDIRECT_REG_CFG 0x10250040
+
+#define REG_GPIO_PIN_CTRL 0x0044
+
+#define REG_SDIO_INDIRECT_REG_DATA 0x10250044
+
+#define REG_GPIO_INTM 0x0048
+#define REG_LED_CFG 0x004C
+#define REG_FSIMR 0x0050
+#define REG_FSISR 0x0054
+#define REG_HSIMR 0x0058
+#define REG_HSISR 0x005C
+#define REG_GPIO_EXT_CTRL 0x0060
+
+#define REG_SDIO_H2C 0x10250060
+
+#define REG_PAD_CTRL1 0x0064
+
+#define REG_SDIO_C2H 0x10250064
+
+#define REG_WL_BT_PWR_CTRL 0x0068
+
+#define REG_SDM_DEBUG 0x006C
+
+#define REG_SYS_SDIO_CTRL 0x0070
+
+#define REG_HCI_OPT_CTRL 0x0074
+
+#define REG_AFE_CTRL4 0x0078
+
+#define REG_LDO_SWR_CTRL 0x007C
+
+#define REG_MCUFW_CTRL 0x0080
+
+#define REG_SDIO_HRPWM1 0x10250080
+#define REG_SDIO_HRPWM2 0x10250082
+
+#define REG_MCU_TST_CFG 0x0084
+
+#define REG_SDIO_HPS_CLKR 0x10250084
+#define REG_SDIO_BUS_CTRL 0x10250085
+
+#define REG_SDIO_HSUS_CTRL 0x10250086
+
+#define REG_HMEBOX_E0_E1 0x0088
+
+#define REG_SDIO_RESPONSE_TIMER 0x10250088
+
+#define REG_SDIO_CMD_CRC 0x1025008A
+
+#define REG_HMEBOX_E2_E3 0x008C
+#define REG_WLLPS_CTRL 0x0090
+
+#define REG_SDIO_HSISR 0x10250090
+
+#define REG_AFE_CTRL5 0x0094
+
+#define REG_GPIO_DEBOUNCE_CTRL 0x0098
+#define REG_RPWM2 0x009C
+#define REG_SYSON_FSM_MON 0x00A0
+
+#define REG_AFE_CTRL6 0x00A4
+
+#define REG_PMC_DBG_CTRL1 0x00A8
+
+#define REG_AFE_CTRL7 0x00AC
+
+#define REG_HIMR0 0x00B0
+#define REG_HISR0 0x00B4
+#define REG_HIMR1 0x00B8
+#define REG_HISR1 0x00BC
+#define REG_DBG_PORT_SEL 0x00C0
+
+#define REG_SDIO_ERR_RPT 0x102500C0
+
+#define REG_SDIO_CMD_ERRCNT 0x102500C2
+#define REG_SDIO_DATA_ERRCNT 0x102500C3
+
+#define REG_PAD_CTRL2 0x00C4
+
+#define REG_SDIO_CMD_ERR_CONTENT 0x102500C4
+
+#define REG_SDIO_CRC_ERR_IDX 0x102500C9
+
+#define REG_SDIO_DATA_CRC 0x102500CA
+
+#define REG_SDIO_DATA_REPLY_TIME 0x102500CB
+
+#define REG_PMC_DBG_CTRL2 0x00CC
+
+#define REG_BIST_CTRL 0x00D0
+#define REG_BIST_RPT 0x00D4
+
+#define REG_MEM_CTRL 0x00D8
+
+#define REG_AFE_CTRL8 0x00DC
+
+#define REG_USB_SIE_INTF 0x00E0
+
+#define REG_PCIE_MIO_INTF 0x00E4
+#define REG_PCIE_MIO_INTD 0x00E8
+
+#define REG_WLRF1 0x00EC
+
+#define REG_SYS_CFG1 0x00F0
+#define REG_SYS_STATUS1 0x00F4
+#define REG_SYS_STATUS2 0x00F8
+#define REG_SYS_CFG2 0x00FC
+#define REG_CR 0x0100
+
+#define REG_TSF_CLK_STATE 0x0108
+#define 

[PATCH v3 13/19] rtlwifi: halmac: add files to implement halmac ops

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

The structure halmac_ops defined in wifi.h, and this commit implements and
hooks ops to the structure, so a symbol rtl_halmac_get_ops_pointer is
expoerted to access this module. Meanwhile, we implement ops defined and
needed by this module.

Signed-off-by: Ping-Ke Shih 
---
 .../wireless/realtek/rtlwifi/halmac/rtl_halmac.c   | 1403 
 .../wireless/realtek/rtlwifi/halmac/rtl_halmac.h   |   77 ++
 2 files changed, 1480 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
new file mode 100644
index ..d9b81824728d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
@@ -0,0 +1,1403 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_api.h"
+#include "rtl_halmac.h"
+#include 
+#include 
+
+#define rtlpriv_to_halmac(priv)
\
+   ((struct halmac_adapter *)((priv)->halmac.internal))
+
+#define DEFAULT_INDICATOR_TIMELMT msecs_to_jiffies(1000) /* ms */
+
+const struct rtl_halmac_ops rtl_halmac_operation = {
+   .halmac_init_adapter = rtl_halmac_init_adapter,
+   .halmac_deinit_adapter = rtl_halmac_deinit_adapter,
+   .halmac_init_hal = rtl_halmac_init_hal,
+   .halmac_deinit_hal = rtl_halmac_deinit_hal,
+   .halmac_poweron = rtl_halmac_poweron,
+   .halmac_poweroff = rtl_halmac_poweroff,
+
+   .halmac_phy_power_switch = rtl_halmac_phy_power_switch,
+   .halmac_set_mac_address = rtl_halmac_set_mac_address,
+   .halmac_set_bssid = rtl_halmac_set_bssid,
+
+   .halmac_get_physical_efuse_size = rtl_halmac_get_physical_efuse_size,
+   .halmac_read_physical_efuse_map = rtl_halmac_read_physical_efuse_map,
+   .halmac_get_logical_efuse_size = rtl_halmac_get_logical_efuse_size,
+   .halmac_read_logical_efuse_map = rtl_halmac_read_logical_efuse_map,
+
+   .halmac_set_bandwidth = rtl_halmac_set_bandwidth,
+
+   .halmac_c2h_handle = rtl_halmac_c2h_handle,
+
+   .halmac_chk_txdesc = rtl_halmac_chk_txdesc,
+   .halmac_iqk = rtl_halmac_iqk,
+};
+EXPORT_SYMBOL(rtl_halmac_operation);
+
+enum pltfm_ret_status {
+   FLTFM_RET_FAIL = 0,
+   FLTFM_RET_SUCCESS = 1,
+};
+
+static u8 _halmac_reg_read_8(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_byte(rtlpriv, offset);
+}
+
+static u16 _halmac_reg_read_16(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_word(rtlpriv, offset);
+}
+
+static u32 _halmac_reg_read_32(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_dword(rtlpriv, offset);
+}
+
+static void _halmac_reg_write_8(void *p, u32 offset, u8 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_byte(rtlpriv, offset, val);
+}
+
+static void _halmac_reg_write_16(void *p, u32 offset, u16 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_word(rtlpriv, offset, val);
+}
+
+static void _halmac_reg_write_32(void *p, u32 offset, u32 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_dword(rtlpriv, offset, val);
+}
+
+static u8 _halmac_write_data_rsvd_page(void *p, u8 *buf, u32 size)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   if (rtlpriv->cfg->ops->halmac_cb_write_data_rsvd_page &&
+   rtlpriv->cfg->ops->halmac_cb_write_data_rsvd_page(rtlpriv, buf,
+ size))
+   return FLTFM_RET_SUCCESS;
+
+   return FLTFM_RET_FAIL;
+}
+
+static u8 _halmac_write_data_h2c(void *p, u8 *buf, u32 size)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   if (rtlpriv->cfg->ops->halmac_cb_write_data_h2c &&
+   rtlpriv->cfg->ops->halmac_cb_write_data_h2c(rtlpriv, buf, size))
+   return FLTFM_RET_SUCCESS;
+
+   return FLTFM_RET_FAIL;
+}
+
+static const char *const RTL_HALMAC_FEATURE_NAME[] = {
+   

[PATCH v3 02/19] rtlwifi: add debug ID COMP_HALMAC

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Add a debug ID for the module halmac

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/debug.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.h 
b/drivers/net/wireless/realtek/rtlwifi/debug.h
index ad6834af618b..90c41c17d678 100644
--- a/drivers/net/wireless/realtek/rtlwifi/debug.h
+++ b/drivers/net/wireless/realtek/rtlwifi/debug.h
@@ -106,6 +106,7 @@
 #define COMP_BT_COEXISTBIT(30)
 #define COMP_IQK   BIT(31)
 #define COMP_TX_REPORT BIT_ULL(32)
+#define COMP_HALMACBIT_ULL(33)
 
 /*--
Define the rt_print components
-- 
2.15.1



[PATCH v3 05/19] rtlwifi: halmac: describe number and size of chip functions

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

The number and size of chip fucntions are different, such as TX/RX FIFO
size, efuse size, etc. So they are defined in an individual file.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_8822b_cfg.h| 68 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h   | 40 +
 2 files changed, 108 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
new file mode 100644
index ..f6ed7b44549c
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
@@ -0,0 +1,68 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_8822B_CFG_H_
+#define _HALMAC_8822B_CFG_H_
+
+#include "../halmac_88xx_cfg.h"
+
+#define TX_FIFO_SIZE_8822B 262144
+#define RX_FIFO_SIZE_8822B 24576
+#define TRX_SHARE_SIZE_8822B   65536
+
+#define RX_DESC_DUMMY_SIZE_8822B   72 /* 8 * 9 Bytes */
+#define RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B  80 /* 8 Byte alignment*/
+
+/* should be 8 Byte alignment*/
+#if (HALMAC_RX_FIFO_EXPANDING_MODE_PKT_SIZE <= \
+   RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B)
+#define RX_FIFO_EXPANDING_UNIT_8822B   (RX_DESC_SIZE_88XX + \
+   RX_DESC_DUMMY_SIZE_8822B + HALMAC_RX_FIFO_EXPANDING_MODE_PKT_SIZE)
+#else
+#define RX_FIFO_EXPANDING_UNIT_8822B (RX_DESC_SIZE_88XX + \
+   RX_DESC_DUMMY_SIZE_8822B + RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B)
+#endif
+
+#define TX_FIFO_SIZE_LA_8822B  (TX_FIFO_SIZE_8822B >>  1)
+#define TX_FIFO_SIZE_RX_EXPAND_1BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - TRX_SHARE_SIZE_8822B)
+#define RX_FIFO_SIZE_RX_EXPAND_1BLK_8822B  \
+   RX_FIFO_EXPANDING_UNIT_8822B << 8) - 1) >> 10) << 10)
+#define TX_FIFO_SIZE_RX_EXPAND_2BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - (2 * TRX_SHARE_SIZE_8822B))
+#define RX_FIFO_SIZE_RX_EXPAND_2BLK_8822B  \
+   (RX_FIFO_SIZE_8822B +  (2 * TRX_SHARE_SIZE_8822B))
+#define TX_FIFO_SIZE_RX_EXPAND_3BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - (3 * TRX_SHARE_SIZE_8822B))
+#define RX_FIFO_SIZE_RX_EXPAND_3BLK_8822B  \
+   (RX_FIFO_SIZE_8822B +  (3 * TRX_SHARE_SIZE_8822B))
+
+#define EFUSE_SIZE_8822B   1024
+#define EEPROM_SIZE_8822B  768
+#define BT_EFUSE_SIZE_8822B128
+
+#define SEC_CAM_NUM_8822B  64
+
+#define OQT_ENTRY_AC_8822B 32
+#define OQT_ENTRY_NOAC_8822B   32
+#define MACID_MAX_8822B128
+
+#define WLAN_FW_IRAM_MAX_SIZE_8822B196608
+#define WLAN_FW_DRAM_MAX_SIZE_8822B49152
+#define WLAN_FW_ERAM_MAX_SIZE_8822B0
+#define WLAN_FW_MAX_SIZE_8822B (WLAN_FW_IRAM_MAX_SIZE_8822B + \
+   WLAN_FW_DRAM_MAX_SIZE_8822B + WLAN_FW_ERAM_MAX_SIZE_8822B)
+
+#endif
diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h
new file mode 100644
index ..22514ef4680d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_88XX_CFG_H_
+#define _HALMAC_88XX_CFG_H_
+
+#include "../halmac_api.h"
+
+#define TX_PAGE_SIZE_88XX

[PATCH v3 00/19] rtlwifi: halmac: Add new module halmac

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

v3: patch 06/17 in v2 is too big, so mail server may block the mail.
In this patchset, I decompose the patch into three patches 06/19-08/19,
so in patchset view v2 and v3 are identical.

v2: remove indirection to get halmac ops
Only patches 1/17 and 11/17 are changed.

Patches 1/19-3/19 are added structure to support this module.
Patches 4/19-18/19 add new files.
Patch 19/19 add this module to Makefile and Kconfig.

Ping-Ke Shih (19):
  rtlwifi: add halmac structure to wifi.h
  rtlwifi: add debug ID COMP_HALMAC
  rtlwifi: add dmdef.h to share with driver and other modules
  rtlwifi: halmac: add main definition used by halmac
  rtlwifi: halmac: describe number and size of chip functions
  rtlwifi: halmac: add register definitions
  rtlwifi: halmac: add bit field definitions
  rtlwifi: halmac: add bit field definitions of rtl8822b
  rtlwifi: halmac: add definition of TX/RX descriptor
  rtlwifi: halmac: add GPIO pin/pinmux definitions
  rtlwifi: halmac: add power sequence to turn on/off wifi card
  rtlwifi: halmac: access efuse through halmac helper functions
  rtlwifi: halmac: add files to implement halmac ops
  rtlwifi: halmac: add halmac init/deinit functions
  rtlwifi: halmac: add firmware related functions and definitions
  rtlwifi: halmac: add bus interface commands
  rtlwifi: halmac: add to control WiFi mac functions and registers
  rtlwifi: halmac: add to support BB and RF functions
  rtlwifi: add halmac to Makefile and Kconfig

 drivers/net/wireless/realtek/rtlwifi/Kconfig   | 5 +
 drivers/net/wireless/realtek/rtlwifi/Makefile  | 1 +
 drivers/net/wireless/realtek/rtlwifi/debug.h   | 1 +
 drivers/net/wireless/realtek/rtlwifi/dmdef.h   |40 +
 .../net/wireless/realtek/rtlwifi/halmac/Makefile   |29 +
 .../halmac_88xx/halmac_8822b/halmac_8822b_cfg.h|68 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.c   |   144 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.h   |36 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.c |   173 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.h |32 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.c   |   847 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.h   |34 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.c   |   688 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.h   |33 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.c   |   218 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.h   |38 +
 .../halmac_88xx/halmac_8822b/halmac_phy_8822b.c|   148 +
 .../halmac_8822b/halmac_pwr_seq_8822b.c|   396 +
 .../halmac_8822b/halmac_pwr_seq_8822b.h|26 +
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.c   |   880 +
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.h   |62 +
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.c|   161 +
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.h|38 +
 .../rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h   |40 +
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c |   397 +
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h |53 +
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.c  |  1158 ++
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.h  |   122 +
 .../halmac/halmac_88xx/halmac_common_88xx.c|  2931 +++
 .../halmac/halmac_88xx/halmac_common_88xx.h|   151 +
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c |  1918 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h |   101 +
 .../rtlwifi/halmac/halmac_88xx/halmac_flash_88xx.c |   316 +
 .../rtlwifi/halmac/halmac_88xx/halmac_flash_88xx.h |35 +
 .../rtlwifi/halmac/halmac_88xx/halmac_fw_88xx.c|  1149 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_fw_88xx.h|57 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c  |   415 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h  |55 +
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c  |  1071 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h  |70 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c  |   869 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h  |79 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c  |   538 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h  |98 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c  |   895 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h  |75 +
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c   |   522 +
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h   |83 +
 .../wireless/realtek/rtlwifi/halmac/halmac_api.c   |   438 +
 .../wireless/realtek/rtlwifi/halmac/halmac_api.h   |65 +
 .../wireless/realtek/rtlwifi/halmac/halmac_bit2.h  | 18234 +++
 .../realtek/rtlwifi/halmac/halmac_bit_8822b.h  | 17870 ++
 .../realtek/rtlwifi/halmac/halmac_fw_info.h|   119 +
 .../rtlwifi/halmac/halmac_fw_offload_c2h_nic.h |   371 +
 .../rtlwifi/halmac/halmac_fw_offload_h2c_nic.h |   694 +
 

[PATCH v3 04/19] rtlwifi: halmac: add main definition used by halmac

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

The files contain main definition of struct, enum, prototypes,
state machine, etc.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/halmac/halmac_state_machine.h  |  157 ++
 .../wireless/realtek/rtlwifi/halmac/halmac_type.h  | 2134 
 2 files changed, 2291 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_type.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
new file mode 100644
index ..d6cce79a460d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
@@ -0,0 +1,157 @@
+/**
+ *
+ * Copyright(c) 2017 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_STATE_MACHINE_H_
+#define _HALMAC_STATE_MACHINE_H_
+
+enum halmac_dlfw_state {
+   HALMAC_DLFW_NONE = 0,
+   HALMAC_DLFW_DONE = 1,
+   HALMAC_GEN_INFO_SENT = 2,
+
+   /* Data CPU firmware download framework */
+   HALMAC_DLFW_INIT = 0x11,
+   HALMAC_DLFW_START = 0x12,
+   HALMAC_DLFW_CONF_READY = 0x13,
+   HALMAC_DLFW_CPU_READY = 0x14,
+   HALMAC_DLFW_MEM_READY = 0x15,
+   HALMAC_DLFW_SW_READY = 0x16,
+   HALMAC_DLFW_OFLD_READY = 0x17,
+
+   HALMAC_DLFW_UNDEFINED = 0x7F,
+};
+
+enum halmac_gpio_cfg_state {
+   HALMAC_GPIO_CFG_STATE_IDLE = 0,
+   HALMAC_GPIO_CFG_STATE_BUSY = 1,
+   HALMAC_GPIO_CFG_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_rsvd_pg_state {
+   HALMAC_RSVD_PG_STATE_IDLE = 0,
+   HALMAC_RSVD_PG_STATE_BUSY = 1,
+   HALMAC_RSVD_PG_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_api_state {
+   HALMAC_API_STATE_INIT = 0,
+   HALMAC_API_STATE_HALT = 1,
+   HALMAC_API_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_cmd_construct_state {
+   HALMAC_CMD_CNSTR_IDLE = 0,
+   HALMAC_CMD_CNSTR_BUSY = 1,
+   HALMAC_CMD_CNSTR_H2C_SENT = 2,
+   HALMAC_CMD_CNSTR_CNSTR = 3,
+   HALMAC_CMD_CNSTR_BUF_CLR = 4,
+   HALMAC_CMD_CNSTR_UNDEFINED = 0x7F,
+};
+
+enum halmac_cmd_process_status {
+   HALMAC_CMD_PROCESS_IDLE = 0x01, /* Init status */
+   HALMAC_CMD_PROCESS_SENDING = 0x02, /* Wait ack */
+   HALMAC_CMD_PROCESS_RCVD = 0x03, /* Rcvd ack */
+   HALMAC_CMD_PROCESS_DONE = 0x04, /* Event done */
+   HALMAC_CMD_PROCESS_ERROR = 0x05, /* Return code error */
+   HALMAC_CMD_PROCESS_UNDEFINE = 0x7F,
+};
+
+enum halmac_mac_power {
+   HALMAC_MAC_POWER_OFF = 0x0,
+   HALMAC_MAC_POWER_ON = 0x1,
+   HALMAC_MAC_POWER_UNDEFINE = 0x7F,
+};
+
+enum halmac_wlcpu_mode {
+   HALMAC_WLCPU_ACTIVE = 0x0,
+   HALMAC_WLCPU_ENTER_SLEEP = 0x1,
+   HALMAC_WLCPU_SLEEP = 0x2,
+   HALMAC_WLCPU_UNDEFINE = 0x7F,
+};
+
+struct halmac_efuse_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_cfg_param_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_scan_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_update_pkt_state {
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_iqk_state {
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_pwr_tracking_state {
+   enum halmac_cmd_process_status  proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_psd_state {
+   enum halmac_cmd_process_status proc_status;
+   u16 data_size;
+   u16 seg_size;
+   u8 *data;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_fw_snding_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_state {
+   struct halmac_efuse_state efuse_state;
+   struct halmac_cfg_param_state cfg_param_state;
+   struct halmac_scan_state scan_state;
+   

[PATCH v3 19/19] rtlwifi: add halmac to Makefile and Kconfig

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

Add halmac to Makefile and Kconfig, so we can build this module if 8822BE
is selected.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/Kconfig   |  5 
 drivers/net/wireless/realtek/rtlwifi/Makefile  |  1 +
 .../net/wireless/realtek/rtlwifi/halmac/Makefile   | 29 ++
 3 files changed, 35 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/Makefile

diff --git a/drivers/net/wireless/realtek/rtlwifi/Kconfig 
b/drivers/net/wireless/realtek/rtlwifi/Kconfig
index 73067cac289c..d9aba8fed151 100644
--- a/drivers/net/wireless/realtek/rtlwifi/Kconfig
+++ b/drivers/net/wireless/realtek/rtlwifi/Kconfig
@@ -151,4 +151,9 @@ config RTLBTCOEXIST
depends on RTL8723AE || RTL8723BE || RTL8821AE || RTL8192EE
default y
 
+config RTLHALMAC
+   tristate
+   depends on RTL8822BE
+   default y
+
 endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/Makefile
index 09c30e428375..a30a73c351d8 100644
--- a/drivers/net/wireless/realtek/rtlwifi/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_RTL8723AE)   += rtl8723ae/
 obj-$(CONFIG_RTL8723BE)+= rtl8723be/
 obj-$(CONFIG_RTL8188EE)+= rtl8188ee/
 obj-$(CONFIG_RTLBTCOEXIST) += btcoexist/
+obj-$(CONFIG_RTLHALMAC)+= halmac/
 obj-$(CONFIG_RTL8723_COMMON)   += rtl8723com/
 obj-$(CONFIG_RTL8821AE)+= rtl8821ae/
 obj-$(CONFIG_RTL8192EE)+= rtl8192ee/
diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile
new file mode 100644
index ..41c1ae7e5e53
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile
@@ -0,0 +1,29 @@
+
+
+halmac-objs := \
+   halmac_api.o\
+   halmac_88xx/halmac_bb_rf_88xx.o \
+   halmac_88xx/halmac_efuse_88xx.o \
+   halmac_88xx/halmac_gpio_88xx.o  \
+   halmac_88xx/halmac_pcie_88xx.o  \
+   halmac_88xx/halmac_sdio_88xx.o  \
+   halmac_88xx/halmac_usb_88xx.o   \
+   halmac_88xx/halmac_cfg_wmac_88xx.o  \
+   halmac_88xx/halmac_flash_88xx.o \
+   halmac_88xx/halmac_init_88xx.o  \
+   halmac_88xx/halmac_common_88xx.o\
+   halmac_88xx/halmac_fw_88xx.o\
+   halmac_88xx/halmac_mimo_88xx.o  \
+   halmac_88xx/halmac_8822b/halmac_gpio_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_pcie_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_sdio_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_usb_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_common_8822b.o  \
+   halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_phy_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_init_8822b.o\
+   rtl_halmac.o
+
+
+obj-m = halmac.o
-- 
2.15.1



[PATCH v3 03/19] rtlwifi: add dmdef.h to share with driver and other modules

2018-04-24 Thread pkshih
From: Ping-Ke Shih 

This header file is maintained by new module phydm, and share with
driver and other modules, such as halmac. This patch adds only one
enumeration, and more information will be added later.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/dmdef.h | 40 
 drivers/net/wireless/realtek/rtlwifi/wifi.h  |  1 +
 2 files changed, 41 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/dmdef.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/dmdef.h 
b/drivers/net/wireless/realtek/rtlwifi/dmdef.h
new file mode 100644
index ..5560cd1f98ed
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/dmdef.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright(c) 2007 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef __RTL_DMINFO_H__
+#define __RTL_DMINFO_H__
+
+enum bb_path {
+   BB_PATH_A = 0x0001,
+   BB_PATH_B = 0x0002,
+   BB_PATH_C = 0x0004,
+   BB_PATH_D = 0x0008,
+
+   BB_PATH_AB = (BB_PATH_A | BB_PATH_B),
+   BB_PATH_AC = (BB_PATH_A | BB_PATH_C),
+   BB_PATH_AD = (BB_PATH_A | BB_PATH_D),
+   BB_PATH_BC = (BB_PATH_B | BB_PATH_C),
+   BB_PATH_BD = (BB_PATH_B | BB_PATH_D),
+   BB_PATH_CD = (BB_PATH_C | BB_PATH_D),
+
+   BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C),
+   BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D),
+   BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D),
+   BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D),
+
+   BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D),
+};
+
+#endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index c8542b87cc2b..c32985cfe48d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include "dmdef.h"
 #include "debug.h"
 
 #defineMASKBYTE0   0xff
-- 
2.15.1



Re: [PATCH v2] rtlwifi: cleanup 8723be ant_sel definition

2018-04-22 Thread Pkshih
Thanks for spending your time to teach and help, Kalle and Larry.
I'll record this example to internal white board.

PK



[PATCH v2] rtlwifi: cleanup 8723be ant_sel definition

2018-04-19 Thread pkshih
From: Ping-Ke Shih 

The module parameter ant_sel is used to control antenna number and path.
There is an existing enum ANT_{X2,X1} defined the antenna number, so
add a new enum ANT_{MAIN,AUX} to make it readable. After this work,
incorrect given values depend on ant_sel were exposed, so refill values
according following definition:
  ant_sel   ant_num   ant_path  print_label
 1  ANT_X1ANT_AUX#2
 2  ANT_X2ANT_MAIN   #1
Then, a workaround resulted from the incorrect values in halbtcoutsrc.c was
removed. These is a existing bug in the workaround while ant_sel=2, but the
case is rare use so user is hard to observe this bug.

The experimental results with single antenna connected to specific path
are in following:
  ant_sel  ANT_MAIN(#1)  ANT_AUX(#2)
 0-8-62
 1-62   -10
 2-6-60

Signed-off-by: Ping-Ke Shih 
Cc: Stable  # 4.7+
Reviewed-by: Larry Finger 
---
v2: Add more description about fixed bugs in end of first paragraph.

---
 .../net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c | 15 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c   | 11 +++
 drivers/net/wireless/realtek/rtlwifi/wifi.h   |  5 +
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
index e0f9985582f9..738a7ea7dc4a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -158,16 +158,6 @@ static u8 halbtc_get_wifi_central_chnl(struct btc_coexist 
*btcoexist)
 
 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
 {
-   struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params;
-
-   /* override ant_num / ant_path */
-   if (mod_params->ant_sel) {
-   rtlpriv->btcoexist.btc_info.ant_num =
-   (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1);
-
-   rtlpriv->btcoexist.btc_info.single_ant_path =
-   (mod_params->ant_sel == 1 ? 0 : 1);
-   }
return rtlpriv->btcoexist.btc_info.single_ant_path;
 }
 
@@ -178,7 +168,6 @@ static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
 
 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
 {
-   struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params;
u8 num;
 
if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
@@ -186,10 +175,6 @@ static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
else
num = 1;
 
-   /* override ant_num / ant_path */
-   if (mod_params->ant_sel)
-   num = (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1) + 1;
-
return num;
 }
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
index e7bbbc95cdb1..b4f3f91b590e 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
@@ -848,6 +848,9 @@ static bool _rtl8723be_init_mac(struct ieee80211_hw *hw)
return false;
}
 
+   if (rtlpriv->cfg->ops->get_btc_status())
+   rtlpriv->btcoexist.btc_ops->btc_power_on_setting(rtlpriv);
+
bytetmp = rtl_read_byte(rtlpriv, REG_MULTI_FUNC_CTRL);
rtl_write_byte(rtlpriv, REG_MULTI_FUNC_CTRL, bytetmp | BIT(3));
 
@@ -2696,21 +2699,21 @@ void rtl8723be_read_bt_coexist_info_from_hwpg(struct 
ieee80211_hw *hw,
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8723B;
rtlpriv->btcoexist.btc_info.ant_num = (value & 0x1);
rtlpriv->btcoexist.btc_info.single_ant_path =
-(value & 0x40);/*0xc3[6]*/
+(value & 0x40 ? ANT_AUX : ANT_MAIN);   /*0xc3[6]*/
} else {
rtlpriv->btcoexist.btc_info.btcoexist = 0;
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8723B;
rtlpriv->btcoexist.btc_info.ant_num = ANT_X2;
-   rtlpriv->btcoexist.btc_info.single_ant_path = 0;
+   rtlpriv->btcoexist.btc_info.single_ant_path = ANT_MAIN;
}
 
/* override ant_num / ant_path */
if (mod_params->ant_sel) {
rtlpriv->btcoexist.btc_info.ant_num =
-   (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1);
+   (mod_params->ant_sel == 1 ? ANT_X1 : ANT_X2);
 
rtlpriv->btcoexist.btc_info.single_ant_path =
-   (mod_params->ant_sel == 1 ? 0 : 1);
+   (mod_params->ant_sel == 1 ? ANT_AUX : ANT_MAIN);
}
 }
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 

Re: [PATCH] rtlwifi: cleanup 8723be ant_sel definition

2018-04-19 Thread Pkshih
On Thu, 2018-04-19 at 12:52 +0300, Kalle Valo wrote:
>  writes:
> 
> > From: Ping-Ke Shih 
> >
> > The module parameter ant_sel is used to control antenna number and path.
> > There is an existing enum ANT_{X2,X1} defined the antenna number, so
> > add a new enum ANT_{MAIN,AUX} to make it readable. After this work,
> > incorrect given values depend on ant_sel were exposed, so refill values
> > according following definition:
> >   ant_sel   ant_num   ant_path  print_label
> >  1  ANT_X1ANT_AUX#2
> >  2  ANT_X2ANT_MAIN   #1
> > Then, the workaround in halbtcoutsrc.c was removed.
> >
> > The experimental results with single antenna connected to specific path
> > are in following:
> >   ant_sel  ANT_MAIN(#1)  ANT_AUX(#2)
> >  0-8-62
> >  1-62   -10
> >  2-6-60
> >
> > Signed-off-by: Ping-Ke Shih 
> > Cc: Stable  # 4.7+
> > Reviewed-by: Larry Finger 
> > ---
> > Hi Kalle,
> >
> > This patch would send to 4.17.
> 
> For -rc releases I require a quite clear bug report but I do not
> understand what you are fixing here, even after reading the commit log
> twice. Could you try to improve it? Especially focus on describing the
> bug in simple terms and how this patch changes the functionality from
> user's point of view.
> 
The patch mainly fix the wrong value of ant_num and single_ant_path when
ant_sel is set.

        if (mod_params->ant_sel) {                                              
                rtlpriv->btcoexist.btc_info.ant_num =                           
-   (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1);           
+   (mod_params->ant_sel == 1 ? ANT_X1 : ANT_X2);           
                                                                                
                rtlpriv->btcoexist.btc_info.single_ant_path =                   
-   (mod_params->ant_sel == 1 ? 0 : 1);                     
+   (mod_params->ant_sel == 1 ? ANT_AUX : ANT_MAIN);        
        }    
So, need workaround to fix the problem.

For end user, most people don't need ant_sel, but HP user needs to set to 1.
In case ant_sel=1, the result is almost the same, but ant_sel=2 that is rare
used is broken. So, this bug may be not seen by user.

Another thing is we want to apply this patch to stable release to give correct
values and remove the workaround, so I think it can apply to -rc too.

Anyway, I'll add more description to commit log, and you can decide to
apply this patch to 4.17 or queue to 4.18.

Thanks
PK


[PATCH] rtlwifi: cleanup 8723be ant_sel definition

2018-04-19 Thread pkshih
From: Ping-Ke Shih 

The module parameter ant_sel is used to control antenna number and path.
There is an existing enum ANT_{X2,X1} defined the antenna number, so
add a new enum ANT_{MAIN,AUX} to make it readable. After this work,
incorrect given values depend on ant_sel were exposed, so refill values
according following definition:
  ant_sel   ant_num   ant_path  print_label
 1  ANT_X1ANT_AUX#2
 2  ANT_X2ANT_MAIN   #1
Then, the workaround in halbtcoutsrc.c was removed.

The experimental results with single antenna connected to specific path
are in following:
  ant_sel  ANT_MAIN(#1)  ANT_AUX(#2)
 0-8-62
 1-62   -10
 2-6-60

Signed-off-by: Ping-Ke Shih 
Cc: Stable  # 4.7+
Reviewed-by: Larry Finger 
---
Hi Kalle,

This patch would send to 4.17.

Thanks
PK

---
 .../net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c | 15 ---
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c   | 11 +++
 drivers/net/wireless/realtek/rtlwifi/wifi.h   |  5 +
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
index e0f9985582f9..738a7ea7dc4a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -158,16 +158,6 @@ static u8 halbtc_get_wifi_central_chnl(struct btc_coexist 
*btcoexist)
 
 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
 {
-   struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params;
-
-   /* override ant_num / ant_path */
-   if (mod_params->ant_sel) {
-   rtlpriv->btcoexist.btc_info.ant_num =
-   (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1);
-
-   rtlpriv->btcoexist.btc_info.single_ant_path =
-   (mod_params->ant_sel == 1 ? 0 : 1);
-   }
return rtlpriv->btcoexist.btc_info.single_ant_path;
 }
 
@@ -178,7 +168,6 @@ static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
 
 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
 {
-   struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params;
u8 num;
 
if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
@@ -186,10 +175,6 @@ static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
else
num = 1;
 
-   /* override ant_num / ant_path */
-   if (mod_params->ant_sel)
-   num = (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1) + 1;
-
return num;
 }
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
index e7bbbc95cdb1..b4f3f91b590e 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c
@@ -848,6 +848,9 @@ static bool _rtl8723be_init_mac(struct ieee80211_hw *hw)
return false;
}
 
+   if (rtlpriv->cfg->ops->get_btc_status())
+   rtlpriv->btcoexist.btc_ops->btc_power_on_setting(rtlpriv);
+
bytetmp = rtl_read_byte(rtlpriv, REG_MULTI_FUNC_CTRL);
rtl_write_byte(rtlpriv, REG_MULTI_FUNC_CTRL, bytetmp | BIT(3));
 
@@ -2696,21 +2699,21 @@ void rtl8723be_read_bt_coexist_info_from_hwpg(struct 
ieee80211_hw *hw,
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8723B;
rtlpriv->btcoexist.btc_info.ant_num = (value & 0x1);
rtlpriv->btcoexist.btc_info.single_ant_path =
-(value & 0x40);/*0xc3[6]*/
+(value & 0x40 ? ANT_AUX : ANT_MAIN);   /*0xc3[6]*/
} else {
rtlpriv->btcoexist.btc_info.btcoexist = 0;
rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8723B;
rtlpriv->btcoexist.btc_info.ant_num = ANT_X2;
-   rtlpriv->btcoexist.btc_info.single_ant_path = 0;
+   rtlpriv->btcoexist.btc_info.single_ant_path = ANT_MAIN;
}
 
/* override ant_num / ant_path */
if (mod_params->ant_sel) {
rtlpriv->btcoexist.btc_info.ant_num =
-   (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1);
+   (mod_params->ant_sel == 1 ? ANT_X1 : ANT_X2);
 
rtlpriv->btcoexist.btc_info.single_ant_path =
-   (mod_params->ant_sel == 1 ? 0 : 1);
+   (mod_params->ant_sel == 1 ? ANT_AUX : ANT_MAIN);
}
 }
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index c32985cfe48d..ab32a62ead81 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2882,6 +2882,11 @@ enum bt_ant_num {
ANT_X1 

[PATCH v4 9/9] rtlwifi: btcoex: Remove global variables of chip specific context

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

Remove the global varaibles, and use local varialbes that point the fields
defined in 'struct btc_coexist' instead, so it is possible to support
multiple devices.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c| 44 --
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c| 56 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c| 57 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c| 45 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c| 39 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 78 --
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.c| 95 --
 7 files changed, 376 insertions(+), 38 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index a4704b2fbeb9..b85e42628bac 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -25,11 +25,6 @@
 
 #include "halbt_precomp.h"
 
-static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant;
-static struct coex_dm_8192e_2ant *coex_dm = _dm_8192e_2ant;
-static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant;
-static struct coex_sta_8192e_2ant *coex_sta = _sta_8192e_2ant;
-
 static const char *const glbt_info_src_8192e_2ant[] = {
"BT Info[wifi fw]",
"BT Info[bt rsp]",
@@ -44,6 +39,7 @@ static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist 
*btcoexist,
 u8 rssi_thresh1)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
int bt_rssi = 0;
u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
 
@@ -106,6 +102,7 @@ static u8 btc8192e2ant_wifi_rssi_state(struct btc_coexist 
*btcoexist,
   u8 rssi_thresh1)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
int wifi_rssi = 0;
u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
 
@@ -171,6 +168,7 @@ static void btc8192e2ant_monitor_bt_enable_disable(struct 
btc_coexist
   *btcoexist)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
static bool pre_bt_disabled;
static u32 bt_disable_cnt;
bool bt_active = true, bt_disabled = false;
@@ -252,6 +250,7 @@ static u32 btc8192e2ant_decide_ra_mask(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_update_ra_mask(struct btc_coexist *btcoexist,
bool force_exec, u32 dis_rate_mask)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_ra_mask = dis_rate_mask;
 
if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
@@ -263,6 +262,7 @@ static void btc8192e2ant_update_ra_mask(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_auto_rate_fallback_retry(struct btc_coexist 
*btcoexist,
  bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
bool wifi_under_b_mode = false;
 
coex_dm->cur_arfr_type = type;
@@ -302,6 +302,7 @@ static void btc8192e2ant_auto_rate_fallback_retry(struct 
btc_coexist *btcoexist,
 static void btc8192e2ant_retry_limit(struct btc_coexist *btcoexist,
 bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_retry_limit_type = type;
 
if (force_exec || (coex_dm->pre_retry_limit_type !=
@@ -325,6 +326,7 @@ static void btc8192e2ant_retry_limit(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_ampdu_maxtime(struct btc_coexist *btcoexist,
   bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_ampdu_time_type = type;
 
if (force_exec || (coex_dm->pre_ampdu_time_type !=
@@ -350,6 +352,7 @@ static void btc8192e2ant_limited_tx(struct btc_coexist 
*btcoexist,
u8 arfr_type, u8 retry_limit_type,
u8 ampdu_time_type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
u32 dis_ra_mask = 0x0;
 
coex_dm->cur_ra_mask_type = ra_mask_type;
@@ -390,6 +393,7 @@ static void btc8192e2ant_limited_rx(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
u32 reg_hp_txrx, 

[PATCH v4 7/9] rtlwifi: btcoex: Add modifier const to version related variables

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

The variables declared as 'static' look a little weird. Since they are
version of btcoex and only used to display in debug message, this patch
changes them to 'static const' to make it clear.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index 959af05117d7..a4704b2fbeb9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8192e_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8192e_2ant = 20130902;
-static u32 glcoex_ver_8192e_2ant = 0x34;
+static const u32 glcoex_ver_date_8192e_2ant = 20130902;
+static const u32 glcoex_ver_8192e_2ant = 0x34;
 
 static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
index e97e907e66cd..31b716fa2524 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8723b_1ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8723b_1ant = 20130918;
-static u32 glcoex_ver_8723b_1ant = 0x47;
+static const u32 glcoex_ver_date_8723b_1ant = 20130918;
+static const u32 glcoex_ver_8723b_1ant = 0x47;
 
 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  bool force_exec, u32 dis_rate_mask)
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
index e9a7f303cdda..8c1cec306bf1 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8723b_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8723b_2ant = 20131113;
-static u32 glcoex_ver_8723b_2ant = 0x3f;
+static const u32 glcoex_ver_date_8723b_2ant = 20131113;
+static const u32 glcoex_ver_8723b_2ant = 0x3f;
 
 static u8 btc8723b2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
index 39dc5966700b..cb34a33ae99a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
@@ -38,8 +38,8 @@ static const char *const glbt_info_src_8821a_1ant[] = {
  "BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8821a_1ant = 20130816;
-static u32 glcoex_ver_8821a_1ant = 0x41;
+static const u32 glcoex_ver_date_8821a_1ant = 20130816;
+static const u32 glcoex_ver_8821a_1ant = 0x41;
 
 static u8 btc8821a1ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
index 264796616d8a..14510d514e2f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8821a_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8821a_2ant = 20130618;
-static u32 glcoex_ver_8821a_2ant = 0x5050;
+static const u32 glcoex_ver_date_8821a_2ant = 20130618;
+static const u32 glcoex_ver_8821a_2ant = 0x5050;
 
 static u8 btc8821a2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
-- 
2.15.1



[PATCH v4 4/9] rtlwifi: btcoex: Add 8822b to Makefile

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

Add btcoex of 8822b to Makefile.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
index d15c58737388..37108c379bd0 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
@@ -4,6 +4,9 @@ btcoexist-objs :=   halbtc8192e2ant.o   \
halbtc8723b2ant.o   \
halbtc8821a1ant.o   \
halbtc8821a2ant.o   \
+   halbtc8822b1ant.o   \
+   halbtc8822b2ant.o   \
+   halbtc8822bwifionly.o   \
halbtcoutsrc.o  \
rtl_btc.o
 
-- 
2.15.1



[PATCH v4 6/9] rtlwifi: btcoex: remove comments that are not meaningful

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

The comments aren't meaningful and the use of '***...***' isn't upstream
style, so remove them. This patch doesn't change any code.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c| 22 +---
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c| 24 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c| 23 ++---
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c| 22 +---
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c| 23 +
 5 files changed, 6 insertions(+), 108 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index 8fce371749d3..959af05117d7 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -22,23 +22,9 @@
  * Larry Finger 
  *
  */
-/**
- * Description:
- *
- * This file is for RTL8192E Co-exist mechanism
- *
- * History
- * 2012/11/15 Cosa first check in.
- *
- **/
 
-/**
- *   include files
- **/
 #include "halbt_precomp.h"
-/**
- *   Global variables, these are static variables
- **/
+
 static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant;
 static struct coex_dm_8192e_2ant *coex_dm = _dm_8192e_2ant;
 static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant;
@@ -53,12 +39,6 @@ static const char *const glbt_info_src_8192e_2ant[] = {
 static u32 glcoex_ver_date_8192e_2ant = 20130902;
 static u32 glcoex_ver_8192e_2ant = 0x34;
 
-/**
- *   local function proto type if needed
- **/
-/**
- *   local function start with btc8192e2ant_
- **/
 static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
 u8 rssi_thresh1)
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
index 59553db020ef..e97e907e66cd 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
@@ -23,23 +23,8 @@
  *
  */
 
-/***
- * Description:
- *
- * This file is for RTL8723B Co-exist mechanism
- *
- * History
- * 2012/11/15 Cosa first check in.
- *
- ***/
-
-/***
- * include files
- ***/
 #include "halbt_precomp.h"
-/***
- * Global variables, these are static variables
- ***/
+
 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant;
 static struct coex_dm_8723b_1ant *coex_dm = _dm_8723b_1ant;
 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
@@ -54,13 +39,6 @@ static const char *const glbt_info_src_8723b_1ant[] = {
 static u32 glcoex_ver_date_8723b_1ant = 20130918;
 static u32 glcoex_ver_8723b_1ant = 0x47;
 
-/***
- * local function proto type if needed
- ***/
-/***
- * local function start with halbtc8723b1ant_
- ***/
-
 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  bool force_exec, u32 dis_rate_mask)
 {
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
index 73ec31972944..e9a7f303cdda 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
@@ -22,22 +22,9 @@
  * Larry Finger 
  *
  

[PATCH v4 0/9] rtlwifi: btcoex: Add 8822b btcoex support

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

v4: swap the order of patch 4/9 and 5/9, because kbuild test robot reports
undefined reference. No source code change.
v3: forget to CC wireless mailing list, so resend again. No any change.
v2: fix misspelling and boolean expression in patch 1/9

Patches 1-2 are revised by patches 12 of previous patchset. 8822b coex
files are split into two patches, and I remove some comments and apply
'static const' to version related variables.
Patches 3-4 aren't changed. (identical to patches 13-15 of previous patchset)
Patches 6-7 remove comments and apply 'static const' to existing files.
Patches 8-9 remove global variables, and use local variables instead.

Ping-Ke Shih (9):
  rtlwifi: btcoex: Add 8822b1ant coex files
  rtlwifi: btcoex: Add 8822b2ant coex files
  rtlwifi: btcoex: Add 8822b header files to precomp.h
  rtlwifi: btcoex: Add 8822b to Makefile
  rtlwifi: btcoex: Add 8822b routine to btc interfaces
  rtlwifi: btcoex: remove comments that are not meaningful
  rtlwifi: btcoex: Add modifier const to version related variables
  rtlwifi: btcoex: Add struct members to replace global varaibles
  rtlwifi: btcoex: Remove global variables of chip specific context

 .../wireless/realtek/rtlwifi/btcoexist/Makefile|3 +
 .../realtek/rtlwifi/btcoexist/halbt_precomp.h  |9 +-
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c|   68 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c|   82 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c|   82 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c|   71 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c|   64 +-
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 5365 +++
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.h|  413 ++
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.c| 5429 
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.h|  434 ++
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.c   |  100 +
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.h   |   24 +
 13 files changed, 12005 insertions(+), 139 deletions(-)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b2ant.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b2ant.h

-- 
2.15.1



[PATCH v4 5/9] rtlwifi: btcoex: Add 8822b routine to btc interfaces

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

Add 8822b routines to run btcoex algorithm

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.c   | 100 +
 1 file changed, 100 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
index 8b6b07a936f5..e0f9985582f9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -1441,6 +1441,11 @@ void exhalbtc_power_on_setting(struct btc_coexist 
*btcoexist)
ex_btc8723b2ant_power_on_setting(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8723b1ant_power_on_setting(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_power_on_setting(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_power_on_setting(btcoexist);
}
 }
 
@@ -1454,6 +1459,11 @@ void exhalbtc_pre_load_firmware(struct btc_coexist 
*btcoexist)
if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8723b2ant_pre_load_firmware(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_pre_load_firmware(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_pre_load_firmware(btcoexist);
}
 }
 
@@ -1479,11 +1489,21 @@ void exhalbtc_init_hw_config(struct btc_coexist 
*btcoexist, bool wifi_only)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_init_hwconfig(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
+
+   halbtc_set_default_port_id_cmd(btcoexist);
+   halbtc_send_wifi_port_id_cmd(btcoexist);
}
 }
 
 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
 {
+   if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
+   ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
 }
 
 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
@@ -1506,6 +1526,11 @@ void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_init_coex_dm(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_init_coex_dm(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_init_coex_dm(btcoexist);
}
 
btcoexist->initilized = true;
@@ -1541,6 +1566,11 @@ void exhalbtc_ips_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
}
 
halbtc_normal_low_power(btcoexist);
@@ -1574,6 +1604,11 @@ void exhalbtc_lps_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
}
 }
 
@@ -1607,6 +1642,11 @@ void exhalbtc_scan_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  

[PATCH v4 8/9] rtlwifi: btcoex: Add struct members to replace global varaibles

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

Chip specific context plays as global variables that will not support
multiple devices simultaneously. This patch adds 'union' fields to hold
the variables, and next patch will remove all of them.

To use the declaration of fields in halbtcoutsrc.h, I move the including
order in header file halbt_precomp.h, and declare two struct terms for
chip specific header files.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbt_precomp.h  |  6 +-
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.h   | 24 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
index 858318fd3d63..e21222b48c2c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
@@ -35,7 +35,6 @@
 #include "../ps.h"
 #include "../pci.h"
 
-#include "halbtcoutsrc.h"
 
 /* Interface type */
 #define RT_PCI_INTERFACE   1
@@ -43,6 +42,9 @@
 #define RT_SDIO_INTERFACE  3
 #define DEV_BUS_TYPE   RT_PCI_INTERFACE
 
+struct btc_coexist;
+struct wifi_only_cfg;
+
 #include "halbtc8192e2ant.h"
 #include "halbtc8723b1ant.h"
 #include "halbtc8723b2ant.h"
@@ -52,6 +54,8 @@
 #include "halbtc8822b2ant.h"
 #include "halbtc8822bwifionly.h"
 
+#include "halbtcoutsrc.h"
+
 #define GetDefaultAdapter(padapter)padapter
 
 #define BIT0   0x0001
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
index 9eae87d19120..46355ce32f1b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
@@ -693,6 +693,30 @@ struct btc_coexist {
enum btc_chip_interface chip_interface;
struct btc_bt_link_info bt_link_info;
 
+   /* context for each chip */
+   union {
+   struct coex_dm_8192e_2ant coex_dm_8192e_2ant;
+   struct coex_dm_8723b_1ant coex_dm_8723b_1ant;
+   struct coex_dm_8723b_2ant coex_dm_8723b_2ant;
+   struct coex_dm_8821a_1ant coex_dm_8821a_1ant;
+   struct coex_dm_8821a_2ant coex_dm_8821a_2ant;
+   struct coex_dm_8822b_1ant coex_dm_8822b_1ant;
+   struct coex_dm_8822b_2ant coex_dm_8822b_2ant;
+   };
+   union {
+   struct coex_sta_8192e_2ant coex_sta_8192e_2ant;
+   struct coex_sta_8723b_1ant coex_sta_8723b_1ant;
+   struct coex_sta_8723b_2ant coex_sta_8723b_2ant;
+   struct coex_sta_8821a_1ant coex_sta_8821a_1ant;
+   struct coex_sta_8821a_2ant coex_sta_8821a_2ant;
+   struct coex_sta_8822b_1ant coex_sta_8822b_1ant;
+   struct coex_sta_8822b_2ant coex_sta_8822b_2ant;
+   };
+   union {
+   struct rfe_type_8822b_1ant rfe_type_8822b_1ant;
+   struct rfe_type_8822b_2ant rfe_type_8822b_2ant;
+   };
+
/* boolean variables to replace BT_AUTO_REPORT_ONLY_Y_ZANT
 * configuration parameters
 */
-- 
2.15.1



[PATCH v4 3/9] rtlwifi: btcoex: Add 8822b header files to precomp.h

2018-04-13 Thread pkshih
From: Ping-Ke Shih 

Add 8822b header files to precomp.h for routing functions.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
index 02dff4c3f664..858318fd3d63 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
@@ -48,6 +48,9 @@
 #include "halbtc8723b2ant.h"
 #include "halbtc8821a2ant.h"
 #include "halbtc8821a1ant.h"
+#include "halbtc8822b1ant.h"
+#include "halbtc8822b2ant.h"
+#include "halbtc8822bwifionly.h"
 
 #define GetDefaultAdapter(padapter)padapter
 
-- 
2.15.1



[PATCH v3 9/9] rtlwifi: btcoex: Remove global variables of chip specific context

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Remove the global varaibles, and use local varialbes that point the fields
defined in 'struct btc_coexist' instead, so it is possible to support
multiple devices.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c| 44 --
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c| 56 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c| 57 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c| 45 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c| 39 +++--
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 78 --
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.c| 95 --
 7 files changed, 376 insertions(+), 38 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index a4704b2fbeb9..b85e42628bac 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -25,11 +25,6 @@
 
 #include "halbt_precomp.h"
 
-static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant;
-static struct coex_dm_8192e_2ant *coex_dm = _dm_8192e_2ant;
-static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant;
-static struct coex_sta_8192e_2ant *coex_sta = _sta_8192e_2ant;
-
 static const char *const glbt_info_src_8192e_2ant[] = {
"BT Info[wifi fw]",
"BT Info[bt rsp]",
@@ -44,6 +39,7 @@ static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist 
*btcoexist,
 u8 rssi_thresh1)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
int bt_rssi = 0;
u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
 
@@ -106,6 +102,7 @@ static u8 btc8192e2ant_wifi_rssi_state(struct btc_coexist 
*btcoexist,
   u8 rssi_thresh1)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
int wifi_rssi = 0;
u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
 
@@ -171,6 +168,7 @@ static void btc8192e2ant_monitor_bt_enable_disable(struct 
btc_coexist
   *btcoexist)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
static bool pre_bt_disabled;
static u32 bt_disable_cnt;
bool bt_active = true, bt_disabled = false;
@@ -252,6 +250,7 @@ static u32 btc8192e2ant_decide_ra_mask(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_update_ra_mask(struct btc_coexist *btcoexist,
bool force_exec, u32 dis_rate_mask)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_ra_mask = dis_rate_mask;
 
if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
@@ -263,6 +262,7 @@ static void btc8192e2ant_update_ra_mask(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_auto_rate_fallback_retry(struct btc_coexist 
*btcoexist,
  bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
bool wifi_under_b_mode = false;
 
coex_dm->cur_arfr_type = type;
@@ -302,6 +302,7 @@ static void btc8192e2ant_auto_rate_fallback_retry(struct 
btc_coexist *btcoexist,
 static void btc8192e2ant_retry_limit(struct btc_coexist *btcoexist,
 bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_retry_limit_type = type;
 
if (force_exec || (coex_dm->pre_retry_limit_type !=
@@ -325,6 +326,7 @@ static void btc8192e2ant_retry_limit(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_ampdu_maxtime(struct btc_coexist *btcoexist,
   bool force_exec, u8 type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
coex_dm->cur_ampdu_time_type = type;
 
if (force_exec || (coex_dm->pre_ampdu_time_type !=
@@ -350,6 +352,7 @@ static void btc8192e2ant_limited_tx(struct btc_coexist 
*btcoexist,
u8 arfr_type, u8 retry_limit_type,
u8 ampdu_time_type)
 {
+   struct coex_dm_8192e_2ant *coex_dm = >coex_dm_8192e_2ant;
u32 dis_ra_mask = 0x0;
 
coex_dm->cur_ra_mask_type = ra_mask_type;
@@ -390,6 +393,7 @@ static void btc8192e2ant_limited_rx(struct btc_coexist 
*btcoexist,
 static void btc8192e2ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
 {
struct rtl_priv *rtlpriv = btcoexist->adapter;
+   struct coex_sta_8192e_2ant *coex_sta = >coex_sta_8192e_2ant;
u32 reg_hp_txrx, 

[PATCH v3 7/9] rtlwifi: btcoex: Add modifier const to version related variables

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

The variables declared as 'static' look a little weird. Since they are
version of btcoex and only used to display in debug message, this patch
changes them to 'static const' to make it clear.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c | 4 ++--
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index 959af05117d7..a4704b2fbeb9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8192e_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8192e_2ant = 20130902;
-static u32 glcoex_ver_8192e_2ant = 0x34;
+static const u32 glcoex_ver_date_8192e_2ant = 20130902;
+static const u32 glcoex_ver_8192e_2ant = 0x34;
 
 static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
index e97e907e66cd..31b716fa2524 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8723b_1ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8723b_1ant = 20130918;
-static u32 glcoex_ver_8723b_1ant = 0x47;
+static const u32 glcoex_ver_date_8723b_1ant = 20130918;
+static const u32 glcoex_ver_8723b_1ant = 0x47;
 
 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  bool force_exec, u32 dis_rate_mask)
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
index e9a7f303cdda..8c1cec306bf1 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8723b_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8723b_2ant = 20131113;
-static u32 glcoex_ver_8723b_2ant = 0x3f;
+static const u32 glcoex_ver_date_8723b_2ant = 20131113;
+static const u32 glcoex_ver_8723b_2ant = 0x3f;
 
 static u8 btc8723b2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
index 39dc5966700b..cb34a33ae99a 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
@@ -38,8 +38,8 @@ static const char *const glbt_info_src_8821a_1ant[] = {
  "BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8821a_1ant = 20130816;
-static u32 glcoex_ver_8821a_1ant = 0x41;
+static const u32 glcoex_ver_date_8821a_1ant = 20130816;
+static const u32 glcoex_ver_8821a_1ant = 0x41;
 
 static u8 btc8821a1ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
index 264796616d8a..14510d514e2f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a2ant.c
@@ -36,8 +36,8 @@ static const char *const glbt_info_src_8821a_2ant[] = {
"BT Info[bt auto report]",
 };
 
-static u32 glcoex_ver_date_8821a_2ant = 20130618;
-static u32 glcoex_ver_8821a_2ant = 0x5050;
+static const u32 glcoex_ver_date_8821a_2ant = 20130618;
+static const u32 glcoex_ver_8821a_2ant = 0x5050;
 
 static u8 btc8821a2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
-- 
2.15.1



[PATCH v3 0/9] rtlwifi: btcoex: Add 8822b btcoex support

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

v3: forget to CC wireless mailing list, so resend again. No any change.
v2: fix misspelling and boolean expression in patch 1/9

Patches 1-2 are revised by patches 12 of previous patchset. 8822b coex
files are split into two patches, and I remove some comments and apply
'static const' to version related variables.
Patches 3-4 aren't changed. (identical to patches 13-15 of previous patchset)
Patches 6-7 remove comments and apply 'static const' to existing files.
Patches 8-9 remove global variables, and use local variables instead.

Ping-Ke Shih (9):
  rtlwifi: btcoex: Add 8822b1ant coex files
  rtlwifi: btcoex: Add 8822b2ant coex files
  rtlwifi: btcoex: Add 8822b header files to precomp.h
  rtlwifi: btcoex: Add 8822b routine to btc interfaces
  rtlwifi: btcoex: Add 8822b to Makefile
  rtlwifi: btcoex: remove comments that are not meaningful
  rtlwifi: btcoex: Add modifier const to version related variables
  rtlwifi: btcoex: Add struct members to replace global varaibles
  rtlwifi: btcoex: Remove global variables of chip specific context

 .../wireless/realtek/rtlwifi/btcoexist/Makefile|3 +
 .../realtek/rtlwifi/btcoexist/halbt_precomp.h  |9 +-
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c|   68 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c|   82 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c|   82 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c|   71 +-
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c|   64 +-
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 5365 +++
 .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.h|  413 ++
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.c| 5429 
 .../realtek/rtlwifi/btcoexist/halbtc8822b2ant.h|  434 ++
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.c   |  100 +
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.h   |   24 +
 13 files changed, 12005 insertions(+), 139 deletions(-)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b2ant.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b2ant.h

-- 
2.15.1



[PATCH v3 4/9] rtlwifi: btcoex: Add 8822b routine to btc interfaces

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Add 8822b routines to run btcoex algorithm

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.c   | 100 +
 1 file changed, 100 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
index 8b6b07a936f5..e0f9985582f9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -1441,6 +1441,11 @@ void exhalbtc_power_on_setting(struct btc_coexist 
*btcoexist)
ex_btc8723b2ant_power_on_setting(btcoexist);
else if (btcoexist->board_info.btdm_ant_num == 1)
ex_btc8723b1ant_power_on_setting(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_power_on_setting(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_power_on_setting(btcoexist);
}
 }
 
@@ -1454,6 +1459,11 @@ void exhalbtc_pre_load_firmware(struct btc_coexist 
*btcoexist)
if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8723b2ant_pre_load_firmware(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_pre_load_firmware(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_pre_load_firmware(btcoexist);
}
 }
 
@@ -1479,11 +1489,21 @@ void exhalbtc_init_hw_config(struct btc_coexist 
*btcoexist, bool wifi_only)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_init_hwconfig(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
+
+   halbtc_set_default_port_id_cmd(btcoexist);
+   halbtc_send_wifi_port_id_cmd(btcoexist);
}
 }
 
 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
 {
+   if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
+   ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
 }
 
 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
@@ -1506,6 +1526,11 @@ void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_init_coex_dm(btcoexist);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_init_coex_dm(btcoexist);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_init_coex_dm(btcoexist);
}
 
btcoexist->initilized = true;
@@ -1541,6 +1566,11 @@ void exhalbtc_ips_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
}
 
halbtc_normal_low_power(btcoexist);
@@ -1574,6 +1604,11 @@ void exhalbtc_lps_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
if (btcoexist->board_info.btdm_ant_num == 2)
ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
+   } else if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
+   if (btcoexist->board_info.btdm_ant_num == 1)
+   ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
+   else if (btcoexist->board_info.btdm_ant_num == 2)
+   ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
}
 }
 
@@ -1607,6 +1642,11 @@ void exhalbtc_scan_notify(struct btc_coexist *btcoexist, 
u8 type)
} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  

[PATCH v3 6/9] rtlwifi: btcoex: remove comments that are not meaningful

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

The comments aren't meaningful and the use of '***...***' isn't upstream
style, so remove them. This patch doesn't change any code.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtc8192e2ant.c| 22 +---
 .../realtek/rtlwifi/btcoexist/halbtc8723b1ant.c| 24 +-
 .../realtek/rtlwifi/btcoexist/halbtc8723b2ant.c| 23 ++---
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c| 22 +---
 .../realtek/rtlwifi/btcoexist/halbtc8821a2ant.c| 23 +
 5 files changed, 6 insertions(+), 108 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
index 8fce371749d3..959af05117d7 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8192e2ant.c
@@ -22,23 +22,9 @@
  * Larry Finger 
  *
  */
-/**
- * Description:
- *
- * This file is for RTL8192E Co-exist mechanism
- *
- * History
- * 2012/11/15 Cosa first check in.
- *
- **/
 
-/**
- *   include files
- **/
 #include "halbt_precomp.h"
-/**
- *   Global variables, these are static variables
- **/
+
 static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant;
 static struct coex_dm_8192e_2ant *coex_dm = _dm_8192e_2ant;
 static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant;
@@ -53,12 +39,6 @@ static const char *const glbt_info_src_8192e_2ant[] = {
 static u32 glcoex_ver_date_8192e_2ant = 20130902;
 static u32 glcoex_ver_8192e_2ant = 0x34;
 
-/**
- *   local function proto type if needed
- **/
-/**
- *   local function start with btc8192e2ant_
- **/
 static u8 btc8192e2ant_bt_rssi_state(struct btc_coexist *btcoexist,
 u8 level_num, u8 rssi_thresh,
 u8 rssi_thresh1)
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
index 59553db020ef..e97e907e66cd 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
@@ -23,23 +23,8 @@
  *
  */
 
-/***
- * Description:
- *
- * This file is for RTL8723B Co-exist mechanism
- *
- * History
- * 2012/11/15 Cosa first check in.
- *
- ***/
-
-/***
- * include files
- ***/
 #include "halbt_precomp.h"
-/***
- * Global variables, these are static variables
- ***/
+
 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant;
 static struct coex_dm_8723b_1ant *coex_dm = _dm_8723b_1ant;
 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
@@ -54,13 +39,6 @@ static const char *const glbt_info_src_8723b_1ant[] = {
 static u32 glcoex_ver_date_8723b_1ant = 20130918;
 static u32 glcoex_ver_8723b_1ant = 0x47;
 
-/***
- * local function proto type if needed
- ***/
-/***
- * local function start with halbtc8723b1ant_
- ***/
-
 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  bool force_exec, u32 dis_rate_mask)
 {
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
index 73ec31972944..e9a7f303cdda 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b2ant.c
@@ -22,22 +22,9 @@
  * Larry Finger 
  *
  

[PATCH v3 8/9] rtlwifi: btcoex: Add struct members to replace global varaibles

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Chip specific context plays as global variables that will not support
multiple devices simultaneously. This patch adds 'union' fields to hold
the variables, and next patch will remove all of them.

To use the declaration of fields in halbtcoutsrc.h, I move the including
order in header file halbt_precomp.h, and declare two struct terms for
chip specific header files.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbt_precomp.h  |  6 +-
 .../realtek/rtlwifi/btcoexist/halbtcoutsrc.h   | 24 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
index 858318fd3d63..e21222b48c2c 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
@@ -35,7 +35,6 @@
 #include "../ps.h"
 #include "../pci.h"
 
-#include "halbtcoutsrc.h"
 
 /* Interface type */
 #define RT_PCI_INTERFACE   1
@@ -43,6 +42,9 @@
 #define RT_SDIO_INTERFACE  3
 #define DEV_BUS_TYPE   RT_PCI_INTERFACE
 
+struct btc_coexist;
+struct wifi_only_cfg;
+
 #include "halbtc8192e2ant.h"
 #include "halbtc8723b1ant.h"
 #include "halbtc8723b2ant.h"
@@ -52,6 +54,8 @@
 #include "halbtc8822b2ant.h"
 #include "halbtc8822bwifionly.h"
 
+#include "halbtcoutsrc.h"
+
 #define GetDefaultAdapter(padapter)padapter
 
 #define BIT0   0x0001
diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
index 9eae87d19120..46355ce32f1b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.h
@@ -693,6 +693,30 @@ struct btc_coexist {
enum btc_chip_interface chip_interface;
struct btc_bt_link_info bt_link_info;
 
+   /* context for each chip */
+   union {
+   struct coex_dm_8192e_2ant coex_dm_8192e_2ant;
+   struct coex_dm_8723b_1ant coex_dm_8723b_1ant;
+   struct coex_dm_8723b_2ant coex_dm_8723b_2ant;
+   struct coex_dm_8821a_1ant coex_dm_8821a_1ant;
+   struct coex_dm_8821a_2ant coex_dm_8821a_2ant;
+   struct coex_dm_8822b_1ant coex_dm_8822b_1ant;
+   struct coex_dm_8822b_2ant coex_dm_8822b_2ant;
+   };
+   union {
+   struct coex_sta_8192e_2ant coex_sta_8192e_2ant;
+   struct coex_sta_8723b_1ant coex_sta_8723b_1ant;
+   struct coex_sta_8723b_2ant coex_sta_8723b_2ant;
+   struct coex_sta_8821a_1ant coex_sta_8821a_1ant;
+   struct coex_sta_8821a_2ant coex_sta_8821a_2ant;
+   struct coex_sta_8822b_1ant coex_sta_8822b_1ant;
+   struct coex_sta_8822b_2ant coex_sta_8822b_2ant;
+   };
+   union {
+   struct rfe_type_8822b_1ant rfe_type_8822b_1ant;
+   struct rfe_type_8822b_2ant rfe_type_8822b_2ant;
+   };
+
/* boolean variables to replace BT_AUTO_REPORT_ONLY_Y_ZANT
 * configuration parameters
 */
-- 
2.15.1



[PATCH v3 5/9] rtlwifi: btcoex: Add 8822b to Makefile

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Add btcoex of 8822b to Makefile.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
index d15c58737388..37108c379bd0 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/Makefile
@@ -4,6 +4,9 @@ btcoexist-objs :=   halbtc8192e2ant.o   \
halbtc8723b2ant.o   \
halbtc8821a1ant.o   \
halbtc8821a2ant.o   \
+   halbtc8822b1ant.o   \
+   halbtc8822b2ant.o   \
+   halbtc8822bwifionly.o   \
halbtcoutsrc.o  \
rtl_btc.o
 
-- 
2.15.1



[PATCH v3 3/9] rtlwifi: btcoex: Add 8822b header files to precomp.h

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Add 8822b header files to precomp.h for routing functions.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
index 02dff4c3f664..858318fd3d63 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbt_precomp.h
@@ -48,6 +48,9 @@
 #include "halbtc8723b2ant.h"
 #include "halbtc8821a2ant.h"
 #include "halbtc8821a1ant.h"
+#include "halbtc8822b1ant.h"
+#include "halbtc8822b2ant.h"
+#include "halbtc8822bwifionly.h"
 
 #define GetDefaultAdapter(padapter)padapter
 
-- 
2.15.1



[PATCH] rtlwifi: btcoex: remove identical statements within if-else branches

2018-04-09 Thread pkshih
From: Ping-Ke Shih 

Since the statements are identical, we can safely remove the statements.
The commit 42e74946f016 ("rtlwifi: btcoexist: Fix if == else warnings in
halbtc8821a1ant.c") had fixed the statements, but the commit c6821613e653
("rtlwifi: btcoex: follow linux coding style") that converted coding style
and upgraded btcoex didn't include the fix.

Reported-by: Gustavo A. R. Silva 
Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/btcoexist/halbtc8821a1ant.c   | 19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c 
b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
index d3eb717078bf..f29bf4f3a905 100644
--- a/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
+++ b/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
@@ -1578,11 +1578,7 @@ static void btc8821a1ant_act_bt_sco_hid_only_busy(struct 
btc_coexist *btcoexist,
/* tdma and coex table */
btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
 
-   if (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
-   wifi_status)
-   btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
-   else
-   btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
+   btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
 }
 
 static void btc8821a1ant_act_wifi_con_bt_acl_busy(struct btc_coexist 
*btcoexist,
@@ -1992,16 +1988,9 @@ static void btc8821a1ant_run_coexist_mechanism(struct 
btc_coexist *btcoexist)
wifi_rssi_state =
btc8821a1ant_wifi_rssi_state(btcoexist, 1, 2,
 30, 0);
-   if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
-   (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
-   btc8821a1ant_limited_tx(btcoexist,
-   NORMAL_EXEC, 1, 1,
-   0, 1);
-   } else {
-   btc8821a1ant_limited_tx(btcoexist,
-   NORMAL_EXEC, 1, 1,
-   0, 1);
-   }
+   btc8821a1ant_limited_tx(btcoexist,
+   NORMAL_EXEC, 1, 1,
+   0, 1);
} else {
btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC,
0, 0, 0, 0);
-- 
2.15.1



Re: [rtlwifi-btcoex] Suspicious code in halbtc8821a1ant driver

2018-04-04 Thread Pkshih
On Thu, 2018-04-05 at 01:25 +, Gustavo A. R. Silva wrote:
> Hi all,
> 
> While doing some static analysis I came across the following piece of code at
> drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c:1581:
> 
> 1581 static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist 
> *btcoexist,
> 1582   u8 wifi_status)
> 1583 {
> 1584 /* tdma and coex table */
> 1585 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
> 1586 
> 1587 if (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
> 1588 wifi_status)
> 1589 btc8821a1ant_coex_table_with_type(btcoexist, 
> NORMAL_EXEC, 1);
> 1590 else
> 1591 btc8821a1ant_coex_table_with_type(btcoexist, 
> NORMAL_EXEC, 1);
> 1592 }
> 
> The issue here is that the code for both branches of the if-else statement is 
> identical.
> 
> The if-else was introduced a year ago in this commit c6821613e653
> 
> I wonder if an argument should be changed in any of the calls to
> btc8821a1ant_coex_table_with_type?
> 
> 

It looks weird. Since we're in spring vacation, I'll check my colleague next 
Monday.

PK



Re: [PATCH 1/9] rtlwifi: btcoex: Add 8822b1ant coex files

2018-04-04 Thread Pkshih
On Wed, 2018-04-04 at 20:41 +0800, Pkshih wrote:
> On Wed, 2018-04-04 at 02:43 +, Larry Finger wrote:
> > On 03/28/2018 02:27 AM, pks...@realtek.com wrote:
> > > From: Ping-Ke Shih <pks...@realtek.com>
> > > 
> > > This file supports 8822be WiFi module with two physical antenna that
> > > means one antenna will share with BT.
> > > 
> > > Signed-off-by: Ping-Ke Shih <pks...@realtek.com>
> > > ---
> > >   .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 5303 
> > >
> > >   .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.h|  413 ++
> > >   2 files changed, 5716 insertions(+)
> > >   create mode 100644 
> > >drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c
> > >   create mode 100644 
> > >drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.h
> > 
> > --snip--
> > 
> > > +/*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
> > > +
> > > +static
> > > +void hallbtc882b1ant_set_ant_switch(struct btc_coexist *btcoexist,
> > > + bool force_exec, u8 ctrl_type,
> > > + u8 pos_type)
> > > +{
> > > + struct rtl_priv *rtlpriv = btcoexist->adapter;
> > > + bool switch_polatiry_inverse = false;
> > > + u8 regval_0xcbd = 0, regval_0x64;
> > > + u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
> > > +
> > > + /* Ext switch buffer mux */
> > > + btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
> > > + btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
> > > + btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
> > > +
> > > + if (!rfe_type->ext_ant_switch_exist)
> > > + return;
> > > +
> > > + coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
> > > +
> > > + if (!force_exec) {
> > > + if (coex_dm->pre_ext_ant_switch_status ==
> > > + coex_dm->cur_ext_ant_switch_status)
> > > + return;
> > > + }
> > > +
> > > + coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
> > > +
> > > + /* swap control polarity if use different switch control polarity*/
> > > + /* Normal switch polarity for SPDT,
> > > +  * 0xcbd[1:0] = 2b'01 => Ant to BTG, WLA
> > > +  * 0xcbd[1:0] = 2b'10 => Ant to WLG
> > > +  */
> > > + switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?
> > > +    ~switch_polatiry_inverse :
> > > +    switch_polatiry_inverse);
> > 
> > gcc 7.3.1 reports the following:
> > 
> >    CC [M]  drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.o
> > drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c: In 
> > function 
> > ‘hallbtc882b1ant_set_ant_switch’:
> > drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c:2193:9: 
> > warning: ‘~’ on a boolean expression [-Wbool-operation]
> >   ~switch_polatiry_inverse :
> >   ^
> > drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c:2193:9: 
> > note: 
> > did you mean to use logical not?
> >   ~switch_polatiry_inverse :
> >   ^
> > 
> > For a boolean, you should use !bool, not -bool. In addition, it would be 
> > better 
> > to use switch_polarity_inverse, not switch_polatiry_inverse. The same 
> > "typo" 
> > happens in other places in this file. I suggest
> > 
> > sed -i 's/polatiry_inverse/polarity_inverse/g' \
> > drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c.
> > 
> 
> I'll fix the typo, and declare the variable switch_polarity_inverse without
> initial value, then assign value true or false in the line mentioned in above
> warning. It looks like:
>   bool switch_polatiry_inverse;
>   ...
>   switch_polarity_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 
> ?
>      true : false);
> 

Fix the last expression again:

switch_polarity_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1);




Re: [PATCH 1/9] rtlwifi: btcoex: Add 8822b1ant coex files

2018-04-04 Thread Pkshih
On Wed, 2018-04-04 at 02:43 +, Larry Finger wrote:
> On 03/28/2018 02:27 AM, pks...@realtek.com wrote:
> > From: Ping-Ke Shih 
> > 
> > This file supports 8822be WiFi module with two physical antenna that
> > means one antenna will share with BT.
> > 
> > Signed-off-by: Ping-Ke Shih 
> > ---
> >   .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.c| 5303 
> >
> >   .../realtek/rtlwifi/btcoexist/halbtc8822b1ant.h|  413 ++
> >   2 files changed, 5716 insertions(+)
> >   create mode 100644 
> >drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c
> >   create mode 100644 
> >drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.h
> 
> --snip--
> 
> > +/*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
> > +
> > +static
> > +void hallbtc882b1ant_set_ant_switch(struct btc_coexist *btcoexist,
> > +   bool force_exec, u8 ctrl_type,
> > +   u8 pos_type)
> > +{
> > +   struct rtl_priv *rtlpriv = btcoexist->adapter;
> > +   bool switch_polatiry_inverse = false;
> > +   u8 regval_0xcbd = 0, regval_0x64;
> > +   u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
> > +
> > +   /* Ext switch buffer mux */
> > +   btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
> > +   btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
> > +   btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
> > +
> > +   if (!rfe_type->ext_ant_switch_exist)
> > +   return;
> > +
> > +   coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
> > +
> > +   if (!force_exec) {
> > +   if (coex_dm->pre_ext_ant_switch_status ==
> > +   coex_dm->cur_ext_ant_switch_status)
> > +   return;
> > +   }
> > +
> > +   coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
> > +
> > +   /* swap control polarity if use different switch control polarity*/
> > +   /* Normal switch polarity for SPDT,
> > +    * 0xcbd[1:0] = 2b'01 => Ant to BTG, WLA
> > +    * 0xcbd[1:0] = 2b'10 => Ant to WLG
> > +    */
> > +   switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?
> > +      ~switch_polatiry_inverse :
> > +      switch_polatiry_inverse);
> 
> gcc 7.3.1 reports the following:
> 
>    CC [M]  drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.o
> drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c: In function 
> ‘hallbtc882b1ant_set_ant_switch’:
> drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c:2193:9: 
> warning: ‘~’ on a boolean expression [-Wbool-operation]
>   ~switch_polatiry_inverse :
>   ^
> drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c:2193:9: 
> note: 
> did you mean to use logical not?
>   ~switch_polatiry_inverse :
>   ^
> 
> For a boolean, you should use !bool, not -bool. In addition, it would be 
> better 
> to use switch_polarity_inverse, not switch_polatiry_inverse. The same "typo" 
> happens in other places in this file. I suggest
> 
> sed -i 's/polatiry_inverse/polarity_inverse/g' \
> drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8822b1ant.c.
> 

I'll fix the typo, and declare the variable switch_polarity_inverse without
initial value, then assign value true or false in the line mentioned in above
warning. It looks like:
bool switch_polatiry_inverse;
...
switch_polarity_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?


   true : false);


PK


[PATCH v2 00/17] rtlwifi: halmac: Add new module halmac

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

v2: remove indirection to get halmac ops
Only patches 1/17 and 11/17 are changed.

Patches 1/17-3/17 are added structure to support this module.
Patches 4/17-16/17 add new files.
Patch 17/17 add this module to Makefile and Kconfig.

Ping-Ke Shih (17):
  rtlwifi: add halmac structure to wifi.h
  rtlwifi: add debug ID COMP_HALMAC
  rtlwifi: add dmdef.h to share with driver and other modules
  rtlwifi: halmac: add main definition used by halmac
  rtlwifi: halmac: describe number and size of chip functions
  rtlwifi: halmac: add definitions of registers and bit fields
  rtlwifi: halmac: add definition of TX/RX descriptor
  rtlwifi: halmac: add GPIO pin/pinmux definitions
  rtlwifi: halmac: add power sequence to turn on/off wifi card
  rtlwifi: halmac: access efuse through halmac helper functions
  rtlwifi: halmac: add files to implement halmac ops
  rtlwifi: halmac: add halmac init/deinit functions
  rtlwifi: halmac: add firmware related functions and definitions
  rtlwifi: halmac: add bus interface commands
  rtlwifi: halmac: add to control WiFi mac functions and registers
  rtlwifi: halmac: add to support BB and RF functions
  rtlwifi: add halmac to Makefile and Kconfig

 drivers/net/wireless/realtek/rtlwifi/Kconfig   | 5 +
 drivers/net/wireless/realtek/rtlwifi/Makefile  | 1 +
 drivers/net/wireless/realtek/rtlwifi/debug.h   | 1 +
 drivers/net/wireless/realtek/rtlwifi/dmdef.h   |40 +
 .../net/wireless/realtek/rtlwifi/halmac/Makefile   |29 +
 .../halmac_88xx/halmac_8822b/halmac_8822b_cfg.h|68 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.c   |   144 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.h   |36 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.c |   173 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.h |32 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.c   |   847 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.h   |34 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.c   |   688 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.h   |33 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.c   |   218 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.h   |38 +
 .../halmac_88xx/halmac_8822b/halmac_phy_8822b.c|   148 +
 .../halmac_8822b/halmac_pwr_seq_8822b.c|   396 +
 .../halmac_8822b/halmac_pwr_seq_8822b.h|26 +
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.c   |   880 +
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.h   |62 +
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.c|   161 +
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.h|38 +
 .../rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h   |40 +
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c |   397 +
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h |53 +
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.c  |  1158 ++
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.h  |   122 +
 .../halmac/halmac_88xx/halmac_common_88xx.c|  2931 +++
 .../halmac/halmac_88xx/halmac_common_88xx.h|   151 +
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c |  1918 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h |   101 +
 .../rtlwifi/halmac/halmac_88xx/halmac_flash_88xx.c |   316 +
 .../rtlwifi/halmac/halmac_88xx/halmac_flash_88xx.h |35 +
 .../rtlwifi/halmac/halmac_88xx/halmac_fw_88xx.c|  1149 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_fw_88xx.h|57 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c  |   415 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h  |55 +
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c  |  1071 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h  |70 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c  |   869 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h  |79 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c  |   538 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h  |98 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c  |   895 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h  |75 +
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c   |   522 +
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h   |83 +
 .../wireless/realtek/rtlwifi/halmac/halmac_api.c   |   438 +
 .../wireless/realtek/rtlwifi/halmac/halmac_api.h   |65 +
 .../wireless/realtek/rtlwifi/halmac/halmac_bit2.h  | 18234 +++
 .../realtek/rtlwifi/halmac/halmac_bit_8822b.h  | 17870 ++
 .../realtek/rtlwifi/halmac/halmac_fw_info.h|   119 +
 .../rtlwifi/halmac/halmac_fw_offload_c2h_nic.h |   371 +
 .../rtlwifi/halmac/halmac_fw_offload_h2c_nic.h |   694 +
 .../realtek/rtlwifi/halmac/halmac_gpio_cmd.h   |84 +
 .../rtlwifi/halmac/halmac_h2c_extra_info_nic.h |   171 +
 .../realtek/rtlwifi/halmac/halmac_intf_phy_cmd.h   |45 +
 .../rtlwifi/halmac/halmac_original_c2h_nic.h   |   408 +
 .../rtlwifi/halmac/halmac_original_h2c_nic.h   |  1143 ++
 

[PATCH v2 09/17] rtlwifi: halmac: add power sequence to turn on/off wifi card

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Define power sequence command, and fill the sequences of 8822b.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_8822b/halmac_pwr_seq_8822b.c| 396 +
 .../halmac_8822b/halmac_pwr_seq_8822b.h|  26 ++
 .../realtek/rtlwifi/halmac/halmac_pwr_seq_cmd.h|  98 +
 3 files changed, 520 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_pwr_seq_cmd.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
new file mode 100644
index ..5aab588eb094
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.c
@@ -0,0 +1,396 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_pwr_seq_8822b.h"
+
+static struct halmac_wlan_pwr_cfg TRANS_CARDDIS_TO_CARDEMU_8822B[] = {
+   /* { offset, cut_msk, interface_msk, base|cmd, msk, value } */
+   {0x0086,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_SDIO,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0x0086,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_SDIO,
+HALMAC_PWR_CMD_POLLING, BIT(1), BIT(1)},
+   {0x004A,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0x0005,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(3) | BIT(4) | BIT(7), 0},
+   {0x0300,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x0301,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+0,
+HALMAC_PWR_CMD_END, 0, 0},
+};
+
+static struct halmac_wlan_pwr_cfg TRANS_CARDEMU_TO_ACT_8822B[] = {
+   /* { offset, cut_msk, interface_msk, base|cmd, msk, value } */
+   {0x0012,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(1), 0},
+   {0x0012,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0020,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0001,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_DELAY, 1, HALMAC_PWR_DELAY_MS},
+   {0x,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK | HALMAC_PWR_INTF_SDIO_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(5), 0},
+   {0x0005,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0},
+   {0x0075,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), BIT(0)},
+   {0x0006,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_ALL_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_POLLING, BIT(1), BIT(1)},
+   {0x0075,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_PCI_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, BIT(0), 0},
+   {0xFF1A,
+HALMAC_PWR_CUT_ALL_MSK,
+HALMAC_PWR_INTF_USB_MSK,
+HALMAC_PWR_ADDR_MAC,
+HALMAC_PWR_CMD_WRITE, 0xFF, 0},
+   {0x0006,
+HALMAC_PWR_CUT_ALL_MSK,
+

[PATCH v2 04/17] rtlwifi: halmac: add main definition used by halmac

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

The files contain main definition of struct, enum, prototypes,
state machine, etc.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/halmac/halmac_state_machine.h  |  157 ++
 .../wireless/realtek/rtlwifi/halmac/halmac_type.h  | 2134 
 2 files changed, 2291 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_type.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
new file mode 100644
index ..d6cce79a460d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_state_machine.h
@@ -0,0 +1,157 @@
+/**
+ *
+ * Copyright(c) 2017 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_STATE_MACHINE_H_
+#define _HALMAC_STATE_MACHINE_H_
+
+enum halmac_dlfw_state {
+   HALMAC_DLFW_NONE = 0,
+   HALMAC_DLFW_DONE = 1,
+   HALMAC_GEN_INFO_SENT = 2,
+
+   /* Data CPU firmware download framework */
+   HALMAC_DLFW_INIT = 0x11,
+   HALMAC_DLFW_START = 0x12,
+   HALMAC_DLFW_CONF_READY = 0x13,
+   HALMAC_DLFW_CPU_READY = 0x14,
+   HALMAC_DLFW_MEM_READY = 0x15,
+   HALMAC_DLFW_SW_READY = 0x16,
+   HALMAC_DLFW_OFLD_READY = 0x17,
+
+   HALMAC_DLFW_UNDEFINED = 0x7F,
+};
+
+enum halmac_gpio_cfg_state {
+   HALMAC_GPIO_CFG_STATE_IDLE = 0,
+   HALMAC_GPIO_CFG_STATE_BUSY = 1,
+   HALMAC_GPIO_CFG_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_rsvd_pg_state {
+   HALMAC_RSVD_PG_STATE_IDLE = 0,
+   HALMAC_RSVD_PG_STATE_BUSY = 1,
+   HALMAC_RSVD_PG_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_api_state {
+   HALMAC_API_STATE_INIT = 0,
+   HALMAC_API_STATE_HALT = 1,
+   HALMAC_API_STATE_UNDEFINED = 0x7F,
+};
+
+enum halmac_cmd_construct_state {
+   HALMAC_CMD_CNSTR_IDLE = 0,
+   HALMAC_CMD_CNSTR_BUSY = 1,
+   HALMAC_CMD_CNSTR_H2C_SENT = 2,
+   HALMAC_CMD_CNSTR_CNSTR = 3,
+   HALMAC_CMD_CNSTR_BUF_CLR = 4,
+   HALMAC_CMD_CNSTR_UNDEFINED = 0x7F,
+};
+
+enum halmac_cmd_process_status {
+   HALMAC_CMD_PROCESS_IDLE = 0x01, /* Init status */
+   HALMAC_CMD_PROCESS_SENDING = 0x02, /* Wait ack */
+   HALMAC_CMD_PROCESS_RCVD = 0x03, /* Rcvd ack */
+   HALMAC_CMD_PROCESS_DONE = 0x04, /* Event done */
+   HALMAC_CMD_PROCESS_ERROR = 0x05, /* Return code error */
+   HALMAC_CMD_PROCESS_UNDEFINE = 0x7F,
+};
+
+enum halmac_mac_power {
+   HALMAC_MAC_POWER_OFF = 0x0,
+   HALMAC_MAC_POWER_ON = 0x1,
+   HALMAC_MAC_POWER_UNDEFINE = 0x7F,
+};
+
+enum halmac_wlcpu_mode {
+   HALMAC_WLCPU_ACTIVE = 0x0,
+   HALMAC_WLCPU_ENTER_SLEEP = 0x1,
+   HALMAC_WLCPU_SLEEP = 0x2,
+   HALMAC_WLCPU_UNDEFINE = 0x7F,
+};
+
+struct halmac_efuse_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_cfg_param_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_scan_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_update_pkt_state {
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_iqk_state {
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_pwr_tracking_state {
+   enum halmac_cmd_process_status  proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_psd_state {
+   enum halmac_cmd_process_status proc_status;
+   u16 data_size;
+   u16 seg_size;
+   u8 *data;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_fw_snding_state {
+   enum halmac_cmd_construct_state cmd_cnstr_state;
+   enum halmac_cmd_process_status proc_status;
+   u8 fw_rc;
+   u16 seq_num;
+};
+
+struct halmac_state {
+   struct halmac_efuse_state efuse_state;
+   struct halmac_cfg_param_state cfg_param_state;
+   struct halmac_scan_state scan_state;
+   

[PATCH v2 07/17] rtlwifi: halmac: add definition of TX/RX descriptor

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

TX/RX descriptor are the headers to describe the packet content.

Signed-off-by: Ping-Ke Shih 
---
 .../realtek/rtlwifi/halmac/halmac_rx_bd_nic.h  |  36 ++
 .../realtek/rtlwifi/halmac/halmac_rx_desc_chip.h   | 100 +
 .../realtek/rtlwifi/halmac/halmac_rx_desc_nic.h| 123 ++
 .../realtek/rtlwifi/halmac/halmac_tx_bd_nic.h  | 106 +
 .../realtek/rtlwifi/halmac/halmac_tx_desc_chip.h   | 398 +++
 .../realtek/rtlwifi/halmac/halmac_tx_desc_nic.h| 439 +
 6 files changed, 1202 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_bd_nic.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_desc_chip.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_tx_desc_nic.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
new file mode 100644
index ..c03d4d0e4e8a
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_bd_nic.h
@@ -0,0 +1,36 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_RX_BD_NIC_H_
+#define _HALMAC_RX_BD_NIC_H_
+
+/*TXBD_DW0*/
+
+#define GET_RX_BD_RXFAIL(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 31, 1)
+#define GET_RX_BD_TOTALRXPKTSIZE(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 16, 13)
+#define GET_RX_BD_RXTAG(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 16, 13)
+#define GET_RX_BD_FS(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 15, 1)
+#define GET_RX_BD_LS(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 14, 1)
+#define GET_RX_BD_RXBUFFSIZE(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x00, 0, 14)
+
+/*TXBD_DW1*/
+
+#define GET_RX_BD_PHYSICAL_ADDR_LOW(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x04, 0, 32)
+
+/*TXBD_DW2*/
+
+#define GET_RX_BD_PHYSICAL_ADDR_HIGH(rxbd) LE_BITS_TO_4BYTE(rxbd + 0x08, 0, 32)
+
+#endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
new file mode 100644
index ..3134d3631281
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_rx_desc_chip.h
@@ -0,0 +1,100 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_RX_DESC_CHIP_H_
+#define _HALMAC_RX_DESC_CHIP_H_
+
+/*RXDESC_WORD0*/
+
+#define GET_RX_DESC_EOR_8822B(rxdesc) GET_RX_DESC_EOR(rxdesc)
+#define GET_RX_DESC_PHYPKTIDC_8822B(rxdesc) GET_RX_DESC_PHYPKTIDC(rxdesc)
+#define GET_RX_DESC_SWDEC_8822B(rxdesc) GET_RX_DESC_SWDEC(rxdesc)
+#define GET_RX_DESC_PHYST_8822B(rxdesc) GET_RX_DESC_PHYST(rxdesc)
+#define GET_RX_DESC_SHIFT_8822B(rxdesc) GET_RX_DESC_SHIFT(rxdesc)
+#define GET_RX_DESC_QOS_8822B(rxdesc) GET_RX_DESC_QOS(rxdesc)
+#define GET_RX_DESC_SECURITY_8822B(rxdesc) GET_RX_DESC_SECURITY(rxdesc)
+#define GET_RX_DESC_DRV_INFO_SIZE_8822B(rxdesc)
\
+   GET_RX_DESC_DRV_INFO_SIZE(rxdesc)
+#define GET_RX_DESC_ICV_ERR_8822B(rxdesc) GET_RX_DESC_ICV_ERR(rxdesc)
+#define GET_RX_DESC_CRC32_8822B(rxdesc) GET_RX_DESC_CRC32(rxdesc)
+#define GET_RX_DESC_PKT_LEN_8822B(rxdesc) GET_RX_DESC_PKT_LEN(rxdesc)
+
+/*RXDESC_WORD1*/
+
+#define GET_RX_DESC_BC_8822B(rxdesc) GET_RX_DESC_BC(rxdesc)
+#define GET_RX_DESC_MC_8822B(rxdesc) GET_RX_DESC_MC(rxdesc)
+#define GET_RX_DESC_TY_PE_8822B(rxdesc) GET_RX_DESC_TY_PE(rxdesc)
+#define GET_RX_DESC_MF_8822B(rxdesc) GET_RX_DESC_MF(rxdesc)
+#define 

[PATCH v2 02/17] rtlwifi: add debug ID COMP_HALMAC

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Add a debug ID for the module halmac

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/debug.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/debug.h 
b/drivers/net/wireless/realtek/rtlwifi/debug.h
index ad6834af618b..90c41c17d678 100644
--- a/drivers/net/wireless/realtek/rtlwifi/debug.h
+++ b/drivers/net/wireless/realtek/rtlwifi/debug.h
@@ -106,6 +106,7 @@
 #define COMP_BT_COEXISTBIT(30)
 #define COMP_IQK   BIT(31)
 #define COMP_TX_REPORT BIT_ULL(32)
+#define COMP_HALMACBIT_ULL(33)
 
 /*--
Define the rt_print components
-- 
2.15.1



[PATCH v2 05/17] rtlwifi: halmac: describe number and size of chip functions

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

The number and size of chip fucntions are different, such as TX/RX FIFO
size, efuse size, etc. So they are defined in an individual file.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_8822b_cfg.h| 68 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h   | 40 +
 2 files changed, 108 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
new file mode 100644
index ..f6ed7b44549c
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_8822b_cfg.h
@@ -0,0 +1,68 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_8822B_CFG_H_
+#define _HALMAC_8822B_CFG_H_
+
+#include "../halmac_88xx_cfg.h"
+
+#define TX_FIFO_SIZE_8822B 262144
+#define RX_FIFO_SIZE_8822B 24576
+#define TRX_SHARE_SIZE_8822B   65536
+
+#define RX_DESC_DUMMY_SIZE_8822B   72 /* 8 * 9 Bytes */
+#define RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B  80 /* 8 Byte alignment*/
+
+/* should be 8 Byte alignment*/
+#if (HALMAC_RX_FIFO_EXPANDING_MODE_PKT_SIZE <= \
+   RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B)
+#define RX_FIFO_EXPANDING_UNIT_8822B   (RX_DESC_SIZE_88XX + \
+   RX_DESC_DUMMY_SIZE_8822B + HALMAC_RX_FIFO_EXPANDING_MODE_PKT_SIZE)
+#else
+#define RX_FIFO_EXPANDING_UNIT_8822B (RX_DESC_SIZE_88XX + \
+   RX_DESC_DUMMY_SIZE_8822B + RX_FIFO_EXPANDING_MODE_PKT_SIZE_MAX_8822B)
+#endif
+
+#define TX_FIFO_SIZE_LA_8822B  (TX_FIFO_SIZE_8822B >>  1)
+#define TX_FIFO_SIZE_RX_EXPAND_1BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - TRX_SHARE_SIZE_8822B)
+#define RX_FIFO_SIZE_RX_EXPAND_1BLK_8822B  \
+   RX_FIFO_EXPANDING_UNIT_8822B << 8) - 1) >> 10) << 10)
+#define TX_FIFO_SIZE_RX_EXPAND_2BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - (2 * TRX_SHARE_SIZE_8822B))
+#define RX_FIFO_SIZE_RX_EXPAND_2BLK_8822B  \
+   (RX_FIFO_SIZE_8822B +  (2 * TRX_SHARE_SIZE_8822B))
+#define TX_FIFO_SIZE_RX_EXPAND_3BLK_8822B  \
+   (TX_FIFO_SIZE_8822B - (3 * TRX_SHARE_SIZE_8822B))
+#define RX_FIFO_SIZE_RX_EXPAND_3BLK_8822B  \
+   (RX_FIFO_SIZE_8822B +  (3 * TRX_SHARE_SIZE_8822B))
+
+#define EFUSE_SIZE_8822B   1024
+#define EEPROM_SIZE_8822B  768
+#define BT_EFUSE_SIZE_8822B128
+
+#define SEC_CAM_NUM_8822B  64
+
+#define OQT_ENTRY_AC_8822B 32
+#define OQT_ENTRY_NOAC_8822B   32
+#define MACID_MAX_8822B128
+
+#define WLAN_FW_IRAM_MAX_SIZE_8822B196608
+#define WLAN_FW_DRAM_MAX_SIZE_8822B49152
+#define WLAN_FW_ERAM_MAX_SIZE_8822B0
+#define WLAN_FW_MAX_SIZE_8822B (WLAN_FW_IRAM_MAX_SIZE_8822B + \
+   WLAN_FW_DRAM_MAX_SIZE_8822B + WLAN_FW_ERAM_MAX_SIZE_8822B)
+
+#endif
diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h
new file mode 100644
index ..22514ef4680d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_88xx_cfg.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef _HALMAC_88XX_CFG_H_
+#define _HALMAC_88XX_CFG_H_
+
+#include "../halmac_api.h"
+
+#define TX_PAGE_SIZE_88XX

[PATCH v2 10/17] rtlwifi: halmac: access efuse through halmac helper functions

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

This file provides interfaces to read and write efuse contents.

Signed-off-by: Ping-Ke Shih 
---
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c | 1918 
 .../rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h |  101 ++
 2 files changed, 2019 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
new file mode 100644
index ..3d51acb5857e
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_efuse_88xx.c
@@ -0,0 +1,1918 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_efuse_88xx.h"
+#include "halmac_88xx_cfg.h"
+#include "halmac_common_88xx.h"
+#include "halmac_init_88xx.h"
+
+#define RSVD_EFUSE_SIZE16
+#define RSVD_CS_EFUSE_SIZE 24
+#define PROTECT_EFUSE_SIZE 96
+#define FEATURE_DUMP_PHY_EFUSE HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE
+#define FEATURE_DUMP_LOG_EFUSE HALMAC_FEATURE_DUMP_LOGICAL_EFUSE
+
+static enum halmac_cmd_construct_state
+efuse_cmd_cnstr_state_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+proc_dump_efuse_88xx(struct halmac_adapter *adapter,
+enum halmac_efuse_read_cfg cfg);
+
+static enum halmac_ret_status
+read_hw_efuse_88xx(struct halmac_adapter *adapter, u32 offset, u32 size,
+  u8 *map);
+
+static enum halmac_ret_status
+eeprom_parser_88xx(struct halmac_adapter *adapter, u8 *phy_map, u8 *log_map);
+
+static enum halmac_ret_status
+read_log_efuse_map_88xx(struct halmac_adapter *adapter, u8 *map);
+
+static enum halmac_ret_status
+proc_pg_efuse_by_map_88xx(struct halmac_adapter *adapter,
+ struct halmac_pg_efuse_info *info,
+ enum halmac_efuse_read_cfg cfg);
+
+static enum halmac_ret_status
+dump_efuse_fw_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+dump_efuse_drv_88xx(struct halmac_adapter *adapter);
+
+static enum halmac_ret_status
+proc_write_log_efuse_88xx(struct halmac_adapter *adapter, u32 offset, u8 
value);
+
+static enum halmac_ret_status
+update_eeprom_mask_88xx(struct halmac_adapter *adapter,
+   struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static enum halmac_ret_status
+check_efuse_enough_88xx(struct halmac_adapter *adapter,
+   struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static enum halmac_ret_status
+pg_extend_efuse_88xx(struct halmac_adapter *adapter,
+struct halmac_pg_efuse_info *info, u8 word_en,
+u8 pre_word_en, u32 eeprom_offset);
+
+static enum halmac_ret_status
+proc_pg_efuse_88xx(struct halmac_adapter *adapter,
+  struct halmac_pg_efuse_info *info, u8 word_en,
+  u8 pre_word_en, u32 eeprom_offset);
+
+static enum halmac_ret_status
+program_efuse_88xx(struct halmac_adapter *adapter,
+  struct halmac_pg_efuse_info *info, u8 *updated_mask);
+
+static void
+mask_eeprom_88xx(struct halmac_adapter *adapter,
+struct halmac_pg_efuse_info *info);
+
+/**
+ * dump_efuse_map_88xx() - dump "physical" efuse map
+ * @adapter : the adapter of halmac
+ * @cfg : dump efuse method
+ * Author : Ivan Lin/KaiYuan Chang
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+dump_efuse_map_88xx(struct halmac_adapter *adapter,
+   enum halmac_efuse_read_cfg cfg)
+{
+   u8 *map = NULL;
+   u8 *efuse_map;
+   u32 efuse_size = adapter->hw_cfg_info.efuse_size;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.efuse_state.proc_status;
+
+   if (cfg == HALMAC_EFUSE_R_FW &&
+   halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+

[PATCH v2 01/17] rtlwifi: add halmac structure to wifi.h

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Add structure and ops to interact with halmac and other modules.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/wifi.h | 58 +
 1 file changed, 58 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index d27e33960e77..c8542b87cc2b 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2305,6 +2305,13 @@ struct rtl_hal_ops {
u16 (*get_available_desc)(struct ieee80211_hw *hw, u8 q_idx);
void (*c2h_content_parsing)(struct ieee80211_hw *hw, u8 tag, u8 len,
u8 *val);
+   /* ops for halmac cb */
+   bool (*halmac_cb_init_mac_register)(struct rtl_priv *rtlpriv);
+   bool (*halmac_cb_init_bb_rf_register)(struct rtl_priv *rtlpriv);
+   bool (*halmac_cb_write_data_rsvd_page)(struct rtl_priv *rtlpriv,
+  u8 *buf, u32 size);
+   bool (*halmac_cb_write_data_h2c)(struct rtl_priv *rtlpriv, u8 *buf,
+u32 size);
 };
 
 struct rtl_intf_ops {
@@ -2687,6 +2694,54 @@ struct rtl_btc_ops {
bool (*btc_is_bt_lps_on)(struct rtl_priv *rtlpriv);
 };
 
+struct rtl_halmac_ops {
+   int (*halmac_init_adapter)(struct rtl_priv *rtlpriv);
+   int (*halmac_deinit_adapter)(struct rtl_priv *rtlpriv);
+   int (*halmac_init_hal)(struct rtl_priv *rtlpriv);
+   int (*halmac_deinit_hal)(struct rtl_priv *rtlpriv);
+   int (*halmac_poweron)(struct rtl_priv *rtlpriv);
+   int (*halmac_poweroff)(struct rtl_priv *rtlpriv);
+
+   int (*halmac_phy_power_switch)(struct rtl_priv *rtlpriv, u8 enable);
+   int (*halmac_set_mac_address)(struct rtl_priv *rtlpriv, u8 hwport,
+ u8 *addr);
+   int (*halmac_set_bssid)(struct rtl_priv *rtlpriv, u8 hwport, u8 *addr);
+
+   int (*halmac_get_physical_efuse_size)(struct rtl_priv *rtlpriv,
+ u32 *size);
+   int (*halmac_read_physical_efuse_map)(struct rtl_priv *rtlpriv,
+ u8 *map, u32 size);
+   int (*halmac_get_logical_efuse_size)(struct rtl_priv *rtlpriv,
+u32 *size);
+   int (*halmac_read_logical_efuse_map)(struct rtl_priv *rtlpriv, u8 *map,
+u32 size);
+
+   int (*halmac_set_bandwidth)(struct rtl_priv *rtlpriv, u8 channel,
+   u8 pri_ch_idx, u8 bw);
+
+   int (*halmac_c2h_handle)(struct rtl_priv *rtlpriv, u8 *c2h, u32 size);
+
+   int (*halmac_chk_txdesc)(struct rtl_priv *rtlpriv, u8 *txdesc,
+u32 size);
+   int (*halmac_iqk)(struct rtl_priv *rtlpriv, u8 clear, u8 segment);
+};
+
+struct rtl_halmac_indicator {
+   struct completion *comp;
+   u32 wait_ms;
+
+   u8 *buffer;
+   u32 buf_size;
+   u32 ret_size;
+   u32 status;
+};
+
+struct rtl_halmac {
+   const struct rtl_halmac_ops *ops;
+   void *internal; /* internal context of halmac, i.e. PHALMAC_ADAPTER */
+   struct rtl_halmac_indicator *indicator; /* size=10 */
+};
+
 struct proxim {
bool proxim_on;
 
@@ -2792,6 +2847,9 @@ struct rtl_priv {
/*for bt coexist use*/
struct bt_coexist_info btcoexist;
 
+   /* halmac for newer ICs */
+   struct rtl_halmac halmac;
+
/* separate 92ee from other ICs,
 * 92ee use new trx flow.
 */
-- 
2.15.1



[PATCH v2 11/17] rtlwifi: halmac: add files to implement halmac ops

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

The structure halmac_ops defined in wifi.h, and this commit implements and
hooks ops to the structure, so a symbol rtl_halmac_get_ops_pointer is
expoerted to access this module. Meanwhile, we implement ops defined and
needed by this module.

Signed-off-by: Ping-Ke Shih 
---
 .../wireless/realtek/rtlwifi/halmac/rtl_halmac.c   | 1403 
 .../wireless/realtek/rtlwifi/halmac/rtl_halmac.h   |   77 ++
 2 files changed, 1480 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
new file mode 100644
index ..d9b81824728d
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/rtl_halmac.c
@@ -0,0 +1,1403 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_api.h"
+#include "rtl_halmac.h"
+#include 
+#include 
+
+#define rtlpriv_to_halmac(priv)
\
+   ((struct halmac_adapter *)((priv)->halmac.internal))
+
+#define DEFAULT_INDICATOR_TIMELMT msecs_to_jiffies(1000) /* ms */
+
+const struct rtl_halmac_ops rtl_halmac_operation = {
+   .halmac_init_adapter = rtl_halmac_init_adapter,
+   .halmac_deinit_adapter = rtl_halmac_deinit_adapter,
+   .halmac_init_hal = rtl_halmac_init_hal,
+   .halmac_deinit_hal = rtl_halmac_deinit_hal,
+   .halmac_poweron = rtl_halmac_poweron,
+   .halmac_poweroff = rtl_halmac_poweroff,
+
+   .halmac_phy_power_switch = rtl_halmac_phy_power_switch,
+   .halmac_set_mac_address = rtl_halmac_set_mac_address,
+   .halmac_set_bssid = rtl_halmac_set_bssid,
+
+   .halmac_get_physical_efuse_size = rtl_halmac_get_physical_efuse_size,
+   .halmac_read_physical_efuse_map = rtl_halmac_read_physical_efuse_map,
+   .halmac_get_logical_efuse_size = rtl_halmac_get_logical_efuse_size,
+   .halmac_read_logical_efuse_map = rtl_halmac_read_logical_efuse_map,
+
+   .halmac_set_bandwidth = rtl_halmac_set_bandwidth,
+
+   .halmac_c2h_handle = rtl_halmac_c2h_handle,
+
+   .halmac_chk_txdesc = rtl_halmac_chk_txdesc,
+   .halmac_iqk = rtl_halmac_iqk,
+};
+EXPORT_SYMBOL(rtl_halmac_operation);
+
+enum pltfm_ret_status {
+   FLTFM_RET_FAIL = 0,
+   FLTFM_RET_SUCCESS = 1,
+};
+
+static u8 _halmac_reg_read_8(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_byte(rtlpriv, offset);
+}
+
+static u16 _halmac_reg_read_16(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_word(rtlpriv, offset);
+}
+
+static u32 _halmac_reg_read_32(void *p, u32 offset)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   return rtl_read_dword(rtlpriv, offset);
+}
+
+static void _halmac_reg_write_8(void *p, u32 offset, u8 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_byte(rtlpriv, offset, val);
+}
+
+static void _halmac_reg_write_16(void *p, u32 offset, u16 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_word(rtlpriv, offset, val);
+}
+
+static void _halmac_reg_write_32(void *p, u32 offset, u32 val)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   rtl_write_dword(rtlpriv, offset, val);
+}
+
+static u8 _halmac_write_data_rsvd_page(void *p, u8 *buf, u32 size)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   if (rtlpriv->cfg->ops->halmac_cb_write_data_rsvd_page &&
+   rtlpriv->cfg->ops->halmac_cb_write_data_rsvd_page(rtlpriv, buf,
+ size))
+   return FLTFM_RET_SUCCESS;
+
+   return FLTFM_RET_FAIL;
+}
+
+static u8 _halmac_write_data_h2c(void *p, u8 *buf, u32 size)
+{
+   struct rtl_priv *rtlpriv = (struct rtl_priv *)p;
+
+   if (rtlpriv->cfg->ops->halmac_cb_write_data_h2c &&
+   rtlpriv->cfg->ops->halmac_cb_write_data_h2c(rtlpriv, buf, size))
+   return FLTFM_RET_SUCCESS;
+
+   return FLTFM_RET_FAIL;
+}
+
+static const char *const RTL_HALMAC_FEATURE_NAME[] = {
+   

[PATCH v2 08/17] rtlwifi: halmac: add GPIO pin/pinmux definitions

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

GPIO with pinmux can switch to many functions such as LED, UART, JTAG,
WoWLAN, etc.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.c   | 847 +
 .../halmac_88xx/halmac_8822b/halmac_gpio_8822b.h   |  34 +
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c  | 415 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h  |  55 ++
 .../realtek/rtlwifi/halmac/halmac_gpio_cmd.h   |  84 ++
 5 files changed, 1435 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_gpio_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_gpio_cmd.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
new file mode 100644
index ..3d43de98bb46
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_gpio_8822b.c
@@ -0,0 +1,847 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_gpio_8822b.h"
+#include "../halmac_gpio_88xx.h"
+
+/* GPIO0 definition */
+#define GPIO0_BT_GPIO0_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO0_BT_ACT_8822B \
+   {HALMAC_BT_PTA, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x41, BIT(1), 0}
+#define GPIO0_WL_ACT_8822B \
+   {HALMAC_WL_PTA, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO0_WLMAC_DBG_GPIO0_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO0, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO0_WLPHY_DBG_GPIO0_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO0_BT_DBG_GPIO0_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO0, HALMAC_GPIO_OUT, \
+   0x40, BIT(1) | BIT(0), BIT(0) | BIT(1)}
+#define GPIO0_SW_IO_8822B  \
+   {HALMAC_SW_IO, HALMAC_GPIO0, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), 0}
+
+/* GPIO1 definition */
+#define GPIO1_BT_GPIO1_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO1_BT_3DD_SYNC_A_8822B  \
+   {HALMAC_BT_3DDLS_A, HALMAC_GPIO1, HALMAC_GPIO_IN, \
+0x66, BIT(2), BIT(2)}
+#define GPIO1_WL_CK_8822B  \
+   {HALMAC_BT_PTA, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x41, BIT(1), 0}
+#define GPIO1_BT_CK_8822B  \
+   {HALMAC_WL_PTA, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO1_WLMAC_DBG_GPIO1_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO1_WLPHY_DBG_GPIO1_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO1_BT_DBG_GPIO1_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO1, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0) | BIT(1)}
+#define GPIO1_SW_IO_8822B  \
+   {HALMAC_SW_IO, HALMAC_GPIO1, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), 0}
+
+/* GPIO2 definition */
+#define GPIO2_BT_GPIO2_8822B   \
+   {HALMAC_BT_GPIO, HALMAC_GPIO2, HALMAC_GPIO_IN_OUT, \
+0x66, BIT(2), BIT(2)}
+#define GPIO2_WL_STATE_8822B   \
+   {HALMAC_BT_PTA, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x41, BIT(1), 0}
+#define GPIO2_BT_STATE_8822B   \
+   {HALMAC_WL_PTA, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x41, BIT(2), BIT(2)}
+#define GPIO2_WLMAC_DBG_GPIO2_8822B\
+   {HALMAC_WLMAC_DBG, HALMAC_GPIO2, HALMAC_GPIO_OUT, \
+0x40, BIT(1) | BIT(0), BIT(0)}
+#define GPIO2_WLPHY_DBG_GPIO2_8822B\
+   {HALMAC_WLPHY_DBG, HALMAC_GPIO2, HALMAC_GPIO_IN_OUT, \
+0x40, BIT(1) | BIT(0), BIT(1)}
+#define GPIO2_BT_DBG_GPIO2_8822B   \
+   {HALMAC_BT_DBG, HALMAC_GPIO2, 

[PATCH v2 03/17] rtlwifi: add dmdef.h to share with driver and other modules

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

This header file is maintained by new module phydm, and share with
driver and other modules, such as halmac. This patch adds only one
enumeration, and more information will be added later.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/dmdef.h | 40 
 drivers/net/wireless/realtek/rtlwifi/wifi.h  |  1 +
 2 files changed, 41 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/dmdef.h

diff --git a/drivers/net/wireless/realtek/rtlwifi/dmdef.h 
b/drivers/net/wireless/realtek/rtlwifi/dmdef.h
new file mode 100644
index ..5560cd1f98ed
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/dmdef.h
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright(c) 2007 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#ifndef __RTL_DMINFO_H__
+#define __RTL_DMINFO_H__
+
+enum bb_path {
+   BB_PATH_A = 0x0001,
+   BB_PATH_B = 0x0002,
+   BB_PATH_C = 0x0004,
+   BB_PATH_D = 0x0008,
+
+   BB_PATH_AB = (BB_PATH_A | BB_PATH_B),
+   BB_PATH_AC = (BB_PATH_A | BB_PATH_C),
+   BB_PATH_AD = (BB_PATH_A | BB_PATH_D),
+   BB_PATH_BC = (BB_PATH_B | BB_PATH_C),
+   BB_PATH_BD = (BB_PATH_B | BB_PATH_D),
+   BB_PATH_CD = (BB_PATH_C | BB_PATH_D),
+
+   BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C),
+   BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D),
+   BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D),
+   BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D),
+
+   BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D),
+};
+
+#endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h 
b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index c8542b87cc2b..c32985cfe48d 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include "dmdef.h"
 #include "debug.h"
 
 #defineMASKBYTE0   0xff
-- 
2.15.1



[PATCH v2 15/17] rtlwifi: halmac: add to control WiFi mac functions and registers

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

This commit provides WiFi mac functions to control wifi easier, and also
provides generic access entries for driver and other modules.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_8822b/halmac_cfg_wmac_8822b.c   |  144 +
 .../halmac_8822b/halmac_cfg_wmac_8822b.h   |   36 +
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.c |  173 ++
 .../halmac_88xx/halmac_8822b/halmac_common_8822b.h |   32 +
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.c  | 1158 
 .../halmac/halmac_88xx/halmac_cfg_wmac_88xx.h  |  122 +
 .../halmac/halmac_88xx/halmac_common_88xx.c| 2931 
 .../halmac/halmac_88xx/halmac_common_88xx.h|  151 +
 8 files changed, 4747 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_common_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_common_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_cfg_wmac_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_cfg_wmac_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_common_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_common_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
new file mode 100644
index ..7de83d7bf922
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.c
@@ -0,0 +1,144 @@
+/**
+ *
+ * Copyright(c) 2017 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_cfg_wmac_8822b.h"
+#include "halmac_8822b_cfg.h"
+
+/**
+ * cfg_drv_info_8822b() - config driver info
+ * @adapter : the adapter of halmac
+ * @drv_info : driver information selection
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+cfg_drv_info_8822b(struct halmac_adapter *adapter,
+  enum halmac_drv_info drv_info)
+{
+   u8 drv_info_size = 0;
+   u8 phy_status_en = 0;
+   u8 sniffer_en = 0;
+   u8 plcp_hdr_en = 0;
+   u8 value8;
+   u32 value32;
+   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG,
+"drv info = %d\n", drv_info);
+
+   switch (drv_info) {
+   case HALMAC_DRV_INFO_NONE:
+   drv_info_size = 0;
+   phy_status_en = 0;
+   sniffer_en = 0;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_STATUS:
+   drv_info_size = 4;
+   phy_status_en = 1;
+   sniffer_en = 0;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_SNIFFER:
+   drv_info_size = 5; /* phy status 4byte, sniffer info 1byte */
+   phy_status_en = 1;
+   sniffer_en = 1;
+   plcp_hdr_en = 0;
+   break;
+   case HALMAC_DRV_INFO_PHY_PLCP:
+   drv_info_size = 6; /* phy status 4byte, plcp header 2byte */
+   phy_status_en = 1;
+   sniffer_en = 0;
+   plcp_hdr_en = 1;
+   break;
+   default:
+   return HALMAC_RET_SW_CASE_NOT_SUPPORT;
+   }
+
+   if (adapter->txff_alloc.rx_fifo_exp_mode !=
+   HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE)
+   drv_info_size = RX_DESC_DUMMY_SIZE_8822B >> 3;
+
+   HALMAC_REG_W8(REG_RX_DRVINFO_SZ, drv_info_size);
+
+   value8 = HALMAC_REG_R8(REG_TRXFF_BNDY + 1);
+   value8 &= 0xF0;
+   /* For rxdesc len = 0 issue */
+   value8 |= 0xF;
+   

[PATCH v2 12/17] rtlwifi: halmac: add halmac init/deinit functions

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Add files to initialize and free halmac context. Since halmac is an three
levels hierarchy file structure, so the added files provide interfaces of
halmac, 88xx and 8822b.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.c   |  688 +
 .../halmac_88xx/halmac_8822b/halmac_init_8822b.h   |   33 +
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c  | 1071 
 .../rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h  |   70 ++
 .../wireless/realtek/rtlwifi/halmac/halmac_api.c   |  438 
 .../wireless/realtek/rtlwifi/halmac/halmac_api.h   |   65 ++
 6 files changed, 2365 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_init_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_init_88xx.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_api.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_api.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
new file mode 100644
index ..57509fd5942a
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_init_8822b.c
@@ -0,0 +1,688 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_init_8822b.h"
+#include "halmac_8822b_cfg.h"
+#include "halmac_pcie_8822b.h"
+#include "halmac_sdio_8822b.h"
+#include "halmac_usb_8822b.h"
+#include "halmac_gpio_8822b.h"
+#include "halmac_common_8822b.h"
+#include "halmac_cfg_wmac_8822b.h"
+#include "../halmac_common_88xx.h"
+#include "../halmac_init_88xx.h"
+
+#define RSVD_PG_DRV_NUM16
+#define RSVD_PG_H2C_EXTRAINFO_NUM  24
+#define RSVD_PG_H2C_STATICINFO_NUM 8
+#define RSVD_PG_H2CQ_NUM   8
+#define RSVD_PG_CPU_INSTRUCTION_NUM0
+#define RSVD_PG_FW_TXBUF_NUM   4
+#define RSVD_PG_CSIBUF_NUM 0
+#define RSVD_PG_DLLB_NUM   (TX_FIFO_SIZE_8822B / 3 >> \
+   TX_PAGE_SIZE_SHIFT_88XX)
+
+#define MAC_TRX_ENABLE (BIT_HCI_TXDMA_EN | BIT_HCI_RXDMA_EN | BIT_TXDMA_EN | \
+   BIT_RXDMA_EN | BIT_PROTOCOL_EN | BIT_SCHEDULE_EN | \
+   BIT_MACTXEN | BIT_MACRXEN)
+
+#define BLK_DESC_NUM   0x3
+
+#define WLAN_AMPDU_MAX_TIME0x70
+#define WLAN_RTS_LEN_TH0xFF
+#define WLAN_RTS_TX_TIME_TH0x08
+#define WLAN_MAX_AGG_PKT_LIMIT 0x20
+#define WLAN_RTS_MAX_AGG_PKT_LIMIT 0x20
+#define WALN_FAST_EDCA_VO_TH   0x06
+#define WLAN_FAST_EDCA_VI_TH   0x06
+#define WLAN_FAST_EDCA_BE_TH   0x06
+#define WLAN_FAST_EDCA_BK_TH   0x06
+#define WLAN_BAR_RETRY_LIMIT   0x01
+#define WLAN_RA_TRY_RATE_AGG_LIMIT 0x08
+
+/*SDIO RQPN Mapping*/
+static struct halmac_rqpn HALMAC_RQPN_SDIO_8822B[] = {
+   /* { mode, vo_map, vi_map, be_map, bk_map, mg_map, hi_map } */
+   {HALMAC_TRX_MODE_NORMAL,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_TRXSHARE,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_WMM,
+HALMAC_MAP2_HQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_NQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_P2P,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_LOOPBACK,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+   {HALMAC_TRX_MODE_DELAY_LOOPBACK,
+HALMAC_MAP2_NQ, HALMAC_MAP2_NQ, HALMAC_MAP2_LQ, HALMAC_MAP2_LQ,
+HALMAC_MAP2_EXQ, HALMAC_MAP2_HQ},
+};
+
+/*PCIE RQPN Mapping*/
+static struct halmac_rqpn HALMAC_RQPN_PCIE_8822B[] 

[PATCH v2 16/17] rtlwifi: halmac: add to support BB and RF functions

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Some BB and RF functions collaborate with firmware or MAC. For instances,
the IQK and PSD functions are implemented in firmware, so use a H2C command
to trigger. For MIMO function, use the helper functions to control related
MAC registers.

Signed-off-by: Ping-Ke Shih 
---
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c | 397 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h |  53 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c  | 869 +
 .../rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h  |  79 ++
 4 files changed, 1398 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_mimo_88xx.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
new file mode 100644
index ..06990ee78ebd
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_bb_rf_88xx.c
@@ -0,0 +1,397 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_bb_rf_88xx.h"
+#include "halmac_88xx_cfg.h"
+#include "halmac_common_88xx.h"
+#include "halmac_init_88xx.h"
+
+/**
+ * start_iqk_88xx() -trigger FW IQK
+ * @adapter : the adapter of halmac
+ * @param : IQK parameter
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+start_iqk_88xx(struct halmac_adapter *adapter, struct halmac_iqk_para *param)
+{
+   u8 h2c_buf[H2C_PKT_SIZE_88XX] = { 0 };
+   u16 seq_num = 0;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   struct halmac_h2c_header_info hdr_info;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.iqk_state.proc_status;
+
+   if (halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+
+   if (*proc_status == HALMAC_CMD_PROCESS_SENDING) {
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG,
+"Wait event(iqk)\n");
+   return HALMAC_RET_BUSY_STATE;
+   }
+
+   *proc_status = HALMAC_CMD_PROCESS_SENDING;
+
+   IQK_SET_CLEAR(h2c_buf, param->clear);
+   IQK_SET_SEGMENT_IQK(h2c_buf, param->segment_iqk);
+
+   hdr_info.sub_cmd_id = SUB_CMD_ID_IQK;
+   hdr_info.content_size = 1;
+   hdr_info.ack = 1;
+   set_h2c_pkt_hdr_88xx(adapter, h2c_buf, _info, _num);
+
+   adapter->halmac_state.iqk_state.seq_num = seq_num;
+
+   status = send_h2c_pkt_88xx(adapter, h2c_buf);
+
+   if (status != HALMAC_RET_SUCCESS) {
+   pr_err("send h2c pkt fail!!\n");
+   reset_ofld_feature_88xx(adapter, HALMAC_FEATURE_IQK);
+   return status;
+   }
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s <===\n",
+__func__);
+
+   return HALMAC_RET_SUCCESS;
+}
+
+/**
+ * ctrl_pwr_tracking_88xx() -trigger FW power tracking
+ * @adapter : the adapter of halmac
+ * @opt : power tracking option
+ * Author : KaiYuan Chang/Ivan Lin
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+ctrl_pwr_tracking_88xx(struct halmac_adapter *adapter,
+  struct halmac_pwr_tracking_option *opt)
+{
+   u8 h2c_buf[H2C_PKT_SIZE_88XX] = { 0 };
+   u16 seq_num = 0;
+   enum halmac_ret_status status = HALMAC_RET_SUCCESS;
+   struct halmac_h2c_header_info hdr_info;
+   struct halmac_pwr_tracking_para *param;
+   enum halmac_cmd_process_status *proc_status;
+
+   proc_status = >halmac_state.pwr_trk_state.proc_status;
+
+   if (halmac_fw_validate(adapter) != HALMAC_RET_SUCCESS)
+   return HALMAC_RET_NO_DLFW;
+
+   

[PATCH v2 17/17] rtlwifi: add halmac to Makefile and Kconfig

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

Add halmac to Makefile and Kconfig, so we can build this module if 8822BE
is selected.

Signed-off-by: Ping-Ke Shih 
---
 drivers/net/wireless/realtek/rtlwifi/Kconfig   |  5 
 drivers/net/wireless/realtek/rtlwifi/Makefile  |  1 +
 .../net/wireless/realtek/rtlwifi/halmac/Makefile   | 29 ++
 3 files changed, 35 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/Makefile

diff --git a/drivers/net/wireless/realtek/rtlwifi/Kconfig 
b/drivers/net/wireless/realtek/rtlwifi/Kconfig
index 73067cac289c..d9aba8fed151 100644
--- a/drivers/net/wireless/realtek/rtlwifi/Kconfig
+++ b/drivers/net/wireless/realtek/rtlwifi/Kconfig
@@ -151,4 +151,9 @@ config RTLBTCOEXIST
depends on RTL8723AE || RTL8723BE || RTL8821AE || RTL8192EE
default y
 
+config RTLHALMAC
+   tristate
+   depends on RTL8822BE
+   default y
+
 endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/Makefile
index 09c30e428375..a30a73c351d8 100644
--- a/drivers/net/wireless/realtek/rtlwifi/Makefile
+++ b/drivers/net/wireless/realtek/rtlwifi/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_RTL8723AE)   += rtl8723ae/
 obj-$(CONFIG_RTL8723BE)+= rtl8723be/
 obj-$(CONFIG_RTL8188EE)+= rtl8188ee/
 obj-$(CONFIG_RTLBTCOEXIST) += btcoexist/
+obj-$(CONFIG_RTLHALMAC)+= halmac/
 obj-$(CONFIG_RTL8723_COMMON)   += rtl8723com/
 obj-$(CONFIG_RTL8821AE)+= rtl8821ae/
 obj-$(CONFIG_RTL8192EE)+= rtl8192ee/
diff --git a/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile 
b/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile
new file mode 100644
index ..41c1ae7e5e53
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/halmac/Makefile
@@ -0,0 +1,29 @@
+
+
+halmac-objs := \
+   halmac_api.o\
+   halmac_88xx/halmac_bb_rf_88xx.o \
+   halmac_88xx/halmac_efuse_88xx.o \
+   halmac_88xx/halmac_gpio_88xx.o  \
+   halmac_88xx/halmac_pcie_88xx.o  \
+   halmac_88xx/halmac_sdio_88xx.o  \
+   halmac_88xx/halmac_usb_88xx.o   \
+   halmac_88xx/halmac_cfg_wmac_88xx.o  \
+   halmac_88xx/halmac_flash_88xx.o \
+   halmac_88xx/halmac_init_88xx.o  \
+   halmac_88xx/halmac_common_88xx.o\
+   halmac_88xx/halmac_fw_88xx.o\
+   halmac_88xx/halmac_mimo_88xx.o  \
+   halmac_88xx/halmac_8822b/halmac_gpio_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_pcie_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_sdio_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_usb_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_pwr_seq_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_common_8822b.o  \
+   halmac_88xx/halmac_8822b/halmac_cfg_wmac_8822b.o\
+   halmac_88xx/halmac_8822b/halmac_phy_8822b.o \
+   halmac_88xx/halmac_8822b/halmac_init_8822b.o\
+   rtl_halmac.o
+
+
+obj-m = halmac.o
-- 
2.15.1



[PATCH v2 14/17] rtlwifi: halmac: add bus interface commands

2018-04-03 Thread pkshih
From: Ping-Ke Shih 

The halmac supports three buses interfaces, PCI, USB and SDIO, and this
commit makes it possible to change their phy parameters.

Signed-off-by: Ping-Ke Shih 
---
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.c   | 218 +
 .../halmac_88xx/halmac_8822b/halmac_pcie_8822b.h   |  38 +
 .../halmac_88xx/halmac_8822b/halmac_phy_8822b.c| 148 
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.c   | 880 
 .../halmac_88xx/halmac_8822b/halmac_sdio_8822b.h   |  62 ++
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.c| 161 
 .../halmac_88xx/halmac_8822b/halmac_usb_8822b.h|  38 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c  | 538 +
 .../rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h  |  98 +++
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c  | 895 +
 .../rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h  |  75 ++
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c   | 522 
 .../rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h   |  83 ++
 .../realtek/rtlwifi/halmac/halmac_intf_phy_cmd.h   |  45 ++
 .../realtek/rtlwifi/halmac/halmac_pcie_reg.h   |  36 +
 .../realtek/rtlwifi/halmac/halmac_sdio_reg.h   |  53 ++
 .../realtek/rtlwifi/halmac/halmac_usb_reg.h|  19 +
 17 files changed, 3909 insertions(+)
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_phy_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_sdio_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_sdio_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_usb_8822b.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_usb_8822b.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_pcie_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_sdio_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.c
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_usb_88xx.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_intf_phy_cmd.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_pcie_reg.h
 create mode 100644 
drivers/net/wireless/realtek/rtlwifi/halmac/halmac_sdio_reg.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/halmac/halmac_usb_reg.h

diff --git 
a/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
new file mode 100644
index ..88a148e528a5
--- /dev/null
+++ 
b/drivers/net/wireless/realtek/rtlwifi/halmac/halmac_88xx/halmac_8822b/halmac_pcie_8822b.c
@@ -0,0 +1,218 @@
+/**
+ *
+ * Copyright(c) 2016 - 2018 Realtek Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ 
**/
+
+#include "halmac_pcie_8822b.h"
+#include "halmac_pwr_seq_8822b.h"
+#include "../halmac_init_88xx.h"
+#include "../halmac_common_88xx.h"
+#include "../halmac_pcie_88xx.h"
+#include "../halmac_88xx_cfg.h"
+
+/**
+ * mac_pwr_switch_pcie_8822b() - switch mac power
+ * @adapter : the adapter of halmac
+ * @pwr : power state
+ * Author : KaiYuan Chang
+ * Return : enum halmac_ret_status
+ * More details of status code can be found in prototype document
+ */
+enum halmac_ret_status
+mac_pwr_switch_pcie_8822b(struct halmac_adapter *adapter,
+ enum halmac_mac_power pwr)
+{
+   u8 value8;
+   u8 rpwm;
+   struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
+   enum halmac_ret_status status;
+
+   RT_TRACE(adapter->drv_adapter, COMP_HALMAC, DBG_DMESG, "%s ===>\n",
+__func__);
+   

  1   2   3   >