diff mbox

[02/12] mwifiex: check tx_hw_pending before downloading sleep confirm

Message ID 1477900940-10549-2-git-send-email-huxinming820@marvell.com (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show

Commit Message

Xinming Hu Oct. 31, 2016, 8:02 a.m. UTC
From: Shengzhen Li <szli@marvell.com>

This patch will only allow downloading sleep confirm
when no tx done interrupt is pending in the hardware.

Signed-off-by: Cathy Luo <cluo@marvell.com>
Signed-off-by: Shengzhen Li <szli@marvell.com>

Change-Id: I6d6955b4a2de0ad791ca28f0f635d636a2c7e406
---
 drivers/net/wireless/marvell/mwifiex/cmdevt.c | 4 ++--
 drivers/net/wireless/marvell/mwifiex/init.c   | 1 +
 drivers/net/wireless/marvell/mwifiex/main.h   | 1 +
 drivers/net/wireless/marvell/mwifiex/pcie.c   | 5 +++++
 4 files changed, 9 insertions(+), 2 deletions(-)

Comments

Brian Norris Nov. 1, 2016, 12:14 a.m. UTC | #1
On Mon, Oct 31, 2016 at 04:02:10PM +0800, Xinming Hu wrote:
> From: Shengzhen Li <szli@marvell.com>
> 
> This patch will only allow downloading sleep confirm
> when no tx done interrupt is pending in the hardware.
> 
> Signed-off-by: Cathy Luo <cluo@marvell.com>
> Signed-off-by: Shengzhen Li <szli@marvell.com>
> 
> Change-Id: I6d6955b4a2de0ad791ca28f0f635d636a2c7e406


^^ Remove this

> ---
>  drivers/net/wireless/marvell/mwifiex/cmdevt.c | 4 ++--
>  drivers/net/wireless/marvell/mwifiex/init.c   | 1 +
>  drivers/net/wireless/marvell/mwifiex/main.h   | 1 +
>  drivers/net/wireless/marvell/mwifiex/pcie.c   | 5 +++++
>  4 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> index 9075be5..25a7475 100644
> --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
> @@ -1118,14 +1118,14 @@ mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
>  void
>  mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
>  {
> -	if (!adapter->cmd_sent &&
> +	if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) &&

How is this different from the following?

https://patchwork.kernel.org/patch/9389485/

And parituclarly, they conflict on this line, so you need to resolve
that somehow...

And if the linked patch serves the same purpose, then I'd rather take
it, since it's much simpler.

Brian

>  	    !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
>  		mwifiex_dnld_sleep_confirm_cmd(adapter);
>  	else
>  		mwifiex_dbg(adapter, CMD,
>  			    "cmd: Delay Sleep Confirm (%s%s%s%s)\n",
>  			    (adapter->cmd_sent) ? "D" : "",
> -			    (adapter->data_sent) ? "T" : "",
> +			    atomic_read(&adapter->tx_hw_pending) ? "T" : "",
>  			    (adapter->curr_cmd) ? "C" : "",
>  			    (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
>  }
> diff --git a/drivers/net/wireless/marvell/mwifiex/init.c b/drivers/net/wireless/marvell/mwifiex/init.c
> index 82839d9..b36cb3f 100644
> --- a/drivers/net/wireless/marvell/mwifiex/init.c
> +++ b/drivers/net/wireless/marvell/mwifiex/init.c
> @@ -270,6 +270,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
>  	adapter->adhoc_11n_enabled = false;
>  
>  	mwifiex_wmm_init(adapter);
> +	atomic_set(&adapter->tx_hw_pending, 0);
>  
>  	sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
>  					adapter->sleep_cfm->data;
> diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h
> index d61fe3a..7f67f23 100644
> --- a/drivers/net/wireless/marvell/mwifiex/main.h
> +++ b/drivers/net/wireless/marvell/mwifiex/main.h
> @@ -857,6 +857,7 @@ struct mwifiex_adapter {
>  	atomic_t rx_pending;
>  	atomic_t tx_pending;
>  	atomic_t cmd_pending;
> +	atomic_t tx_hw_pending;
>  	struct workqueue_struct *workqueue;
>  	struct work_struct main_work;
>  	struct workqueue_struct *rx_workqueue;
> diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
> index 063c707..4aa5d91 100644
> --- a/drivers/net/wireless/marvell/mwifiex/pcie.c
> +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
> @@ -516,6 +516,7 @@ static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
>  		}
>  	}
>  
> +	atomic_set(&adapter->tx_hw_pending, 0);
>  	return 0;
>  }
>  
> @@ -689,6 +690,7 @@ static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
>  		card->tx_buf_list[i] = NULL;
>  	}
>  
> +	atomic_set(&adapter->tx_hw_pending, 0);
>  	return;
>  }
>  
> @@ -1126,6 +1128,7 @@ static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
>  							    -1);
>  			else
>  				mwifiex_write_data_complete(adapter, skb, 0, 0);
> +			atomic_dec(&adapter->tx_hw_pending);
>  		}
>  
>  		card->tx_buf_list[wrdoneidx] = NULL;
> @@ -1218,6 +1221,7 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
>  		wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
>  		buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
>  		card->tx_buf_list[wrindx] = skb;
> +		atomic_inc(&adapter->tx_hw_pending);
>  
>  		if (reg->pfu_enabled) {
>  			desc2 = card->txbd_ring[wrindx];
> @@ -1295,6 +1299,7 @@ mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
>  done_unmap:
>  	mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
>  	card->tx_buf_list[wrindx] = NULL;
> +	atomic_dec(&adapter->tx_hw_pending);
>  	if (reg->pfu_enabled)
>  		memset(desc2, 0, sizeof(*desc2));
>  	else
> -- 
> 1.8.1.4
>
Xinming Hu Nov. 1, 2016, 10:24 a.m. UTC | #2
Hi Brain,

> -----Original Message-----

> From: linux-wireless-owner@vger.kernel.org

> [mailto:linux-wireless-owner@vger.kernel.org] On Behalf Of Brian Norris

> Sent: 2016年11月1日 8:15

> To: Xinming Hu

> Cc: Linux Wireless; Kalle Valo; Dmitry Torokhov; Amitkumar Karwar; Cathy Luo;

> Shengzhen Li

> Subject: Re: [PATCH 02/12] mwifiex: check tx_hw_pending before downloading

> sleep confirm

> 

> On Mon, Oct 31, 2016 at 04:02:10PM +0800, Xinming Hu wrote:

> > From: Shengzhen Li <szli@marvell.com>

> >

> > This patch will only allow downloading sleep confirm when no tx done

> > interrupt is pending in the hardware.

> >

> > Signed-off-by: Cathy Luo <cluo@marvell.com>

> > Signed-off-by: Shengzhen Li <szli@marvell.com>

> >

> > Change-Id: I6d6955b4a2de0ad791ca28f0f635d636a2c7e406

> 

> 

> ^^ Remove this

> 


Ok, will remove in updated version!

> > ---

> >  drivers/net/wireless/marvell/mwifiex/cmdevt.c | 4 ++--

> >  drivers/net/wireless/marvell/mwifiex/init.c   | 1 +

> >  drivers/net/wireless/marvell/mwifiex/main.h   | 1 +

> >  drivers/net/wireless/marvell/mwifiex/pcie.c   | 5 +++++

> >  4 files changed, 9 insertions(+), 2 deletions(-)

> >

> > diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c

> > b/drivers/net/wireless/marvell/mwifiex/cmdevt.c

> > index 9075be5..25a7475 100644

> > --- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c

> > +++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c

> > @@ -1118,14 +1118,14 @@ mwifiex_cancel_pending_ioctl(struct

> > mwifiex_adapter *adapter)  void  mwifiex_check_ps_cond(struct

> > mwifiex_adapter *adapter)  {

> > -	if (!adapter->cmd_sent &&

> > +	if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) &&

> 

> How is this different from the following?

> 

> https://patchwork.kernel.org/patch/9389485/

> 

> And parituclarly, they conflict on this line, so you need to resolve that

> somehow...

> 

> And if the linked patch serves the same purpose, then I'd rather take it, since

> it's much simpler.

> 

> Brian

> 


This patch is an enhanced version compared with https://patchwork.kernel.org/patch/9389485/ , 
Mwifiex pcie try to "aggregate" tx ring buffers, before notify firmware data ready.
data_sent will only be set true when pcie aggregation is done.
During the "pcie aggregation" stage, data_sent is not set, driver still be able to download sleep confirm in another thread, 
In this case, we will still meet kernel crash caused by concurrent execution between PM handshake and processing tx done interrupt. 
tx_hw_pending will be a better solution to match this case. 

> >  	    !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))

