diff mbox series

[1/6] mt76: mt7921: move mt7921_dma_reset in dma.c

Message ID 1618763767-1292-2-git-send-email-sean.wang@mediatek.com (mailing list archive)
State New
Headers show
Series enable deep sleep mode when mt7921e suspends | expand

Commit Message

Sean Wang April 18, 2021, 4:36 p.m. UTC
From: Lorenzo Bianconi <lorenzo@kernel.org>

Move mt7921_dma_reset routine in dma.c and make mt7921_dma_prefetch
static. Moreover add force parameter to mt7921_dma_reset signature.
This is a preliminary patch to reset dma mt7921_mcu_drv_pmctrl.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7921/dma.c   | 71 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7921/mac.c   | 66 +----------------
 .../wireless/mediatek/mt76/mt7921/mt7921.h    |  2 +-
 3 files changed, 73 insertions(+), 66 deletions(-)

Comments

Lorenzo Bianconi April 18, 2021, 4:47 p.m. UTC | #1
> From: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> Move mt7921_dma_reset routine in dma.c and make mt7921_dma_prefetch
> static. Moreover add force parameter to mt7921_dma_reset signature.
> This is a preliminary patch to reset dma mt7921_mcu_drv_pmctrl.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  .../net/wireless/mediatek/mt76/mt7921/dma.c   | 71 +++++++++++++++++++
>  .../net/wireless/mediatek/mt76/mt7921/mac.c   | 66 +----------------
>  .../wireless/mediatek/mt76/mt7921/mt7921.h    |  2 +-
>  3 files changed, 73 insertions(+), 66 deletions(-)

Hi Sean,

I have just posted a preliminary series mandatory to enable deep sleep on mt7921.
I can post my patches of this seires (the one you posted) on top of it,
or if you prefer, can you please repost on top of my new series?

Regards,
Lorenzo

> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
> index 992faf82ad09..f8815aa247eb 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
> @@ -206,6 +206,77 @@ static int mt7921_dmashdl_disabled(struct mt7921_dev *dev)
>  	return 0;
>  }
>  
> +int mt7921_dma_reset(struct mt7921_dev *dev, bool force)
> +{
> +	int i;
> +
> +	if (force) {
> +		/* reset */
> +		mt76_clear(dev, MT_WFDMA0_RST,
> +			   MT_WFDMA0_RST_DMASHDL_ALL_RST |
> +			   MT_WFDMA0_RST_LOGIC_RST);
> +
> +		mt76_set(dev, MT_WFDMA0_RST,
> +			 MT_WFDMA0_RST_DMASHDL_ALL_RST |
> +			 MT_WFDMA0_RST_LOGIC_RST);
> +	}
> +
> +	/* disable WFDMA0 */
> +	mt76_clear(dev, MT_WFDMA0_GLO_CFG,
> +		   MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN |
> +		   MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
> +		   MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
> +		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO |
> +		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
> +
> +	if (!mt76_poll(dev, MT_WFDMA0_GLO_CFG,
> +		       MT_WFDMA0_GLO_CFG_TX_DMA_BUSY |
> +		       MT_WFDMA0_GLO_CFG_RX_DMA_BUSY, 0, 1000))
> +		return -ETIMEDOUT;
> +
> +	/* reset hw queues */
> +	for (i = 0; i < __MT_TXQ_MAX; i++)
> +		mt76_queue_reset(dev, dev->mphy.q_tx[i]);
> +
> +	for (i = 0; i < __MT_MCUQ_MAX; i++)
> +		mt76_queue_reset(dev, dev->mt76.q_mcu[i]);
> +
> +	mt76_for_each_q_rx(&dev->mt76, i)
> +		mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
> +
> +	mt76_tx_status_check(&dev->mt76, NULL, true);
> +
> +	/* configure perfetch settings */
> +	mt7921_dma_prefetch(dev);
> +
> +	/* reset dma idx */
> +	mt76_wr(dev, MT_WFDMA0_RST_DTX_PTR, ~0);
> +
> +	/* configure delay interrupt */
> +	mt76_wr(dev, MT_WFDMA0_PRI_DLY_INT_CFG0, 0);
> +
> +	mt76_set(dev, MT_WFDMA0_GLO_CFG,
> +		 MT_WFDMA0_GLO_CFG_TX_WB_DDONE |
> +		 MT_WFDMA0_GLO_CFG_FIFO_LITTLE_ENDIAN |
> +		 MT_WFDMA0_GLO_CFG_CLK_GAT_DIS |
> +		 MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
> +		 MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
> +		 MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
> +
> +	mt76_set(dev, MT_WFDMA0_GLO_CFG,
> +		 MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN);
> +
> +	mt76_set(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
> +
> +	/* enable interrupts for TX/RX rings */
> +	mt7921_irq_enable(dev,
> +			  MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
> +			  MT_INT_MCU_CMD);
> +	mt76_set(dev, MT_MCU2HOST_SW_INT_ENA, MT_MCU_CMD_WAKE_RX_PCIE);
> +
> +	return 0;
> +}
> +
>  int mt7921_dma_init(struct mt7921_dev *dev)
>  {
>  	/* Increase buffer size to receive large VHT/HE MPDUs */
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> index 3145880df6e7..4e319f1521a6 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
> @@ -1220,70 +1220,6 @@ int mt7921_wfsys_reset(struct mt7921_dev *dev)
>  				WFSYS_SW_INIT_DONE, WFSYS_SW_INIT_DONE, 500);
>  }
>  
> -static void
> -mt7921_dma_reset(struct mt7921_dev *dev)
> -{
> -	int i;
> -
> -	/* reset */
> -	mt76_clear(dev, MT_WFDMA0_RST,
> -		   MT_WFDMA0_RST_DMASHDL_ALL_RST | MT_WFDMA0_RST_LOGIC_RST);
> -
> -	mt76_set(dev, MT_WFDMA0_RST,
> -		 MT_WFDMA0_RST_DMASHDL_ALL_RST | MT_WFDMA0_RST_LOGIC_RST);
> -
> -	/* disable WFDMA0 */
> -	mt76_clear(dev, MT_WFDMA0_GLO_CFG,
> -		   MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN |
> -		   MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
> -		   MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
> -		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO |
> -		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
> -
> -	mt76_poll(dev, MT_WFDMA0_GLO_CFG,
> -		  MT_WFDMA0_GLO_CFG_TX_DMA_BUSY |
> -		  MT_WFDMA0_GLO_CFG_RX_DMA_BUSY, 0, 1000);
> -
> -	/* reset hw queues */
> -	for (i = 0; i < __MT_TXQ_MAX; i++)
> -		mt76_queue_reset(dev, dev->mphy.q_tx[i]);
> -
> -	for (i = 0; i < __MT_MCUQ_MAX; i++)
> -		mt76_queue_reset(dev, dev->mt76.q_mcu[i]);
> -
> -	mt76_for_each_q_rx(&dev->mt76, i)
> -		mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
> -
> -	mt76_tx_status_check(&dev->mt76, NULL, true);
> -
> -	/* configure perfetch settings */
> -	mt7921_dma_prefetch(dev);
> -
> -	/* reset dma idx */
> -	mt76_wr(dev, MT_WFDMA0_RST_DTX_PTR, ~0);
> -
> -	/* configure delay interrupt */
> -	mt76_wr(dev, MT_WFDMA0_PRI_DLY_INT_CFG0, 0);
> -
> -	mt76_set(dev, MT_WFDMA0_GLO_CFG,
> -		 MT_WFDMA0_GLO_CFG_TX_WB_DDONE |
> -		 MT_WFDMA0_GLO_CFG_FIFO_LITTLE_ENDIAN |
> -		 MT_WFDMA0_GLO_CFG_CLK_GAT_DIS |
> -		 MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
> -		 MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
> -		 MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
> -
> -	mt76_set(dev, MT_WFDMA0_GLO_CFG,
> -		 MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN);
> -
> -	mt76_set(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
> -
> -	/* enable interrupts for TX/RX rings */
> -	mt7921_irq_enable(dev,
> -			  MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
> -			  MT_INT_MCU_CMD);
> -}
> -
>  void mt7921_tx_token_put(struct mt7921_dev *dev)
>  {
>  	struct mt76_txwi_cache *txwi;
> @@ -1354,7 +1290,7 @@ mt7921_mac_reset(struct mt7921_dev *dev)
>  		mt76_queue_rx_cleanup(dev, &dev->mt76.q_rx[i]);
>  
>  	mt7921_wfsys_reset(dev);
> -	mt7921_dma_reset(dev);
> +	mt7921_dma_reset(dev, true);
>  
>  	mt76_for_each_q_rx(&dev->mt76, i) {
>  		mt76_queue_rx_reset(dev, i);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> index c34cf3e3a26b..9b476641616d 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
> @@ -253,7 +253,7 @@ int mt7921_eeprom_get_target_power(struct mt7921_dev *dev,
>  				   u8 chain_idx);
>  void mt7921_eeprom_init_sku(struct mt7921_dev *dev);
>  int mt7921_dma_init(struct mt7921_dev *dev);
> -void mt7921_dma_prefetch(struct mt7921_dev *dev);
> +int mt7921_dma_reset(struct mt7921_dev *dev, bool force);
>  void mt7921_dma_cleanup(struct mt7921_dev *dev);
>  int mt7921_run_firmware(struct mt7921_dev *dev);
>  int mt7921_mcu_init(struct mt7921_dev *dev);
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
index 992faf82ad09..f8815aa247eb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c
@@ -206,6 +206,77 @@  static int mt7921_dmashdl_disabled(struct mt7921_dev *dev)
 	return 0;
 }
 
+int mt7921_dma_reset(struct mt7921_dev *dev, bool force)
+{
+	int i;
+
+	if (force) {
+		/* reset */
+		mt76_clear(dev, MT_WFDMA0_RST,
+			   MT_WFDMA0_RST_DMASHDL_ALL_RST |
+			   MT_WFDMA0_RST_LOGIC_RST);
+
+		mt76_set(dev, MT_WFDMA0_RST,
+			 MT_WFDMA0_RST_DMASHDL_ALL_RST |
+			 MT_WFDMA0_RST_LOGIC_RST);
+	}
+
+	/* disable WFDMA0 */
+	mt76_clear(dev, MT_WFDMA0_GLO_CFG,
+		   MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN |
+		   MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
+		   MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
+		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO |
+		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
+
+	if (!mt76_poll(dev, MT_WFDMA0_GLO_CFG,
+		       MT_WFDMA0_GLO_CFG_TX_DMA_BUSY |
+		       MT_WFDMA0_GLO_CFG_RX_DMA_BUSY, 0, 1000))
+		return -ETIMEDOUT;
+
+	/* reset hw queues */
+	for (i = 0; i < __MT_TXQ_MAX; i++)
+		mt76_queue_reset(dev, dev->mphy.q_tx[i]);
+
+	for (i = 0; i < __MT_MCUQ_MAX; i++)
+		mt76_queue_reset(dev, dev->mt76.q_mcu[i]);
+
+	mt76_for_each_q_rx(&dev->mt76, i)
+		mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
+
+	mt76_tx_status_check(&dev->mt76, NULL, true);
+
+	/* configure perfetch settings */
+	mt7921_dma_prefetch(dev);
+
+	/* reset dma idx */
+	mt76_wr(dev, MT_WFDMA0_RST_DTX_PTR, ~0);
+
+	/* configure delay interrupt */
+	mt76_wr(dev, MT_WFDMA0_PRI_DLY_INT_CFG0, 0);
+
+	mt76_set(dev, MT_WFDMA0_GLO_CFG,
+		 MT_WFDMA0_GLO_CFG_TX_WB_DDONE |
+		 MT_WFDMA0_GLO_CFG_FIFO_LITTLE_ENDIAN |
+		 MT_WFDMA0_GLO_CFG_CLK_GAT_DIS |
+		 MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
+		 MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
+		 MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
+
+	mt76_set(dev, MT_WFDMA0_GLO_CFG,
+		 MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN);
+
+	mt76_set(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
+
+	/* enable interrupts for TX/RX rings */
+	mt7921_irq_enable(dev,
+			  MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
+			  MT_INT_MCU_CMD);
+	mt76_set(dev, MT_MCU2HOST_SW_INT_ENA, MT_MCU_CMD_WAKE_RX_PCIE);
+
+	return 0;
+}
+
 int mt7921_dma_init(struct mt7921_dev *dev)
 {
 	/* Increase buffer size to receive large VHT/HE MPDUs */
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 3145880df6e7..4e319f1521a6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -1220,70 +1220,6 @@  int mt7921_wfsys_reset(struct mt7921_dev *dev)
 				WFSYS_SW_INIT_DONE, WFSYS_SW_INIT_DONE, 500);
 }
 
-static void
-mt7921_dma_reset(struct mt7921_dev *dev)
-{
-	int i;
-
-	/* reset */
-	mt76_clear(dev, MT_WFDMA0_RST,
-		   MT_WFDMA0_RST_DMASHDL_ALL_RST | MT_WFDMA0_RST_LOGIC_RST);
-
-	mt76_set(dev, MT_WFDMA0_RST,
-		 MT_WFDMA0_RST_DMASHDL_ALL_RST | MT_WFDMA0_RST_LOGIC_RST);
-
-	/* disable WFDMA0 */
-	mt76_clear(dev, MT_WFDMA0_GLO_CFG,
-		   MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN |
-		   MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
-		   MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
-		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO |
-		   MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
-
-	mt76_poll(dev, MT_WFDMA0_GLO_CFG,
-		  MT_WFDMA0_GLO_CFG_TX_DMA_BUSY |
-		  MT_WFDMA0_GLO_CFG_RX_DMA_BUSY, 0, 1000);
-
-	/* reset hw queues */
-	for (i = 0; i < __MT_TXQ_MAX; i++)
-		mt76_queue_reset(dev, dev->mphy.q_tx[i]);
-
-	for (i = 0; i < __MT_MCUQ_MAX; i++)
-		mt76_queue_reset(dev, dev->mt76.q_mcu[i]);
-
-	mt76_for_each_q_rx(&dev->mt76, i)
-		mt76_queue_reset(dev, &dev->mt76.q_rx[i]);
-
-	mt76_tx_status_check(&dev->mt76, NULL, true);
-
-	/* configure perfetch settings */
-	mt7921_dma_prefetch(dev);
-
-	/* reset dma idx */
-	mt76_wr(dev, MT_WFDMA0_RST_DTX_PTR, ~0);
-
-	/* configure delay interrupt */
-	mt76_wr(dev, MT_WFDMA0_PRI_DLY_INT_CFG0, 0);
-
-	mt76_set(dev, MT_WFDMA0_GLO_CFG,
-		 MT_WFDMA0_GLO_CFG_TX_WB_DDONE |
-		 MT_WFDMA0_GLO_CFG_FIFO_LITTLE_ENDIAN |
-		 MT_WFDMA0_GLO_CFG_CLK_GAT_DIS |
-		 MT_WFDMA0_GLO_CFG_OMIT_TX_INFO |
-		 MT_WFDMA0_GLO_CFG_CSR_DISP_BASE_PTR_CHAIN_EN |
-		 MT_WFDMA0_GLO_CFG_OMIT_RX_INFO_PFET2);
-
-	mt76_set(dev, MT_WFDMA0_GLO_CFG,
-		 MT_WFDMA0_GLO_CFG_TX_DMA_EN | MT_WFDMA0_GLO_CFG_RX_DMA_EN);
-
-	mt76_set(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
-
-	/* enable interrupts for TX/RX rings */
-	mt7921_irq_enable(dev,
-			  MT_INT_RX_DONE_ALL | MT_INT_TX_DONE_ALL |
-			  MT_INT_MCU_CMD);
-}
-
 void mt7921_tx_token_put(struct mt7921_dev *dev)
 {
 	struct mt76_txwi_cache *txwi;
@@ -1354,7 +1290,7 @@  mt7921_mac_reset(struct mt7921_dev *dev)
 		mt76_queue_rx_cleanup(dev, &dev->mt76.q_rx[i]);
 
 	mt7921_wfsys_reset(dev);
-	mt7921_dma_reset(dev);
+	mt7921_dma_reset(dev, true);
 
 	mt76_for_each_q_rx(&dev->mt76, i) {
 		mt76_queue_rx_reset(dev, i);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
index c34cf3e3a26b..9b476641616d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
@@ -253,7 +253,7 @@  int mt7921_eeprom_get_target_power(struct mt7921_dev *dev,
 				   u8 chain_idx);
 void mt7921_eeprom_init_sku(struct mt7921_dev *dev);
 int mt7921_dma_init(struct mt7921_dev *dev);
-void mt7921_dma_prefetch(struct mt7921_dev *dev);
+int mt7921_dma_reset(struct mt7921_dev *dev, bool force);
 void mt7921_dma_cleanup(struct mt7921_dev *dev);
 int mt7921_run_firmware(struct mt7921_dev *dev);
 int mt7921_mcu_init(struct mt7921_dev *dev);