All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: nbd@nbd.name
Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org
Subject: [PATCH 03/26] mt76: add mt76x02_dma_enable/mt76x02_dma_disable utility routines
Date: Thu, 27 Sep 2018 11:01:32 +0200	[thread overview]
Message-ID: <829c1c000477a7600add8319e5a3cff46b690ff6.1538036134.git.lorenzo.bianconi@redhat.com> (raw)
In-Reply-To: <cover.1538036134.git.lorenzo.bianconi@redhat.com>

Introduce mt76x02_dma_enable and mt76x02_dma_disable utility routines
in order to be reused in mt76x0 mac configuration and remove duplicated
code

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 drivers/net/wireless/mediatek/mt76/Makefile   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x02_dma.c  | 51 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt76x02_dma.h  |  3 ++
 .../net/wireless/mediatek/mt76/mt76x2_init.c  | 20 +-------
 4 files changed, 57 insertions(+), 19 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_dma.c

diff --git a/drivers/net/wireless/mediatek/mt76/Makefile b/drivers/net/wireless/mediatek/mt76/Makefile
index 1fc7450650ee..0cde9dff74a3 100644
--- a/drivers/net/wireless/mediatek/mt76/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/Makefile
@@ -16,7 +16,7 @@ CFLAGS_trace.o := -I$(src)
 CFLAGS_usb_trace.o := -I$(src)
 
 mt76x02-lib-y := mt76x02_util.o mt76x02_mac.o mt76x02_mcu.o \
-		 mt76x02_eeprom.o mt76x02_phy.o
+		 mt76x02_eeprom.o mt76x02_phy.o mt76x02_dma.o
 
 mt76x02-usb-y := mt76x02_usb_mcu.o mt76x02_usb_core.o
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_dma.c b/drivers/net/wireless/mediatek/mt76/mt76x02_dma.c
new file mode 100644
index 000000000000..f471c3a0674a
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_dma.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
+ * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <linux/kernel.h>
+
+#include "mt76.h"
+#include "mt76x02_dma.h"
+#include "mt76x02_regs.h"
+
+void mt76x02_dma_enable(struct mt76_dev *dev)
+{
+	u32 val;
+
+	__mt76_wr(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_TX);
+	mt76x02_wait_for_wpdma(dev, 1000);
+	usleep_range(50, 100);
+
+	val = FIELD_PREP(MT_WPDMA_GLO_CFG_DMA_BURST_SIZE, 3) |
+	      MT_WPDMA_GLO_CFG_TX_DMA_EN |
+	      MT_WPDMA_GLO_CFG_RX_DMA_EN;
+	__mt76_set(dev, MT_WPDMA_GLO_CFG, val);
+	__mt76_clear(dev, MT_WPDMA_GLO_CFG,
+		     MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE);
+}
+EXPORT_SYMBOL_GPL(mt76x02_dma_enable);
+
+void mt76x02_dma_disable(struct mt76_dev *dev)
+{
+	u32 val = __mt76_rr(dev, MT_WPDMA_GLO_CFG);
+
+	val &= MT_WPDMA_GLO_CFG_DMA_BURST_SIZE |
+	       MT_WPDMA_GLO_CFG_BIG_ENDIAN |
+	       MT_WPDMA_GLO_CFG_HDR_SEG_LEN;
+	val |= MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE;
+	__mt76_wr(dev, MT_WPDMA_GLO_CFG, val);
+}
+EXPORT_SYMBOL_GPL(mt76x02_dma_disable);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_dma.h b/drivers/net/wireless/mediatek/mt76/mt76x02_dma.h
index 2396d49a84dd..0b78857c9b4c 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_dma.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_dma.h
@@ -67,4 +67,7 @@ mt76x02_wait_for_wpdma(struct mt76_dev *dev, int timeout)
 			   0, timeout);
 }
 
+void mt76x02_dma_enable(struct mt76_dev *dev);
+void mt76x02_dma_disable(struct mt76_dev *dev);
+
 #endif /* __MT76x02_DMA_H */
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2_init.c
index 68244b47312a..bd52c8b2ee9f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2_init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2_init.c
@@ -206,16 +206,7 @@ int mt76x2_mac_start(struct mt76x2_dev *dev)
 
 	memset(dev->aggr_stats, 0, sizeof(dev->aggr_stats));
 