> >  		mwifiex_dnld_sleep_confirm_cmd(adapter);

> >  	else

> >  		mwifiex_dbg(adapter, CMD,

> >  			    "cmd: Delay Sleep Confirm (%s%s%s%s)\n",

> >  			    (adapter->cmd_sent) ? "D" : "",

> > -			    (adapter->data_sent) ? "T" : "",

> > +			    atomic_read(&adapter->tx_hw_pending) ? "T" : "",

> >  			    (adapter->curr_cmd) ? "C" : "",

> >  			    (IS_CARD_RX_RCVD(adapter)) ? "R" : "");  } diff --git

> > a/drivers/net/wireless/marvell/mwifiex/init.c

> > b/drivers/net/wireless/marvell/mwifiex/init.c

> > index 82839d9..b36cb3f 100644

> > --- a/drivers/net/wireless/marvell/mwifiex/init.c

> > +++ b/drivers/net/wireless/marvell/mwifiex/init.c

> > @@ -270,6 +270,7 @@ static void mwifiex_init_adapter(struct

> mwifiex_adapter *adapter)

> >  	adapter->adhoc_11n_enabled = false;

> >

> >  	mwifiex_wmm_init(adapter);

> > +	atomic_set(&adapter->tx_hw_pending, 0);

> >

> >  	sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)

