[PATCH v2 1/3] mwifiex: refactor device dump code to make it generic for usb interface

2017-11-26 Thread Xinming Hu
This patch refactor current device dump code to make it generic
for subsequent implementation on usb interface.

Signed-off-by: Xinming Hu 
Signed-off-by: Cathy Luo 
Signed-off-by: Ganapathi Bhat 
---
v2: Addressed below review comments from Brian Norris
a) use new API timer_setup/from_timer.
b) reset devdump_len during initization
---
 drivers/net/wireless/marvell/mwifiex/init.c |  1 +
 drivers/net/wireless/marvell/mwifiex/main.c | 87 +++--
 drivers/net/wireless/marvell/mwifiex/main.h | 11 +++-
 drivers/net/wireless/marvell/mwifiex/pcie.c | 13 +++--
 drivers/net/wireless/marvell/mwifiex/sdio.c | 14 +++--
 5 files changed, 72 insertions(+), 54 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/init.c 
b/drivers/net/wireless/marvell/mwifiex/init.c
index e1aa860..b0d3d68 100644
--- a/drivers/net/wireless/marvell/mwifiex/init.c
+++ b/drivers/net/wireless/marvell/mwifiex/init.c
@@ -314,6 +314,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter 
*adapter)
adapter->iface_limit.p2p_intf = MWIFIEX_MAX_P2P_NUM;
adapter->active_scan_triggered = false;
timer_setup(>wakeup_timer, wakeup_timer_fn, 0);
+   adapter->devdump_len = 0;
 }
 
 /*
diff --git a/drivers/net/wireless/marvell/mwifiex/main.c 
b/drivers/net/wireless/marvell/mwifiex/main.c
index a96bd7e..f7d0299 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.c
+++ b/drivers/net/wireless/marvell/mwifiex/main.c
@@ -1051,9 +1051,23 @@ void mwifiex_multi_chan_resync(struct mwifiex_adapter 
*adapter)
 }
 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
 
-int mwifiex_drv_info_dump(struct mwifiex_adapter *adapter, void **drv_info)
+void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)
 {
-   void *p;
+   /* Dump all the memory data into single file, a userspace script will
+* be used to split all the memory data to multiple files
+*/
+   mwifiex_dbg(adapter, MSG,
+   "== mwifiex dump information to /sys/class/devcoredump 
start");
+   dev_coredumpv(adapter->dev, adapter->devdump_data, adapter->devdump_len,
+ GFP_KERNEL);
+   mwifiex_dbg(adapter, MSG,
+   "== mwifiex dump information to /sys/class/devcoredump 
end");
+}
+EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
+
+void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter)
+{
+   char *p;
char drv_version[64];
struct usb_card_rec *cardp;
struct sdio_mmc_card *sdio_card;
@@ -1061,17 +1075,12 @@ int mwifiex_drv_info_dump(struct mwifiex_adapter 
*adapter, void **drv_info)
int i, idx;
struct netdev_queue *txq;
struct mwifiex_debug_info *debug_info;
-   void *drv_info_dump;
 
mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
 
-   /* memory allocate here should be free in mwifiex_upload_device_dump*/
-   drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
-
-   if (!drv_info_dump)
-   return 0;
-
-   p = (char *)(drv_info_dump);
+   p = adapter->devdump_data;
+   strcpy(p, "Start dump driverinfo\n");
+   p += strlen("Start dump driverinfo\n");
p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
 
mwifiex_drv_get_driver_version(adapter, drv_version,
@@ -1155,21 +1164,18 @@ int mwifiex_drv_info_dump(struct mwifiex_adapter 
*adapter, void **drv_info)
kfree(debug_info);
}
 
+   strcpy(p, "\nEnd dump\n");
+   p += strlen("\nEnd dump\n");
mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
-   *drv_info = drv_info_dump;
-   return p - drv_info_dump;
+   adapter->devdump_len = p - (char *)adapter->devdump_data;
 }
 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
 