-	mt76_wr(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_TX);
-	mt76x02_wait_for_wpdma(&dev->mt76, 1000);
-	usleep_range(50, 100);
-
-	mt76_set(dev, MT_WPDMA_GLO_CFG,
-		 MT_WPDMA_GLO_CFG_TX_DMA_EN |
-		 MT_WPDMA_GLO_CFG_RX_DMA_EN);
-
-	mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE);
-
+	mt76x02_dma_enable(&dev->mt76);
 	mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);
 
 	mt76_wr(dev, MT_MAC_SYS_CTRL,
@@ -354,20 +345,13 @@ int mt76x2_init_hardware(struct mt76x2_dev *dev)
 		0xc000,
 		0xc000,
 	};
-	u32 val;
 	int ret;
 
 	dev->beacon_offsets = beacon_offsets;
 	tasklet_init(&dev->pre_tbtt_tasklet, mt76x2_pre_tbtt_tasklet,
 		     (unsigned long) dev);
 
-	val = mt76_rr(dev, MT_WPDMA_GLO_CFG);
-	val &= MT_WPDMA_GLO_CFG_DMA_BURST_SIZE |
-	       MT_WPDMA_GLO_CFG_BIG_ENDIAN |
-	       MT_WPDMA_GLO_CFG_HDR_SEG_LEN;
-	val |= MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE;
-	mt76_wr(dev, MT_WPDMA_GLO_CFG, val);
-
+	mt76x02_dma_disable(&dev->mt76);
 	mt76x2_reset_wlan(dev, true);
 	mt76x2_power_on(dev);
 
-- 
2.17.1


  parent reply	other threads:[~2018-09-27  9:02 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-27  9:01 [PATCH 00/26] add mt76x0e hw initialization support Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 01/26] mt76x0: use mt76_poll in mt76x0_set_wlan_state Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 02/26] mt76: move wait_for_wpdma in mt76x02_dma.h Lorenzo Bianconi
2018-09-27  9:01 ` Lorenzo Bianconi [this message]
2018-09-27  9:01 ` [PATCH 04/26] mt76: move mt76x02_set_irq_mask in mt76x02_core.c Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 05/26] mt76: move queue initialization in mt76x02_dma.c Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 06/26] mt76: move mt76x02_beacon_offset in mt76x02_core.c Lorenzo Bianconi
2018-09-27 10:06   ` Stanislaw Gruszka
2018-09-27 15:14     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 07/26] mt76: mmio: add implementation of wr_rp and rd_rp Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 08/26] mt76: move mt76x2_wait_for_bbp in mt76x02-lib module Lorenzo Bianconi
2018-09-27 10:10   ` Stanislaw Gruszka
2018-09-27 15:15     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 09/26] mt76x0: update initvals to latest version of vendor driver Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 10/26] mt76x0: pci: move mcu code in pci_mcu.c Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 11/26] mt76x0: usb: move mcu code in usb_mcu.c Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 12/26] mt76x0: use mt76x02 utility routines in mt76x0 init code Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 13/26] mt76x0: init: remove duplicated initialization Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 14/26] mt76x0: init: remove MT_PBF_SYS_CTRL configuration in mt76x0_reset_csr_bbp Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 15/26] mt76x0: init: reset beacon offset during bootstrap Lorenzo Bianconi
2018-09-27 10:14   ` Stanislaw Gruszka
2018-09-27 15:12     ` Lorenzo Bianconi
2018-09-27 10:15   ` Felix Fietkau
2018-09-27 15:12     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 16/26] mt76x0: init rx filter in mt76x0_init_hardware Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 17/26] mt76: add mt76x02_mac_start routine Lorenzo Bianconi
2018-09-27 10:17   ` Stanislaw Gruszka
2018-09-27 15:10     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 18/26] mt76x0: usb: move initialization code in usb_init.c Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 19/26] mt76x0: pci: add hw initialization at bootstrap Lorenzo Bianconi
2018-09-27 10:24   ` Stanislaw Gruszka
2018-09-27 15:18     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 20/26] mt76x0: phy: set antenna parameter according to wireless band Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 21/26] mt76: move set_{tx,rx}_path routines in mt76x02-lib module Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 22/26] mt76x0: add ieee80211_ops ops pointer to mt76x0_alloc_device signature Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 23/26] mt76x0: pci: add mt76x0e_start callback Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 24/26] mt76x0: pci: add mt76x0e_stop callback Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 25/26] mt76: move eeprom_load routines in mt76x02_eeprom.c Lorenzo Bianconi
2018-09-27 10:30   ` Felix Fietkau
2018-09-27 14:46     ` Lorenzo Bianconi
2018-09-27  9:01 ` [PATCH 26/26] mt76x0: introduce mt76x0{e,u}_eeprom_init routines Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=829c1c000477a7600add8319e5a3cff46b690ff6.1538036134.git.lorenzo.bianconi@redhat.com \
    --to=lorenzo.bianconi@redhat.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    --cc=sgruszka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.