> >  					adapter->sleep_cfm->data;

> > diff --git a/drivers/net/wireless/marvell/mwifiex/main.h

> > b/drivers/net/wireless/marvell/mwifiex/main.h

> > index d61fe3a..7f67f23 100644

> > --- a/drivers/net/wireless/marvell/mwifiex/main.h

> > +++ b/drivers/net/wireless/marvell/mwifiex/main.h

> > @@ -857,6 +857,7 @@ struct mwifiex_adapter {

> >  	atomic_t rx_pending;

> >  	atomic_t tx_pending;

> >  	atomic_t cmd_pending;

> > +	atomic_t tx_hw_pending;

> >  	struct workqueue_struct *workqueue;

> >  	struct work_struct main_work;

> >  	struct workqueue_struct *rx_workqueue; diff --git

> > a/drivers/net/wireless/marvell/mwifiex/pcie.c

> > b/drivers/net/wireless/marvell/mwifiex/pcie.c

> > index 063c707..4aa5d91 100644

> > --- a/drivers/net/wireless/marvell/mwifiex/pcie.c

> > +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c

> > @@ -516,6 +516,7 @@ static int mwifiex_pcie_enable_host_int(struct

> mwifiex_adapter *adapter)

> >  		}

> >  	}

> >

> > +	atomic_set(&adapter->tx_hw_pending, 0);

> >  	return 0;

> >  }

> >

> > @@ -689,6 +690,7 @@ static void mwifiex_cleanup_txq_ring(struct

> mwifiex_adapter *adapter)

> >  		card->tx_buf_list[i] = NULL;

> >  	}

> >

> > +	atomic_set(&adapter->tx_hw_pending, 0);

> >  	return;

> >  }

> >

> > @@ -1126,6 +1128,7 @@ static int mwifiex_pcie_send_data_complete(struct

> mwifiex_adapter *adapter)

> >  							    -1);

> >  			else

> >  				mwifiex_write_data_complete(adapter, skb, 0, 0);

> > +			atomic_dec(&adapter->tx_hw_pending);

> >  		}

> >

> >  		card->tx_buf_list[wrdoneidx] = NULL; @@ -1218,6 +1221,7 @@

> > mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff

> *skb,

> >  		wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;

> >  		buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);

> >  		card->tx_buf_list[wrindx] = skb;

> > +		atomic_inc(&adapter->tx_hw_pending);