-void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter, void 
*drv_info,
-   int drv_info_size)
+void mwifiex_prepare_fw_dump_info(struct mwifiex_adapter *adapter)
 {
-   u8 idx, *dump_data, *fw_dump_ptr;
-   u32 dump_len;
-
-   dump_len = (strlen("Start dump driverinfo\n") +
-  drv_info_size +
-  strlen("\nEnd dump\n"));
+   u8 idx;
+   char *fw_dump_ptr;
+   u32 dump_len = 0;
 
for (idx = 0; idx < adapter->num_mem_types; idx++) {
struct memory_type_mapping *entry =
@@ -1184,24 +1190,24 @@ void mwifiex_upload_device_dump(struct mwifiex_adapter 
*adapter, void *drv_info,
}
}
 
-   dump_data = vzalloc(dump_len + 1);
-   if (!dump_data)
-   goto done;
-
-   fw_dump_ptr = dump_data;
+   if (dump_len + 1 + adapter->devdump_len > MWIFIEX_FW_DUMP_SIZE) {
+   /* Realloc in case buffer overflow */
+   fw_dump_ptr = vzalloc(dump_len + 1 + 

[PATCH v2 3/3] mwifiex: debugfs: trigger device dump for usb interface

2017-11-26 Thread Xinming Hu
This patch extend device_dump debugfs function to make it
works for usb interface.

Signed-off-by: Xinming Hu 
Signed-off-by: Cathy Luo 
---
v2: Same as v1
---
 drivers/net/wireless/marvell/mwifiex/cmdevt.c  | 11 +++
 drivers/net/wireless/marvell/mwifiex/debugfs.c |  9 +
 drivers/net/wireless/marvell/mwifiex/fw.h  |  1 +
 drivers/net/wireless/marvell/mwifiex/sta_cmd.c |  4 
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c 
b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
index dcc529e..8746600 100644
--- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
@@ -290,13 +290,16 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private 
*priv,
adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] =
get_unaligned_le16((u8 *)host_cmd + S_DS_GEN);
 
+   /* Setup the timer after transmit command, except that specific
+* command might not have command response.
+*/
+   if (cmd_code != HostCmd_CMD_FW_DUMP_EVENT)
+   mod_timer(>cmd_timer,
+ jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
+
/* Clear BSS_NO_BITS from HostCmd */
cmd_code &= HostCmd_CMD_ID_MASK;
 
-   /* Setup the timer after transmit command */
-   mod_timer(>cmd_timer,
- jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
-
return 0;
 }
 
diff --git a/drivers/net/wireless/marvell/mwifiex/debugfs.c 
b/drivers/net/wireless/marvell/mwifiex/debugfs.c
index 6f4239b..5d476de 100644
--- a/drivers/net/wireless/marvell/mwifiex/debugfs.c
+++ b/drivers/net/wireless/marvell/mwifiex/debugfs.c
@@ -168,10 +168,11 @@
 {
struct mwifiex_private *priv = file->private_data;
 
-   if (!priv->adapter->if_ops.device_dump)
-   return -EIO;
-
-   priv->adapter->if_ops.device_dump(priv->adapter);
+   if (priv->adapter->iface_type == MWIFIEX_USB)
+   mwifiex_send_cmd(priv, HostCmd_CMD_FW_DUMP_EVENT,
+HostCmd_ACT_GEN_SET, 0, NULL, true);
+   else
+   priv->adapter->if_ops.device_dump(priv->adapter);
 
return 0;
 }
diff --git a/drivers/net/wireless/marvell/mwifiex/fw.h 
b/drivers/net/wireless/marvell/mwifiex/fw.h
index 4d5e686..9c2cdef 100644
--- a/drivers/net/wireless/marvell/mwifiex/fw.h
+++ b/drivers/net/wireless/marvell/mwifiex/fw.h
@@ -409,6 +409,7 @@ enum MWIFIEX_802_11_PRIVACY_FILTER {
 #define HostCmd_CMD_TDLS_CONFIG   0x0100
 #define HostCmd_CMD_MC_POLICY 0x0121
 #define HostCmd_CMD_TDLS_OPER 0x0122
+#define HostCmd_CMD_FW_DUMP_EVENT0x0125
 #define HostCmd_CMD_SDIO_SP_RX_AGGR_CFG   0x0223
 #define HostCmd_CMD_CHAN_REGION_CFG  0x0242
 #define HostCmd_CMD_PACKET_AGGR_CTRL 0x0251
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c 
b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
index fb09014..211e47d 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
@@ -2206,6 +2206,10 @@ int mwifiex_sta_prepare_cmd(struct mwifiex_private 
*priv, uint16_t cmd_no,
case HostCmd_CMD_CHAN_REGION_CFG:
ret = mwifiex_cmd_chan_region_cfg(priv, cmd_ptr, cmd_action);
break;
+   case HostCmd_CMD_FW_DUMP_EVENT:
+   cmd_ptr->command = cpu_to_le16(cmd_no);
+   cmd_ptr->size = cpu_to_le16(S_DS_GEN);
+   break;
default:
mwifiex_dbg(priv->adapter, ERROR,
"PREP_CMD: unknown cmd- %#x\n", cmd_no);
-- 
1.9.1



[PATCH v2 2/3] mwifiex: device dump support for usb interface

2017-11-26 Thread Xinming Hu
Firmware dump on usb interface is different with current
sdio/pcie chipset, which is based on register operation.

When firmware hang on usb interface, context dump will be
upload to host using 0x73 firmware debug event.

This patch store dump data from debug event and send to
userspace using device coredump API.

Signed-off-by: Xinming Hu 
Signed-off-by: Cathy Luo 
---
v2: Addressed below review comments from Brian Norris
a) Check for overflow introduced by invalid event.
b) Use end of transmission signal to recognize last event.
---
 drivers/net/wireless/marvell/mwifiex/fw.h| 10 
 drivers/net/wireless/marvell/mwifiex/init.c  |  9 
 drivers/net/wireless/marvell/mwifiex/main.h  |  2 +
 drivers/net/wireless/marvell/mwifiex/sta_event.c | 61 
 4 files changed, 82 insertions(+)

diff --git a/drivers/net/wireless/marvell/mwifiex/fw.h 
b/drivers/net/wireless/marvell/mwifiex/fw.h
index 13cd58e9..4d5e686 100644
--- a/drivers/net/wireless/marvell/mwifiex/fw.h
+++ b/drivers/net/wireless/marvell/mwifiex/fw.h
@@ -56,6 +56,15 @@ struct mwifiex_fw_data {
u8 data[1];
 } __packed;
 
+struct mwifiex_fw_dump_header {
+   __le16  seq_num;
+   __le16  reserved;
+   __le16  type;
+   __le16  len;
+} __packed;
+
+#define FW_DUMP_INFO_ENDED 0x0002
+
 #define MWIFIEX_FW_DNLD_CMD_1 0x1
 #define MWIFIEX_FW_DNLD_CMD_5 0x5
 #define MWIFIEX_FW_DNLD_CMD_6 0x6
@@ -570,6 +579,7 @@ enum mwifiex_channel_flags {
 #define EVENT_BG_SCAN_STOPPED   0x0065
 #define EVENT_REMAIN_ON_CHAN_EXPIRED0x005f
 #define EVENT_MULTI_CHAN_INFO   0x006a
+#define EVENT_FW_DUMP_INFO 0x0073
 #define EVENT_TX_STATUS_REPORT 0x0074
 #define EVENT_BT_COEX_WLAN_PARA_CHANGE 0X0076
 
diff --git a/drivers/net/wireless/marvell/mwifiex/init.c 
b/drivers/net/wireless/marvell/mwifiex/init.c
index b0d3d68..d239e92 100644
--- a/drivers/net/wireless/marvell/mwifiex/init.c
+++ b/drivers/net/wireless/marvell/mwifiex/init.c
@@ -64,6 +64,13 @@ static void wakeup_timer_fn(struct timer_list *t)
adapter->if_ops.card_reset(adapter);
 }
 
+static void fw_dump_timer_fn(struct timer_list *t)
+{
+   struct mwifiex_adapter *adapter = from_timer(adapter, t, devdump_timer);
+
+   mwifiex_upload_device_dump(adapter);
+}
+
 /*
  * This function initializes the private structure and sets default
  * values to the members.
@@ -315,6 +322,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter 
*adapter)
adapter->active_scan_triggered = false;
timer_setup(>wakeup_timer, wakeup_timer_fn, 0);
adapter->devdump_len = 0;
+   timer_setup(>devdump_timer, fw_dump_timer_fn, 0);
 }
 
 /*
@@ -397,6 +405,7 @@ static void mwifiex_invalidate_lists(struct mwifiex_adapter 
*adapter)
 mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter)
 {
del_timer(>wakeup_timer);
+   del_timer_sync(>devdump_timer);
mwifiex_cancel_all_pending_cmd(adapter);
wake_up_interruptible(>cmd_wait_q.wait);
wake_up_interruptible(>hs_activate_wait_q);
diff --git a/drivers/net/wireless/marvell/mwifiex/main.h 
b/drivers/net/wireless/marvell/mwifiex/main.h
index 8b6241a..6b5539b 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.h
+++ b/drivers/net/wireless/marvell/mwifiex/main.h
@@ -1037,6 +1037,7 @@ struct mwifiex_adapter {
/* Device dump data/length */
void *devdump_data;
int devdump_len;
+   struct timer_list devdump_timer;
 };
 
 void mwifiex_process_tx_queue(struct mwifiex_adapter *adapter);
@@ -1682,6 +1683,7 @@ void mwifiex_process_multi_chan_event(struct 
mwifiex_private *priv,
 void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter);
 int mwifiex_set_mac_address(struct mwifiex_private *priv,
struct net_device *dev);
+void mwifiex_devdump_tmo_func(unsigned long function_context);
 
 #ifdef CONFIG_DEBUG_FS
 void mwifiex_debugfs_init(void);
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_event.c 
b/drivers/net/wireless/marvell/mwifiex/sta_event.c
index d8db412..93dfb76 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_event.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_event.c
@@ -584,6 +584,62 @@ void mwifiex_bt_coex_wlan_param_update_event(struct 
mwifiex_private *priv,
adapter->coex_rx_win_size);
 }
 
+static void
+mwifiex_fw_dump_info_event(struct mwifiex_private *priv,
+  struct sk_buff *event_skb)
+{
+   struct mwifiex_adapter *adapter = priv->adapter;
+   struct mwifiex_fw_dump_header *fw_dump_hdr =
+   (void *)adapter->event_body;
+
+   if (adapter->iface_type != MWIFIEX_USB) {
+   mwifiex_dbg(adapter, MSG,
+   "event is not on usb interface, ignore it\n");
+   return;
+   }
+
+   if (!adapter->devdump_data) {
+  

Re: [PATCH] Removed Warning shown in checkpatch.pl for comment and white space

2017-11-26 Thread Morgan Freeman
On Sun, Nov 26, 2017 at 09:35:50PM +0530, Ashish Kalra wrote:

Hi Ashish,

> checkpatch.pl was showing warnings due to incorrected space at the end
> of line and also not using * at start of second comment line, Corrected
> the same and now there is zero warning

Your patch subject is incorrect in many ways :

o It doesn't mention what driver you are cleaning.
o Don't mention the tool you used in the subject, in fact I would run
checkpatch.pl on your patch itself before sending.
o Always write commit log in *imperative mood*

Perhaps this might help you :
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes



> Signed-off-by: Ashish Kalra 
> ---
>  drivers/bcma/driver_pcie2.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bcma/driver_pcie2.c b/drivers/bcma/driver_pcie2.c
> index b1a6e327cb23..cf889fc62ac7 100644
> --- a/drivers/bcma/driver_pcie2.c
> +++ b/drivers/bcma/driver_pcie2.c
> @@ -83,7 +83,8 @@ static void bcma_core_pcie2_hw_ltr_war(struct 
> bcma_drv_pcie2 *pcie2)
>   bcma_core_pcie2_set_ltr_vals(pcie2);
>  
>   /* TODO:
> - si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0); */
> +  *si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0);
> +  */
>  
>   /* enable the LTR */
>   devstsctr2 |= PCIE2_CAP_DEVSTSCTRL2_LTRENAB;
> -- 
> 2.14.1
> 


[PATCH] Removed Warning shown in checkpatch.pl for comment and white space

2017-11-26 Thread Ashish Kalra
checkpatch.pl was showing warnings due to incorrected space at the end
of line and also not using * at start of second comment line, Corrected
the same and now there is zero warning

Signed-off-by: Ashish Kalra 
---
 drivers/bcma/driver_pcie2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/bcma/driver_pcie2.c b/drivers/bcma/driver_pcie2.c
index b1a6e327cb23..cf889fc62ac7 100644
--- a/drivers/bcma/driver_pcie2.c
+++ b/drivers/bcma/driver_pcie2.c
@@ -83,7 +83,8 @@ static void bcma_core_pcie2_hw_ltr_war(struct bcma_drv_pcie2 
*pcie2)
bcma_core_pcie2_set_ltr_vals(pcie2);
 
/* TODO:
-   si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0); */
+*si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0);
+*/
 
/* enable the LTR */
devstsctr2 |= PCIE2_CAP_DEVSTSCTRL2_LTRENAB;
-- 
2.14.1



Re: [linuxwifi] Need support for Intel new wifi module 9462NGW

2017-11-26 Thread Luca Coelho
On Wed, 2017-11-22 at 21:48 +0800, Chris Chiu wrote:
> On Fri, Nov 17, 2017 at 3:38 PM, Chris Chiu 
> wrote:
> > On Fri, Nov 17, 2017 at 2:46 PM, Luca Coelho 
> > wrote:
> > > On Fri, 2017-11-17 at 14:39 +0800, Chris Chiu wrote:
> > > > On Thu, Nov 16, 2017 at 5:49 PM, Luca Coelho 
> > > > wrote:
> > > > > Hi Chris,
> > > > > 
> > > > > On Thu, 2017-11-09 at 11:11 +0800, Chris Chiu wrote:
> > > > > > Hi Luca,
> > > > > > Any suggestion for the "Failed to start INIT ucode:
> > > > > > -110"
> > > > > > issue
> > > > > > for the firmware?
> > > > > 
> > > > > There were a few problems which should now be fixed.  We
> > > > > published
> > > > > new
> > > > > firmwares in our linux-firmware.git tree[1] and also made
> > > > > some
> > > > > fixes in
> > > > > the driver[2].  Please update your system accordingly and let
> > > > > me
> > > > > know
> > > > > if it works for you.
> > > > > 
> > > > > Thanks!
> > > > > 
> > > > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/l
> > > > > inux-f
> > > > > irmware.git/
> > > > > [2] https://patchwork.kernel.org/patch/10059871/
> > > > > https://patchwork.kernel.org/patch/10059875/
> > > > > https://patchwork.kernel.org/patch/10059873/
> > > > > 
> > > > > --
> > > > > Cheers,
> > > > > Luca.
> > > > 
> > > > Hi Luca,
> > > 
> > > Hi Chris,
> > > 
> > > 
> > > > Thanks for your patch and updated firmware. The driver can
> > > > initialize w/o error now. However, it always fails on ip-config 
> > > > after
> > > > 4-way handshake complete. I have to mention that I removed the
> > > > field
> > > > ".soc_latency" in all new iwl_cfg you added in
> > > > https://patchwork.kernel.org/patch/10059875/ to remove compile
> > > > error
> > > > based on the linux mainline 4.14.
> > > > I don't know whether if this causes the problem. Do you
> > > > need me
> > > > to
> > > > do anything for more information?
> > > 
> > > That was my fault, I forgot to include one file in my commit.  I
> > > have
> > > sent v2 of the two last patches to solve the problem.  Can you
> > > try
> > > them?
> > > 
> > > The problem you're seeing could be related to that, because we
> > > use a
> > > bit longer wait period for HW stabilization with integrated
> > > devices.
> > > And if you remove it, you may encounter random problems...
> > > 
> > > --
> > > Cheers,
> > > Luca.
> > 
> > Hi Luca,
> > Thanks for your quick response. I  tried your v2 patch but
> > things
> > remain the same. The signal strength and scan results seems nothing
> > wrong but still fail to get ip from DHCP server. Please let me know
> > what I can help here.
> > 
> > Chris
> 
> Hi Luca,
> Some more observation I want to point out and maybe you can
> suggest.
> After your v2 patch and the latest firmware. I'm pretty sure there's
> no problem
> on my 9462NGW module to associate to an AP (4-way handshaking
> complete)
> dmesg in https://gist.github.com/mschiu77/1fe1f5128f1c49a93055ce23976
> c09b5
> here also shows
> [   59.338785] wlp0s12f0: associated
> 
> Then I do air sniffer with my mac book air and only dump DHCP packets
> in
> https://gist.github.com/mschiu77/677b5fbfdea0fea2eda4a36a84bcac8e
> 
> As you see, 4 DHCP Discovery here but no response. I do the same
> thing on
> the other laptop to associate to the same AP SSID, there's no
> problem.
> 
> And yet another interesting thing is, every time I was trying to
> associate
> The ifconfig always give me a totally different ether address. I log
> 5 times in
> https://gist.github.com/mschiu77/54169d52b9fcf205d5c26752988f8a3d
> 
> The read HW address should be 34:13:e8:6f:34:25 and it's also true in
> tcpdump
> log.
> 
> I think maybe it's related. Can you suggest anything that I can try?

Hey Chris,

Thanks for the update and sorry for the delay.  I'll take a look into
this in the coming week, there's probably something missing in the
driver that is causing this issue...

--
Cheers,
Luca.