> >

> >  		if (reg->pfu_enabled) {

> >  			desc2 = card->txbd_ring[wrindx];

> > @@ -1295,6 +1299,7 @@ mwifiex_pcie_send_data(struct mwifiex_adapter

> > *adapter, struct sk_buff *skb,

> >  done_unmap:

> >  	mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);

> >  	card->tx_buf_list[wrindx] = NULL;

> > +	atomic_dec(&adapter->tx_hw_pending);

> >  	if (reg->pfu_enabled)

> >  		memset(desc2, 0, sizeof(*desc2));

> >  	else

> > --

> > 1.8.1.4

> >


Best Regards,
Xinming
diff mbox

Patch

diff --git a/drivers/net/wireless/marvell/mwifiex/cmdevt.c b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
index 9075be5..25a7475 100644
--- a/drivers/net/wireless/marvell/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/marvell/mwifiex/cmdevt.c
@@ -1118,14 +1118,14 @@  mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
 void
 mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
 {
-	if (!adapter->cmd_sent &&
+	if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) &&
 	    !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
 		mwifiex_dnld_sleep_confirm_cmd(adapter);
 	else
 		mwifiex_dbg(adapter, CMD,
 			    "cmd: Delay Sleep Confirm (%s%s%s%s)\n",
 			    (adapter->cmd_sent) ? "D" : "",
-			    (adapter->data_sent) ? "T" : "",
+			    atomic_read(&adapter->tx_hw_pending) ? "T" : "",
 			    (adapter->curr_cmd) ? "C" : "",
 			    (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
 }
diff --git a/drivers/net/wireless/marvell/mwifiex/init.c b/drivers/net/wireless/marvell/mwifiex/init.c
index 82839d9..b36cb3f 100644
--- a/drivers/net/wireless/marvell/mwifiex/init.c
+++ b/drivers/net/wireless/marvell/mwifiex/init.c
@@ -270,6 +270,7 @@  static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
 	adapter->adhoc_11n_enabled = false;
 
 	mwifiex_wmm_init(adapter);
+	atomic_set(&adapter->tx_hw_pending, 0);
 
 	sleep_cfm_buf = (struct mwifiex_opt_sleep_confirm *)
 					adapter->sleep_cfm->data;
diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h
index d61fe3a..7f67f23 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.h
+++ b/drivers/net/wireless/marvell/mwifiex/main.h
@@ -857,6 +857,7 @@  struct mwifiex_adapter {
 	atomic_t rx_pending;
 	atomic_t tx_pending;
 	atomic_t cmd_pending;
+	atomic_t tx_hw_pending;
 	struct workqueue_struct *workqueue;
 	struct work_struct main_work;
 	struct workqueue_struct *rx_workqueue;
diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
index 063c707..4aa5d91 100644
--- a/drivers/net/wireless/marvell/mwifiex/pcie.c
+++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
@@ -516,6 +516,7 @@  static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
 		}
 	}
 
+	atomic_set(&adapter->tx_hw_pending, 0);
 	return 0;
 }
 
@@ -689,6 +690,7 @@  static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
 		card->tx_buf_list[i] = NULL;
 	}
 
+	atomic_set(&adapter->tx_hw_pending, 0);
 	return;
 }
 
@@ -1126,6 +1128,7 @@  static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
 							    -1);
 			else
 				mwifiex_write_data_complete(adapter, skb, 0, 0);
+			atomic_dec(&adapter->tx_hw_pending);
 		}
 
 		card->tx_buf_list[wrdoneidx] = NULL;
@@ -1218,6 +1221,7 @@  mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
 		wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
 		buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
 		card->tx_buf_list[wrindx] = skb;
+		atomic_inc(&adapter->tx_hw_pending);
 
 		if (reg->pfu_enabled) {
 			desc2 = card->txbd_ring[wrindx];
@@ -1295,6 +1299,7 @@  mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
 done_unmap:
 	mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
 	card->tx_buf_list[wrindx] = NULL;
+	atomic_dec(&adapter->tx_hw_pending);
 	if (reg->pfu_enabled)
 		memset(desc2, 0, sizeof(*desc2));
 	else