Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RESEND PATCH net 07/10] net: ethernet: mediatek: fix issue of driver removal with interface is up
From: Sean Wang @ 2016-08-26  5:50 UTC (permalink / raw)
  To: john-Pj+rj9U5foFAfugRpC6u6w
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q, keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <2203871f-d73d-3a39-928d-39862ba5e367-Pj+rj9U5foFAfugRpC6u6w@public.gmane.org>

Date: Thu, 25 Aug 2016 15:35:34 +0200, John Crispin wrote:
>On 25/08/2016 12:44, Sean Wang wrote:
>> 1) mtk_stop() must be called to stop for freeing DMA resources
>> acquired and restoring state changed by mtk_open() when module
>> removal.
>> 
>> 2) group clock disabled related function into mtk_hw_deinit which
>> could be reused with others functionality such as the whole ethernet
>> reset that would be posted in the later series of patches.
>> 
>
>Hi Sean,
>
>these are 2 unrelated changes so they really need to go into two
>separate patches. i also think that change 1) would better fit into the
>future series making use of that functionality.
>
>	John
>

okay. splitting makes sense more

I will leave 1) here 
and move 2) into the better place that is one part of the future series 
about whole ethernet reset, I will post them after the current series is done

thanks for your effort on reviewing

>> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
>> ---
>>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 22 ++++++++++++++++++----
>>  1 file changed, 18 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> index 0a4c782..c573475 100644
>> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
>> @@ -1478,6 +1478,16 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
>>  	return 0;
>>  }
>>  
>> +static int mtk_hw_deinit(struct mtk_eth *eth)
>> +{
>> +	clk_disable_unprepare(eth->clk_esw);
>> +	clk_disable_unprepare(eth->clk_gp1);
>> +	clk_disable_unprepare(eth->clk_gp2);
>> +	clk_disable_unprepare(eth->clk_ethif);
>> +
>> +	return 0;
>> +}
>> +
>>  static int __init mtk_init(struct net_device *dev)
>>  {
>>  	struct mtk_mac *mac = netdev_priv(dev);
>> @@ -1919,11 +1929,15 @@ err_free_dev:
>>  static int mtk_remove(struct platform_device *pdev)
>>  {
>>  	struct mtk_eth *eth = platform_get_drvdata(pdev);
>> +	int i;
>>  
>> -	clk_disable_unprepare(eth->clk_ethif);
>> -	clk_disable_unprepare(eth->clk_esw);
>> -	clk_disable_unprepare(eth->clk_gp1);
>> -	clk_disable_unprepare(eth->clk_gp2);
>> +	/* stop all devices to make sure that dma is properly shut down */
>> +	for (i = 0; i < MTK_MAC_COUNT; i++) {
>> +		if (!eth->netdev[i])
>> +			continue;
>> +		mtk_stop(eth->netdev[i]);
>> +	}
>> +	mtk_hw_deinit(eth);
>>  
>>  	netif_napi_del(&eth->tx_napi);
>>  	netif_napi_del(&eth->rx_napi);
>> 

^ permalink raw reply

* Re: [RESEND PATCH net 02/10] net: ethernet: mediatek: fix incorrect
From: Sean Wang @ 2016-08-26  5:22 UTC (permalink / raw)
  To: john-Pj+rj9U5foFAfugRpC6u6w
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q, keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <e1e9ca7a-c33b-3a9e-fd47-48f80bb10a32-Pj+rj9U5foFAfugRpC6u6w@public.gmane.org>

On Date: Thu, 25 Aug 2016 15:49:10 +0200, John Crispin wrote:
>On 25/08/2016 12:44, Sean Wang wrote:
>> If the return value of devm_clk_get is EPROBE_DEFER, we should
>> defer probing the driver. The change is verified and works based
>> on 4.8-rc1 staying with the latest clk-next code for MT7623.
>> 
>> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
>> ---
>>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
...
>> +		    PTR_ERR(eth->clk_gp2) == -EPROBE_DEFER)
>> +			return -EPROBE_DEFER;
>> +		else
>> +			return -ENODEV;
>> +	}
>
>Hi Sean,
>
>this looks a bit tedious. maybe a better solution would be to add an
>array to struct mtk_eth for the clocks and an enum for the index
>mapping. that would allow the usage of loops to work out if all clocks
>are fine. the following code calling clk_prepare_enable() could then
>also be turned into a loop
>
>	John

The suggestion is better, so I will use your suggested way to 
to implement the logic in the next version.

>
>>  
>>  	clk_prepare_enable(eth->clk_ethif);
>>  	clk_prepare_enable(eth->clk_esw);
>> 

^ permalink raw reply

* Re: [RESEND PATCH net 06/10] net: ethernet: mediatek: fix the loss
From: Sean Wang @ 2016-08-26  3:33 UTC (permalink / raw)
  To: andrew-g2DYL2Zd6BY
  Cc: nbd-p3rKhJxN3npAfugRpC6u6w, keyhaede-Re5JQEeQqe8AvxtiuMwx3w,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	john-Pj+rj9U5foFAfugRpC6u6w, davem-fT/PcQaiUtIeIZ0/mPfg9Q
In-Reply-To: <20160825133034.GA25046-g2DYL2Zd6BY@public.gmane.org>

On Thu, 25 Aug 2016 15:30:34 +0200, Andrew Lunn wrote:
>On Thu, Aug 25, 2016 at 06:44:57PM +0800, Sean Wang wrote:
>> ommited the setting about pin-mux which results in incorrect signals
>> being routed on GMAC2.
>
>Hi Sean
>
>Please could you explain this some more. I don't know too much about
>pinctrl, but i've never seen a driver have to do anything with it. The
>core driver code handles it all, selecting the default state. See
>seeing this here makes me wonder if it is correct.
>
>Thanks
>	Andrew
>
>>

Hi Andrew,

Here pinctrl is used to setup what function the group of the pins is for.

The group of the pins could be configured for the function provided 
by the SoC, such as general purpose I/O or specific function such as
ethernet depending on what products or boards you design for various 
customers or vendors. Thanks for device tree introducing, it is easy 
to find what resources the board needs including the pins usage is 
also defined here.
 
Pins are limited resource that is also meant for the cost 
so that it is common way seen on embedded system.

thanks,
Sean

>> +	eth->pins = devm_pinctrl_get(&pdev->dev);
>> +	if (IS_ERR(eth->pins)) {
>> +		dev_err(&pdev->dev, "cannot get pinctrl\n");
>> +		return PTR_ERR(eth->pins);
>> +	}
>> +
>> +	eth->ephy_default =
>> +		pinctrl_lookup_state(eth->pins, "default");
>> +	if (IS_ERR(eth->ephy_default)) {
>> +		dev_err(&pdev->dev, "cannot get pinctrl state\n");
>> +		return PTR_ERR(eth->ephy_default);
>> +	}
>> +
>>  	clk_prepare_enable(eth->clk_ethif);
>>  	clk_prepare_enable(eth->clk_esw);
>>  	clk_prepare_enable(eth->clk_gp1);
>> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
>> index f82e3ac..13d3f1b 100644
>> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
>> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
>> @@ -404,6 +404,9 @@ struct mtk_eth {
>>  	struct clk			*clk_esw;
>>  	struct clk			*clk_gp1;
>>  	struct clk			*clk_gp2;
>> +	struct pinctrl			*pins;
>> +	struct pinctrl_state		*ephy_default;
>> +
>>  	struct mii_bus			*mii_bus;
>>  	struct work_struct		pending_work;
>>  };
>> -- 
>> 1.9.1

^ permalink raw reply

* [PATCH net-next v4 2/2] net: ethernet: mediatek: modify GDM to send packets to the PDMA for RX
From: Nelson Chang @ 2016-08-25 17:09 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, nelsonch.tw, Nelson Chang
In-Reply-To: <1472144983-5048-1-git-send-email-nelson.chang@mediatek.com>

Because we change to use the PDMA as the Ethernet RX DMA engine,
the patch modifies to set GDM to send packets to PDMA for RX.

Acked-by: John Crispin <john@phrozen.org>
Signed-off-by: Nelson Chang <nelson.chang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index cbeb793..0fd9fc8 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -1473,9 +1473,8 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
 	for (i = 0; i < 2; i++) {
 		u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
 
-		/* setup the forward port to send frame to QDMA */
+		/* setup the forward port to send frame to PDMA */
 		val &= ~0xffff;
-		val |= 0x5555;
 
 		/* Enable RX checksum */
 		val |= MTK_GDMA_ICS_EN | MTK_GDMA_TCS_EN | MTK_GDMA_UCS_EN;
-- 
1.9.1

^ permalink raw reply related

* [PATCH net-next v4 1/2] net: ethernet: mediatek: modify to use the PDMA instead of the QDMA for Ethernet RX
From: Nelson Chang @ 2016-08-25 17:09 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, nelsonch.tw, Nelson Chang
In-Reply-To: <1472144983-5048-1-git-send-email-nelson.chang@mediatek.com>

Because the PDMA has richer features than the QDMA for Ethernet RX
(such as multiple RX rings, HW LRO, etc.),
the patch modifies to use the PDMA to handle Ethernet RX.

Acked-by: John Crispin <john@phrozen.org>
Signed-off-by: Nelson Chang <nelson.chang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 76 +++++++++++++++++------------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 31 +++++++++++-
 2 files changed, 74 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 1801fd8..cbeb793 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -342,25 +342,27 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
 	mdiobus_free(eth->mii_bus);
 }
 
-static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
+static inline void mtk_irq_disable(struct mtk_eth *eth,
+				   unsigned reg, u32 mask)
 {
 	unsigned long flags;
 	u32 val;
 
 	spin_lock_irqsave(&eth->irq_lock, flags);
-	val = mtk_r32(eth, MTK_QDMA_INT_MASK);
-	mtk_w32(eth, val & ~mask, MTK_QDMA_INT_MASK);
+	val = mtk_r32(eth, reg);
+	mtk_w32(eth, val & ~mask, reg);
 	spin_unlock_irqrestore(&eth->irq_lock, flags);
 }
 
-static inline void mtk_irq_enable(struct mtk_eth *eth, u32 mask)
+static inline void mtk_irq_enable(struct mtk_eth *eth,
+				  unsigned reg, u32 mask)
 {
 	unsigned long flags;
 	u32 val;
 
 	spin_lock_irqsave(&eth->irq_lock, flags);
-	val = mtk_r32(eth, MTK_QDMA_INT_MASK);
-	mtk_w32(eth, val | mask, MTK_QDMA_INT_MASK);
+	val = mtk_r32(eth, reg);
+	mtk_w32(eth, val | mask, reg);
 	spin_unlock_irqrestore(&eth->irq_lock, flags);
 }
 
@@ -897,12 +899,12 @@ release_desc:
 		 * we continue
 		 */
 		wmb();
-		mtk_w32(eth, ring->calc_idx, MTK_QRX_CRX_IDX0);
+		mtk_w32(eth, ring->calc_idx, MTK_PRX_CRX_IDX0);
 		done++;
 	}
 
 	if (done < budget)
-		mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
+		mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
 
 	return done;
 }
@@ -1012,7 +1014,7 @@ static int mtk_napi_tx(struct napi_struct *napi, int budget)
 		return budget;
 
 	napi_complete(napi);
-	mtk_irq_enable(eth, MTK_TX_DONE_INT);
+	mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
 
 	return tx_done;
 }
@@ -1024,12 +1026,12 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
 	int rx_done = 0;
 
 	mtk_handle_status_irq(eth);
-	mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
+	mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
 	rx_done = mtk_poll_rx(napi, budget, eth);
 
 	if (unlikely(netif_msg_intr(eth))) {
-		status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
-		mask = mtk_r32(eth, MTK_QDMA_INT_MASK);
+		status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
+		mask = mtk_r32(eth, MTK_PDMA_INT_MASK);
 		dev_info(eth->dev,
 			 "done rx %d, intr 0x%08x/0x%x\n",
 			 rx_done, status, mask);
@@ -1038,12 +1040,12 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
 	if (rx_done == budget)
 		return budget;
 
-	status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
+	status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
 	if (status & MTK_RX_DONE_INT)
 		return budget;
 
 	napi_complete(napi);
-	mtk_irq_enable(eth, MTK_RX_DONE_INT);
+	mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 
 	return rx_done;
 }
@@ -1092,6 +1094,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
 	mtk_w32(eth,
 		ring->phys + ((MTK_DMA_SIZE - 1) * sz),
 		MTK_QTX_DRX_PTR);
+	mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES, MTK_QTX_CFG(0));
 
 	return 0;
 
@@ -1162,11 +1165,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth)
 	 */
 	wmb();
 
-	mtk_w32(eth, eth->rx_ring.phys, MTK_QRX_BASE_PTR0);
-	mtk_w32(eth, MTK_DMA_SIZE, MTK_QRX_MAX_CNT0);
-	mtk_w32(eth, eth->rx_ring.calc_idx, MTK_QRX_CRX_IDX0);
-	mtk_w32(eth, MTK_PST_DRX_IDX0, MTK_QDMA_RST_IDX);
-	mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES, MTK_QTX_CFG(0));
+	mtk_w32(eth, eth->rx_ring.phys, MTK_PRX_BASE_PTR0);
+	mtk_w32(eth, MTK_DMA_SIZE, MTK_PRX_MAX_CNT0);
+	mtk_w32(eth, eth->rx_ring.calc_idx, MTK_PRX_CRX_IDX0);
+	mtk_w32(eth, MTK_PST_DRX_IDX0, MTK_PDMA_RST_IDX);
 
 	return 0;
 }
@@ -1285,7 +1287,7 @@ static irqreturn_t mtk_handle_irq_rx(int irq, void *_eth)
 
 	if (likely(napi_schedule_prep(&eth->rx_napi))) {
 		__napi_schedule(&eth->rx_napi);
-		mtk_irq_disable(eth, MTK_RX_DONE_INT);
+		mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 	}
 
 	return IRQ_HANDLED;
@@ -1297,7 +1299,7 @@ static irqreturn_t mtk_handle_irq_tx(int irq, void *_eth)
 
 	if (likely(napi_schedule_prep(&eth->tx_napi))) {
 		__napi_schedule(&eth->tx_napi);
-		mtk_irq_disable(eth, MTK_TX_DONE_INT);
+		mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
 	}
 
 	return IRQ_HANDLED;
@@ -1308,11 +1310,12 @@ static void mtk_poll_controller(struct net_device *dev)
 {
 	struct mtk_mac *mac = netdev_priv(dev);
 	struct mtk_eth *eth = mac->hw;
-	u32 int_mask = MTK_TX_DONE_INT | MTK_RX_DONE_INT;
 
-	mtk_irq_disable(eth, int_mask);
+	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
+	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 	mtk_handle_irq_rx(eth->irq[2], dev);
-	mtk_irq_enable(eth, int_mask);
+	mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
+	mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 }
 #endif
 
@@ -1327,11 +1330,15 @@ static int mtk_start_dma(struct mtk_eth *eth)
 	}
 
 	mtk_w32(eth,
-		MTK_TX_WB_DDONE | MTK_RX_DMA_EN | MTK_TX_DMA_EN |
-		MTK_RX_2B_OFFSET | MTK_DMA_SIZE_16DWORDS |
-		MTK_RX_BT_32DWORDS | MTK_NDP_CO_PRO,
+		MTK_TX_WB_DDONE | MTK_TX_DMA_EN |
+		MTK_DMA_SIZE_16DWORDS | MTK_NDP_CO_PRO,
 		MTK_QDMA_GLO_CFG);
 
+	mtk_w32(eth,
+		MTK_RX_DMA_EN | MTK_RX_2B_OFFSET |
+		MTK_RX_BT_32DWORDS | MTK_MULTI_EN,
+		MTK_PDMA_GLO_CFG);
+
 	return 0;
 }
 
@@ -1349,7 +1356,8 @@ static int mtk_open(struct net_device *dev)
 
 		napi_enable(&eth->tx_napi);
 		napi_enable(&eth->rx_napi);
-		mtk_irq_enable(eth, MTK_TX_DONE_INT | MTK_RX_DONE_INT);
+		mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
+		mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 	}
 	atomic_inc(&eth->dma_refcnt);
 
@@ -1394,7 +1402,8 @@ static int mtk_stop(struct net_device *dev)
 	if (!atomic_dec_and_test(&eth->dma_refcnt))
 		return 0;
 
-	mtk_irq_disable(eth, MTK_TX_DONE_INT | MTK_RX_DONE_INT);
+	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
+	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
 	napi_disable(&eth->tx_napi);
 	napi_disable(&eth->rx_napi);
 
@@ -1448,7 +1457,9 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
 
 	/* disable delay and normal interrupt */
 	mtk_w32(eth, 0, MTK_QDMA_DELAY_INT);
-	mtk_irq_disable(eth, ~0);
+	mtk_w32(eth, 0, MTK_PDMA_DELAY_INT);
+	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
+	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
 	mtk_w32(eth, RST_GL_PSE, MTK_RST_GL);
 	mtk_w32(eth, 0, MTK_RST_GL);
 
@@ -1504,7 +1515,8 @@ static void mtk_uninit(struct net_device *dev)
 
 	phy_disconnect(mac->phy_dev);
 	mtk_mdio_cleanup(eth);
-	mtk_irq_disable(eth, ~0);
+	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
+	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
 	free_irq(eth->irq[1], dev);
 	free_irq(eth->irq[2], dev);
 }
@@ -1683,7 +1695,7 @@ static void mtk_get_ethtool_stats(struct net_device *dev,
 	}
 
 	do {
-		data_src = (u64*)hwstats;
+		data_src = (u64 *)hwstats;
 		data_dst = data;
 		start = u64_stats_fetch_begin_irq(&hwstats->syncp);
 
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index f82e3ac..7c1f3f2 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -68,6 +68,32 @@
 /* Unicast Filter MAC Address Register - High */
 #define MTK_GDMA_MAC_ADRH(x)	(0x50C + (x * 0x1000))
 
+/* PDMA RX Base Pointer Register */
+#define MTK_PRX_BASE_PTR0	0x900
+
+/* PDMA RX Maximum Count Register */
+#define MTK_PRX_MAX_CNT0	0x904
+
+/* PDMA RX CPU Pointer Register */
+#define MTK_PRX_CRX_IDX0	0x908
+
+/* PDMA Global Configuration Register */
+#define MTK_PDMA_GLO_CFG	0xa04
+#define MTK_MULTI_EN		BIT(10)
+
+/* PDMA Reset Index Register */
+#define MTK_PDMA_RST_IDX	0xa08
+#define MTK_PST_DRX_IDX0	BIT(16)
+
+/* PDMA Delay Interrupt Register */
+#define MTK_PDMA_DELAY_INT	0xa0c
+
+/* PDMA Interrupt Status Register */
+#define MTK_PDMA_INT_STATUS	0xa20
+
+/* PDMA Interrupt Mask Register */
+#define MTK_PDMA_INT_MASK	0xa28
+
 /* PDMA Interrupt grouping registers */
 #define MTK_PDMA_INT_GRP1	0xa50
 #define MTK_PDMA_INT_GRP2	0xa54
@@ -119,13 +145,16 @@
 
 /* QDMA Interrupt Status Register */
 #define MTK_QMTK_INT_STATUS	0x1A18
+#define MTK_RX_DONE_INT3	BIT(19)
+#define MTK_RX_DONE_INT2	BIT(18)
 #define MTK_RX_DONE_INT1	BIT(17)
 #define MTK_RX_DONE_INT0	BIT(16)
 #define MTK_TX_DONE_INT3	BIT(3)
 #define MTK_TX_DONE_INT2	BIT(2)
 #define MTK_TX_DONE_INT1	BIT(1)
 #define MTK_TX_DONE_INT0	BIT(0)
-#define MTK_RX_DONE_INT		(MTK_RX_DONE_INT0 | MTK_RX_DONE_INT1)
+#define MTK_RX_DONE_INT		(MTK_RX_DONE_INT0 | MTK_RX_DONE_INT1 | \
+				 MTK_RX_DONE_INT2 | MTK_RX_DONE_INT3)
 #define MTK_TX_DONE_INT		(MTK_TX_DONE_INT0 | MTK_TX_DONE_INT1 | \
 				 MTK_TX_DONE_INT2 | MTK_TX_DONE_INT3)
 
-- 
1.9.1

^ permalink raw reply related

* [PATCH net-next v4 0/2] net: ethernet: mediatek: modify to use the PDMA for Ethernet RX
From: Nelson Chang @ 2016-08-25 17:09 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, nelsonch.tw, Nelson Chang

This series have some modifications and refines to support Ethernet RX by the PDMA.

changes since v4:
- Remove the redundant OR operation in mtk_hw_init()

changes since v3:
- Add GDM hardware settings to send packets to PDMA for RX

changes since v2:
- Fix the bugs of PDMA cpu index and interrupt settings in mtk_poll_rx()

changes since v1:
- Modify to use the PDMA instead of the QDMA for Ethernet RX

Nelson Chang (2):
  net: ethernet: mediatek: modify to use the PDMA instead of the QDMA
    for Ethernet RX
  net: ethernet: mediatek: modify GDM to send packets to the PDMA for RX

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 79 ++++++++++++++++-------------
 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 31 ++++++++++-
 2 files changed, 75 insertions(+), 35 deletions(-)

-- 
1.9.1

^ permalink raw reply

* Re: [PATCH net 00/10] net: ethernet: mediatek: a couple of fixes
From: David Miller @ 2016-08-25 16:13 UTC (permalink / raw)
  To: sean.wang-NuS5LvNUpcJWk0Htik3J/w
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	keyhaede-Re5JQEeQqe8AvxtiuMwx3w, john-Pj+rj9U5foFAfugRpC6u6w
In-Reply-To: <1472120557-15216-1-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

From: Sean Wang
Date: Thu, 25 Aug 2016 18:22:27 +0800


You really need to fix whatever you used to send this patch set
out, all of the email header fields were messed up.

^ permalink raw reply

* Re: [RESEND PATCH net 02/10] net: ethernet: mediatek: fix incorrect return value of devm_clk_get with EPROBE_DEFER
From: John Crispin @ 2016-08-25 13:49 UTC (permalink / raw)
  To: Sean Wang, davem; +Cc: netdev, nbd, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-3-git-send-email-sean.wang@mediatek.com>



On 25/08/2016 12:44, Sean Wang wrote:
> If the return value of devm_clk_get is EPROBE_DEFER, we should
> defer probing the driver. The change is verified and works based
> on 4.8-rc1 staying with the latest clk-next code for MT7623.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 6e4a6ca..02b048f 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1851,8 +1851,15 @@ static int mtk_probe(struct platform_device *pdev)
>  	eth->clk_gp1 = devm_clk_get(&pdev->dev, "gp1");
>  	eth->clk_gp2 = devm_clk_get(&pdev->dev, "gp2");
>  	if (IS_ERR(eth->clk_esw) || IS_ERR(eth->clk_gp1) ||
> -	    IS_ERR(eth->clk_gp2) || IS_ERR(eth->clk_ethif))
> -		return -ENODEV;
> +	    IS_ERR(eth->clk_gp2) || IS_ERR(eth->clk_ethif)) {
> +		if (PTR_ERR(eth->clk_esw) == -EPROBE_DEFER ||
> +		    PTR_ERR(eth->clk_gp1) == -EPROBE_DEFER ||
> +		    PTR_ERR(eth->clk_gp1) == -EPROBE_DEFER ||
> +		    PTR_ERR(eth->clk_gp2) == -EPROBE_DEFER)
> +			return -EPROBE_DEFER;
> +		else
> +			return -ENODEV;
> +	}

Hi Sean,

this looks a bit tedious. maybe a better solution would be to add an
array to struct mtk_eth for the clocks and an enum for the index
mapping. that would allow the usage of loops to work out if all clocks
are fine. the following code calling clk_prepare_enable() could then
also be turned into a loop

	John

>  
>  	clk_prepare_enable(eth->clk_ethif);
>  	clk_prepare_enable(eth->clk_esw);
> 

^ permalink raw reply

* Re: [PATCH v13 0/4] Mediatek MT8173 CMDQ support
From: Jassi Brar @ 2016-08-25 13:42 UTC (permalink / raw)
  To: Horng-Shyang Liao
  Cc: Matthias Brugger, Rob Herring, Daniel Kurtz, Sascha Hauer,
	Devicetree List, Linux Kernel Mailing List,
	linux-arm-kernel@lists.infradead.org, linux-mediatek,
	srv_heupstream, Sascha Hauer, Philipp Zabel, Nicolas Boichat,
	CK HU, cawa cheng, Bibby Hsieh, YT Shen, Daoyuan Huang, Damon Chu
In-Reply-To: <1472132247.26044.23.camel@mtksdaap41>

On Thu, Aug 25, 2016 at 7:07 PM, Horng-Shyang Liao <hs.liao@mediatek.com> wrote:
> Hi Matthias,
>
> On Wed, 2016-08-24 at 13:00 +0200, Matthias Brugger wrote:
>> On 24/08/16 05:27, HS Liao wrote:
> [...]
>> > Changes since v12:
>> >  - remove mediatek,gce from device tree
>>
>> Why? The binding got accepted by Rob.
>
> We can get cmdq dev from mailbox controller,
> so we don't need mediatek,gce anymore.
>
>> >
>> > Best regards,
>> > HS Liao
>> >
>> > HS Liao (4):
>> >   dt-bindings: soc: Add documentation for the MediaTek GCE unit
>> >   CMDQ: Mediatek CMDQ driver
>> >   arm64: dts: mt8173: Add GCE node
>> >   CMDQ: save more energy in idle
>> >
>> >  .../devicetree/bindings/soc/mediatek/gce.txt       |  44 +
>> >  arch/arm64/boot/dts/mediatek/mt8173.dtsi           |  10 +
>> >  drivers/soc/mediatek/Kconfig                       |  11 +
>> >  drivers/soc/mediatek/Makefile                      |   1 +
>> >  drivers/soc/mediatek/mtk-cmdq.c                    | 983 +++++++++++++++++++++
>>
>> The driver uses the mailbox framework, so it should live in the
>> drivers/mailbox folder.
>
> As you know, the maximum number of gce threads is 16.
> However, we plan to support more clients in the future,
> and they may need to use more than 16 gce threads.
>
> For this issue, our plan is to let multiple clients share the same gce
> thread; i.e. we will acquire gce thread for client dynamically by
> internal policy in cmdq driver.
> Unfortunately. mailbox channel has exclusive feature.
> Quote from comment of mbox_request_channel().
> "The channel is exclusively allocated and can't be used by another
> client before the owner calls mbox_free_channel."
> Therefore, we plan to remove mailbox framework from cmdq driver in the
> future.
>
Platforms that need shared access to a channel, implement a 'server'
driver that serialise (which is needed still) the access to common
channel. If you think you don't need mutual exclusion and don't care
about replies, simply share the mailbox handle among different
clients.

^ permalink raw reply

* Re: [RESEND PATCH net 10/10] net: ethernet: mediatek: fix error handling inside mtk_mdio_init
From: John Crispin @ 2016-08-25 13:39 UTC (permalink / raw)
  To: Sean Wang, davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <1472121901-15629-11-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>



On 25/08/2016 12:45, Sean Wang wrote:
> return -ENODEV if no child is found in MDIO bus.
> 
> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

Acked-by: John Crispin <john-Pj+rj9U5foFAfugRpC6u6w@public.gmane.org>

> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 05d85da..2d547c2 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -300,7 +300,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  	}
>  
>  	if (!of_device_is_available(mii_np)) {
> -		err = 0;
> +		err = -ENODEV;
>  		goto err_put_node;
>  	}
>  
> 

^ permalink raw reply

* Re: [RESEND PATCH net 09/10] net: ethernet: mediatek: use devm_mdiobus_alloc instead of mdiobus_alloc inside mtk_mdio_init
From: John Crispin @ 2016-08-25 13:39 UTC (permalink / raw)
  To: Sean Wang, davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <1472121901-15629-10-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

Hi Sean,

small nitpick inline

On 25/08/2016 12:45, Sean Wang wrote:
> a lot of parts in the driver uses devm_* APIs to gain benefits from the
> device resource management, so devm_mdiobus_alloc is also used instead
> of mdiobus_alloc to have more elegant code flow.
> 
> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index e3baa63..05d85da 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -304,7 +304,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  		goto err_put_node;
>  	}
>  
> -	eth->mii_bus = mdiobus_alloc();
> +	eth->mii_bus = devm_mdiobus_alloc(eth->dev);
>  	if (!eth->mii_bus) {
>  		err = -ENOMEM;
>  		goto err_put_node;
> @@ -318,18 +318,9 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  
>  	snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name);
>  	err = of_mdiobus_register(eth->mii_bus, mii_np);
> -	if (err)
> -		goto err_free_bus;
> -	of_node_put(mii_np);
> -
> -	return 0;
> -
> -err_free_bus:
> -	mdiobus_free(eth->mii_bus);
>  
>  err_put_node:
>  	of_node_put(mii_np);
> -	eth->mii_bus = NULL;
>  	return err;

you might want to rename err to ret. that would make it more readable.
right now it looks like the code always flows through the error path.

	John

>  }
>  
> @@ -339,8 +330,6 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
>  		return;
>  
>  	mdiobus_unregister(eth->mii_bus);
> -	of_node_put(eth->mii_bus->dev.of_node);
> -	mdiobus_free(eth->mii_bus);
>  }
>  
>  static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
> 

^ permalink raw reply

* Re: [PATCH v13 0/4] Mediatek MT8173 CMDQ support
From: Horng-Shyang Liao @ 2016-08-25 13:37 UTC (permalink / raw)
  To: Matthias Brugger
  Cc: Rob Herring, Daniel Kurtz, Sascha Hauer, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek, srv_heupstream, Sascha Hauer,
	Philipp Zabel, Nicolas Boichat, CK HU, cawa cheng, Bibby Hsieh,
	YT Shen, Daoyuan Huang, Damon Chu, Josh-YC Liu, Glory Hung,
	Jiaguang Zhang
In-Reply-To: <20b10079-3ae2-9da9-1149-0bceabac9837@gmail.com>

Hi Matthias,

On Wed, 2016-08-24 at 13:00 +0200, Matthias Brugger wrote:
> On 24/08/16 05:27, HS Liao wrote:
[...]
> > Changes since v12:
> >  - remove mediatek,gce from device tree
> 
> Why? The binding got accepted by Rob.

We can get cmdq dev from mailbox controller,
so we don't need mediatek,gce anymore.

> >
> > Best regards,
> > HS Liao
> >
> > HS Liao (4):
> >   dt-bindings: soc: Add documentation for the MediaTek GCE unit
> >   CMDQ: Mediatek CMDQ driver
> >   arm64: dts: mt8173: Add GCE node
> >   CMDQ: save more energy in idle
> >
> >  .../devicetree/bindings/soc/mediatek/gce.txt       |  44 +
> >  arch/arm64/boot/dts/mediatek/mt8173.dtsi           |  10 +
> >  drivers/soc/mediatek/Kconfig                       |  11 +
> >  drivers/soc/mediatek/Makefile                      |   1 +
> >  drivers/soc/mediatek/mtk-cmdq.c                    | 983 +++++++++++++++++++++
> 
> The driver uses the mailbox framework, so it should live in the 
> drivers/mailbox folder.

As you know, the maximum number of gce threads is 16.
However, we plan to support more clients in the future,
and they may need to use more than 16 gce threads.

For this issue, our plan is to let multiple clients share the same gce
thread; i.e. we will acquire gce thread for client dynamically by
internal policy in cmdq driver.
Unfortunately. mailbox channel has exclusive feature.
Quote from comment of mbox_request_channel().
"The channel is exclusively allocated and can't be used by another
client before the owner calls mbox_free_channel."
Therefore, we plan to remove mailbox framework from cmdq driver in the
future.

For current status, could you tell us your preference?
(1) Move cmdq to mailbox folder and then move it back here when we
submit another patch to support more than 16 gce clients; or
(2) Remove mailbox framework from cmdq now for its future extensibility.

Thanks,
HS

> Please don't forget to add Jassi to the loop, as he is the maintainer of 
> this subsystem and the last instance to decide if/when the driver will 
> get accepted.
> 
> Thanks,
> Matthias
> 

^ permalink raw reply

* Re: [RESEND PATCH net 08/10] net: ethernet: mediatek: fix the missing of_node_put() after node is used done inside mtk_mdio_init
From: John Crispin @ 2016-08-25 13:36 UTC (permalink / raw)
  To: Sean Wang, davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <1472121901-15629-9-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>



On 25/08/2016 12:44, Sean Wang wrote:
> This patch adds the missing of_node_put() after finishing the usage
> of of_get_child_by_name.
> 
> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

Acked-by: John Crispin <john-Pj+rj9U5foFAfugRpC6u6w@public.gmane.org>

> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index c573475..e3baa63 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -320,6 +320,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  	err = of_mdiobus_register(eth->mii_bus, mii_np);
>  	if (err)
>  		goto err_free_bus;
> +	of_node_put(mii_np);
>  
>  	return 0;
>  
> 

^ permalink raw reply

* Re: [RESEND PATCH net 07/10] net: ethernet: mediatek: fix issue of driver removal with interface is up
From: John Crispin @ 2016-08-25 13:35 UTC (permalink / raw)
  To: Sean Wang, davem-fT/PcQaiUtIeIZ0/mPfg9Q
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, nbd-p3rKhJxN3npAfugRpC6u6w,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	keyhaede-Re5JQEeQqe8AvxtiuMwx3w
In-Reply-To: <1472121901-15629-8-git-send-email-sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>



On 25/08/2016 12:44, Sean Wang wrote:
> 1) mtk_stop() must be called to stop for freeing DMA resources
> acquired and restoring state changed by mtk_open() when module
> removal.
> 
> 2) group clock disabled related function into mtk_hw_deinit which
> could be reused with others functionality such as the whole ethernet
> reset that would be posted in the later series of patches.
> 

Hi Sean,

these are 2 unrelated changes so they really need to go into two
separate patches. i also think that change 1) would better fit into the
future series making use of that functionality.

	John

> Signed-off-by: Sean Wang <sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 0a4c782..c573475 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1478,6 +1478,16 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
>  	return 0;
>  }
>  
> +static int mtk_hw_deinit(struct mtk_eth *eth)
> +{
> +	clk_disable_unprepare(eth->clk_esw);
> +	clk_disable_unprepare(eth->clk_gp1);
> +	clk_disable_unprepare(eth->clk_gp2);
> +	clk_disable_unprepare(eth->clk_ethif);
> +
> +	return 0;
> +}
> +
>  static int __init mtk_init(struct net_device *dev)
>  {
>  	struct mtk_mac *mac = netdev_priv(dev);
> @@ -1919,11 +1929,15 @@ err_free_dev:
>  static int mtk_remove(struct platform_device *pdev)
>  {
>  	struct mtk_eth *eth = platform_get_drvdata(pdev);
> +	int i;
>  
> -	clk_disable_unprepare(eth->clk_ethif);
> -	clk_disable_unprepare(eth->clk_esw);
> -	clk_disable_unprepare(eth->clk_gp1);
> -	clk_disable_unprepare(eth->clk_gp2);
> +	/* stop all devices to make sure that dma is properly shut down */
> +	for (i = 0; i < MTK_MAC_COUNT; i++) {
> +		if (!eth->netdev[i])
> +			continue;
> +		mtk_stop(eth->netdev[i]);
> +	}
> +	mtk_hw_deinit(eth);
>  
>  	netif_napi_del(&eth->tx_napi);
>  	netif_napi_del(&eth->rx_napi);
> 

^ permalink raw reply

* Re: [RESEND PATCH net 06/10] net: ethernet: mediatek: fix the loss of pin-mux setting for GMAC2
From: Andrew Lunn @ 2016-08-25 13:30 UTC (permalink / raw)
  To: Sean Wang; +Cc: john, davem, nbd, netdev, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-7-git-send-email-sean.wang@mediatek.com>

On Thu, Aug 25, 2016 at 06:44:57PM +0800, Sean Wang wrote:
> ommited the setting about pin-mux which results in incorrect signals
> being routed on GMAC2.

Hi Sean

Please could you explain this some more. I don't know too much about
pinctrl, but i've never seen a driver have to do anything with it. The
core driver code handles it all, selecting the default state. See
seeing this here makes me wonder if it is correct.

Thanks
	Andrew

> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 14 ++++++++++++++
>  drivers/net/ethernet/mediatek/mtk_eth_soc.h |  3 +++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 5bd31f8..0a4c782 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1415,6 +1415,7 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
>  	usleep_range(10, 20);
>  	reset_control_deassert(eth->rstc);
>  	usleep_range(10, 20);
> +	pinctrl_select_state(eth->pins, eth->ephy_default);
>  
>  	/* Set GE2 driving and slew rate */
>  	regmap_write(eth->pctl, GPIO_DRV_SEL10, 0xa00);
> @@ -1858,6 +1859,19 @@ static int mtk_probe(struct platform_device *pdev)
>  			return -ENODEV;
>  	}
>  
> +	eth->pins = devm_pinctrl_get(&pdev->dev);
> +	if (IS_ERR(eth->pins)) {
> +		dev_err(&pdev->dev, "cannot get pinctrl\n");
> +		return PTR_ERR(eth->pins);
> +	}
> +
> +	eth->ephy_default =
> +		pinctrl_lookup_state(eth->pins, "default");
> +	if (IS_ERR(eth->ephy_default)) {
> +		dev_err(&pdev->dev, "cannot get pinctrl state\n");
> +		return PTR_ERR(eth->ephy_default);
> +	}
> +
>  	clk_prepare_enable(eth->clk_ethif);
>  	clk_prepare_enable(eth->clk_esw);
>  	clk_prepare_enable(eth->clk_gp1);
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> index f82e3ac..13d3f1b 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> @@ -404,6 +404,9 @@ struct mtk_eth {
>  	struct clk			*clk_esw;
>  	struct clk			*clk_gp1;
>  	struct clk			*clk_gp2;
> +	struct pinctrl			*pins;
> +	struct pinctrl_state		*ephy_default;
> +
>  	struct mii_bus			*mii_bus;
>  	struct work_struct		pending_work;
>  };
> -- 
> 1.9.1
> 

^ permalink raw reply

* Re: [RESEND PATCH net 05/10] net: ethernet: mediatek: fix logic unbalance between probe and remove
From: John Crispin @ 2016-08-25 12:22 UTC (permalink / raw)
  To: Sean Wang, davem; +Cc: netdev, nbd, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-6-git-send-email-sean.wang@mediatek.com>



On 25/08/2016 12:44, Sean Wang wrote:
> original mdio_cleanup is not in the symmetric place against where
> mdio_init is, so relocate mdio_cleanup to the right one.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>

Acked-by: John Crispin <john@phrozen.org>

> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 9883dac..5bd31f8 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1504,7 +1504,6 @@ static void mtk_uninit(struct net_device *dev)
>  	struct mtk_eth *eth = mac->hw;
>  
>  	phy_disconnect(mac->phy_dev);
> -	mtk_mdio_cleanup(eth);
>  	mtk_irq_disable(eth, ~0);
>  }
>  
> @@ -1915,6 +1914,7 @@ static int mtk_remove(struct platform_device *pdev)
>  	netif_napi_del(&eth->tx_napi);
>  	netif_napi_del(&eth->rx_napi);
>  	mtk_cleanup(eth);
> +	mtk_mdio_cleanup(eth);
>  
>  	return 0;
>  }
> 

^ permalink raw reply

* Re: [RESEND PATCH net 03/10] net: ethernet: mediatek: fix API usage with skb_free_frag
From: John Crispin @ 2016-08-25 12:20 UTC (permalink / raw)
  To: Sean Wang, davem; +Cc: netdev, nbd, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-4-git-send-email-sean.wang@mediatek.com>



On 25/08/2016 12:44, Sean Wang wrote:
> use skb_free_frag() instead of legacy put_page()
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>

Acked-by: John Crispin <john@phrozen.org>

> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 02b048f..1b131a1 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -864,7 +864,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
>  		/* receive data */
>  		skb = build_skb(data, ring->frag_size);
>  		if (unlikely(!skb)) {
> -			put_page(virt_to_head_page(new_data));
> +			skb_free_frag(new_data);
>  			netdev->stats.rx_dropped++;
>  			goto release_desc;
>  		}
> 

^ permalink raw reply

* Re: [RESEND PATCH net 04/10] net: ethernet: mediatek: remove redundant free_irq for devm_request_irq allocated irq
From: John Crispin @ 2016-08-25 12:20 UTC (permalink / raw)
  To: Sean Wang, davem; +Cc: netdev, nbd, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-5-git-send-email-sean.wang@mediatek.com>



On 25/08/2016 12:44, Sean Wang wrote:
> these irqs are not used for shared irq and disabled during ethernet stops.
> irq requested by devm_request_irq is safe to be freed automatically on
> driver detach.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>

Acked-by: John Crispin <john@phrozen.org>

> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 1b131a1..9883dac 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1506,8 +1506,6 @@ static void mtk_uninit(struct net_device *dev)
>  	phy_disconnect(mac->phy_dev);
>  	mtk_mdio_cleanup(eth);
>  	mtk_irq_disable(eth, ~0);
> -	free_irq(eth->irq[1], dev);
> -	free_irq(eth->irq[2], dev);
>  }
>  
>  static int mtk_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
> 

^ permalink raw reply

* Re: [RESEND PATCH net 01/10] net: ethernet: mediatek: fix fails from TX housekeeping due to incorrect port setup
From: John Crispin @ 2016-08-25 12:19 UTC (permalink / raw)
  To: Sean Wang, davem; +Cc: nbd, netdev, linux-mediatek, keyhaede
In-Reply-To: <1472121901-15629-2-git-send-email-sean.wang@mediatek.com>



On 25/08/2016 12:44, Sean Wang wrote:
> which net device the SKB is complete for depends on the forward port
> on txd4 on the corresponding TX descriptor, but the information isn't
> set up well in case of  SKB fragments that would lead to watchdog timeout
> from the upper layer, so fix it up.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>

Acked-by: John Crispin <john@phrozen.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 1801fd8..6e4a6ca 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -587,14 +587,15 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
>  	dma_addr_t mapped_addr;
>  	unsigned int nr_frags;
>  	int i, n_desc = 1;
> -	u32 txd4 = 0;
> +	u32 txd4 = 0, fport;
>  
>  	itxd = ring->next_free;
>  	if (itxd == ring->last_free)
>  		return -ENOMEM;
>  
>  	/* set the forward port */
> -	txd4 |= (mac->id + 1) << TX_DMA_FPORT_SHIFT;
> +	fport = (mac->id + 1) << TX_DMA_FPORT_SHIFT;
> +	txd4 |= fport;
>  
>  	tx_buf = mtk_desc_to_tx_buf(ring, itxd);
>  	memset(tx_buf, 0, sizeof(*tx_buf));
> @@ -652,7 +653,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
>  			WRITE_ONCE(txd->txd3, (TX_DMA_SWC |
>  					       TX_DMA_PLEN0(frag_map_size) |
>  					       last_frag * TX_DMA_LS0));
> -			WRITE_ONCE(txd->txd4, 0);
> +			WRITE_ONCE(txd->txd4, fport);
>  
>  			tx_buf->skb = (struct sk_buff *)MTK_DMA_DUMMY_DESC;
>  			tx_buf = mtk_desc_to_tx_buf(ring, txd);
> 

^ permalink raw reply

* Re: [PATCH net-next v3 2/2] net: ethernet: mediatek: modify GDM to send packets to the PDMA for RX
From: John Crispin @ 2016-08-25 12:10 UTC (permalink / raw)
  To: Nelson Chang, davem; +Cc: netdev, nbd, linux-mediatek, nelsonch.tw
In-Reply-To: <1472091991-1814-3-git-send-email-nelson.chang@mediatek.com>



On 25/08/2016 04:26, Nelson Chang wrote:
> Because we change to use the PDMA as the Ethernet RX DMA engine,
> the patch modifies to set GDM to send packets to PDMA for RX.
> 
> Signed-off-by: Nelson Chang <nelson.chang@mediatek.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++--
>  drivers/net/ethernet/mediatek/mtk_eth_soc.h | 0
>  2 files changed, 2 insertions(+), 2 deletions(-)
>  mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_eth_soc.c
>  mode change 100755 => 100644 drivers/net/ethernet/mediatek/mtk_eth_soc.h
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> old mode 100755
> new mode 100644
> index cbeb793..c47fef4
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1473,9 +1473,9 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
>  	for (i = 0; i < 2; i++) {
>  		u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
>  
> -		/* setup the forward port to send frame to QDMA */
> +		/* setup the forward port to send frame to PDMA */
>  		val &= ~0xffff;
> -		val |= 0x5555;
> +		val |= 0x0000;

masking it and then setting it to 0 makes no sense. simply remove the
2nd line.

	John

>  
>  		/* Enable RX checksum */
>  		val |= MTK_GDMA_ICS_EN | MTK_GDMA_TCS_EN | MTK_GDMA_UCS_EN;
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> old mode 100755
> new mode 100644
> 

^ permalink raw reply

* Re: [PATCH net-next v3 1/2] net: ethernet: mediatek: modify to use the PDMA instead of the QDMA for Ethernet RX
From: John Crispin @ 2016-08-25 12:09 UTC (permalink / raw)
  To: Nelson Chang, davem; +Cc: netdev, nbd, linux-mediatek, nelsonch.tw
In-Reply-To: <1472091991-1814-2-git-send-email-nelson.chang@mediatek.com>



On 25/08/2016 04:26, Nelson Chang wrote:
> Because the PDMA has richer features than the QDMA for Ethernet RX
> (such as multiple RX rings, HW LRO, etc.),
> the patch modifies to use the PDMA to handle Ethernet RX.
> 
> Signed-off-by: Nelson Chang <nelson.chang@mediatek.com>

Acked-by: John Crispin <john@phrozen.org>


> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 76 +++++++++++++++++------------
>  drivers/net/ethernet/mediatek/mtk_eth_soc.h | 31 +++++++++++-
>  2 files changed, 74 insertions(+), 33 deletions(-)
>  mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_eth_soc.c
>  mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_eth_soc.h
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> old mode 100644
> new mode 100755
> index 1801fd8..cbeb793
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -342,25 +342,27 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
>  	mdiobus_free(eth->mii_bus);
>  }
>  
> -static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
> +static inline void mtk_irq_disable(struct mtk_eth *eth,
> +				   unsigned reg, u32 mask)
>  {
>  	unsigned long flags;
>  	u32 val;
>  
>  	spin_lock_irqsave(&eth->irq_lock, flags);
> -	val = mtk_r32(eth, MTK_QDMA_INT_MASK);
> -	mtk_w32(eth, val & ~mask, MTK_QDMA_INT_MASK);
> +	val = mtk_r32(eth, reg);
> +	mtk_w32(eth, val & ~mask, reg);
>  	spin_unlock_irqrestore(&eth->irq_lock, flags);
>  }
>  
> -static inline void mtk_irq_enable(struct mtk_eth *eth, u32 mask)
> +static inline void mtk_irq_enable(struct mtk_eth *eth,
> +				  unsigned reg, u32 mask)
>  {
>  	unsigned long flags;
>  	u32 val;
>  
>  	spin_lock_irqsave(&eth->irq_lock, flags);
> -	val = mtk_r32(eth, MTK_QDMA_INT_MASK);
> -	mtk_w32(eth, val | mask, MTK_QDMA_INT_MASK);
> +	val = mtk_r32(eth, reg);
> +	mtk_w32(eth, val | mask, reg);
>  	spin_unlock_irqrestore(&eth->irq_lock, flags);
>  }
>  
> @@ -897,12 +899,12 @@ release_desc:
>  		 * we continue
>  		 */
>  		wmb();
> -		mtk_w32(eth, ring->calc_idx, MTK_QRX_CRX_IDX0);
> +		mtk_w32(eth, ring->calc_idx, MTK_PRX_CRX_IDX0);
>  		done++;
>  	}
>  
>  	if (done < budget)
> -		mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
> +		mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
>  
>  	return done;
>  }
> @@ -1012,7 +1014,7 @@ static int mtk_napi_tx(struct napi_struct *napi, int budget)
>  		return budget;
>  
>  	napi_complete(napi);
> -	mtk_irq_enable(eth, MTK_TX_DONE_INT);
> +	mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
>  
>  	return tx_done;
>  }
> @@ -1024,12 +1026,12 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
>  	int rx_done = 0;
>  
>  	mtk_handle_status_irq(eth);
> -	mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
> +	mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
>  	rx_done = mtk_poll_rx(napi, budget, eth);
>  
>  	if (unlikely(netif_msg_intr(eth))) {
> -		status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
> -		mask = mtk_r32(eth, MTK_QDMA_INT_MASK);
> +		status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
> +		mask = mtk_r32(eth, MTK_PDMA_INT_MASK);
>  		dev_info(eth->dev,
>  			 "done rx %d, intr 0x%08x/0x%x\n",
>  			 rx_done, status, mask);
> @@ -1038,12 +1040,12 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
>  	if (rx_done == budget)
>  		return budget;
>  
> -	status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
> +	status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
>  	if (status & MTK_RX_DONE_INT)
>  		return budget;
>  
>  	napi_complete(napi);
> -	mtk_irq_enable(eth, MTK_RX_DONE_INT);
> +	mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  
>  	return rx_done;
>  }
> @@ -1092,6 +1094,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
>  	mtk_w32(eth,
>  		ring->phys + ((MTK_DMA_SIZE - 1) * sz),
>  		MTK_QTX_DRX_PTR);
> +	mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES, MTK_QTX_CFG(0));
>  
>  	return 0;
>  
> @@ -1162,11 +1165,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth)
>  	 */
>  	wmb();
>  
> -	mtk_w32(eth, eth->rx_ring.phys, MTK_QRX_BASE_PTR0);
> -	mtk_w32(eth, MTK_DMA_SIZE, MTK_QRX_MAX_CNT0);
> -	mtk_w32(eth, eth->rx_ring.calc_idx, MTK_QRX_CRX_IDX0);
> -	mtk_w32(eth, MTK_PST_DRX_IDX0, MTK_QDMA_RST_IDX);
> -	mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES, MTK_QTX_CFG(0));
> +	mtk_w32(eth, eth->rx_ring.phys, MTK_PRX_BASE_PTR0);
> +	mtk_w32(eth, MTK_DMA_SIZE, MTK_PRX_MAX_CNT0);
> +	mtk_w32(eth, eth->rx_ring.calc_idx, MTK_PRX_CRX_IDX0);
> +	mtk_w32(eth, MTK_PST_DRX_IDX0, MTK_PDMA_RST_IDX);
>  
>  	return 0;
>  }
> @@ -1285,7 +1287,7 @@ static irqreturn_t mtk_handle_irq_rx(int irq, void *_eth)
>  
>  	if (likely(napi_schedule_prep(&eth->rx_napi))) {
>  		__napi_schedule(&eth->rx_napi);
> -		mtk_irq_disable(eth, MTK_RX_DONE_INT);
> +		mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  	}
>  
>  	return IRQ_HANDLED;
> @@ -1297,7 +1299,7 @@ static irqreturn_t mtk_handle_irq_tx(int irq, void *_eth)
>  
>  	if (likely(napi_schedule_prep(&eth->tx_napi))) {
>  		__napi_schedule(&eth->tx_napi);
> -		mtk_irq_disable(eth, MTK_TX_DONE_INT);
> +		mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
>  	}
>  
>  	return IRQ_HANDLED;
> @@ -1308,11 +1310,12 @@ static void mtk_poll_controller(struct net_device *dev)
>  {
>  	struct mtk_mac *mac = netdev_priv(dev);
>  	struct mtk_eth *eth = mac->hw;
> -	u32 int_mask = MTK_TX_DONE_INT | MTK_RX_DONE_INT;
>  
> -	mtk_irq_disable(eth, int_mask);
> +	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
> +	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  	mtk_handle_irq_rx(eth->irq[2], dev);
> -	mtk_irq_enable(eth, int_mask);
> +	mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
> +	mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  }
>  #endif
>  
> @@ -1327,11 +1330,15 @@ static int mtk_start_dma(struct mtk_eth *eth)
>  	}
>  
>  	mtk_w32(eth,
> -		MTK_TX_WB_DDONE | MTK_RX_DMA_EN | MTK_TX_DMA_EN |
> -		MTK_RX_2B_OFFSET | MTK_DMA_SIZE_16DWORDS |
> -		MTK_RX_BT_32DWORDS | MTK_NDP_CO_PRO,
> +		MTK_TX_WB_DDONE | MTK_TX_DMA_EN |
> +		MTK_DMA_SIZE_16DWORDS | MTK_NDP_CO_PRO,
>  		MTK_QDMA_GLO_CFG);
>  
> +	mtk_w32(eth,
> +		MTK_RX_DMA_EN | MTK_RX_2B_OFFSET |
> +		MTK_RX_BT_32DWORDS | MTK_MULTI_EN,
> +		MTK_PDMA_GLO_CFG);
> +
>  	return 0;
>  }
>  
> @@ -1349,7 +1356,8 @@ static int mtk_open(struct net_device *dev)
>  
>  		napi_enable(&eth->tx_napi);
>  		napi_enable(&eth->rx_napi);
> -		mtk_irq_enable(eth, MTK_TX_DONE_INT | MTK_RX_DONE_INT);
> +		mtk_irq_enable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
> +		mtk_irq_enable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  	}
>  	atomic_inc(&eth->dma_refcnt);
>  
> @@ -1394,7 +1402,8 @@ static int mtk_stop(struct net_device *dev)
>  	if (!atomic_dec_and_test(&eth->dma_refcnt))
>  		return 0;
>  
> -	mtk_irq_disable(eth, MTK_TX_DONE_INT | MTK_RX_DONE_INT);
> +	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, MTK_TX_DONE_INT);
> +	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, MTK_RX_DONE_INT);
>  	napi_disable(&eth->tx_napi);
>  	napi_disable(&eth->rx_napi);
>  
> @@ -1448,7 +1457,9 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
>  
>  	/* disable delay and normal interrupt */
>  	mtk_w32(eth, 0, MTK_QDMA_DELAY_INT);
> -	mtk_irq_disable(eth, ~0);
> +	mtk_w32(eth, 0, MTK_PDMA_DELAY_INT);
> +	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
> +	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
>  	mtk_w32(eth, RST_GL_PSE, MTK_RST_GL);
>  	mtk_w32(eth, 0, MTK_RST_GL);
>  
> @@ -1504,7 +1515,8 @@ static void mtk_uninit(struct net_device *dev)
>  
>  	phy_disconnect(mac->phy_dev);
>  	mtk_mdio_cleanup(eth);
> -	mtk_irq_disable(eth, ~0);
> +	mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
> +	mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
>  	free_irq(eth->irq[1], dev);
>  	free_irq(eth->irq[2], dev);
>  }
> @@ -1683,7 +1695,7 @@ static void mtk_get_ethtool_stats(struct net_device *dev,
>  	}
>  
>  	do {
> -		data_src = (u64*)hwstats;
> +		data_src = (u64 *)hwstats;
>  		data_dst = data;
>  		start = u64_stats_fetch_begin_irq(&hwstats->syncp);
>  
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> old mode 100644
> new mode 100755
> index f82e3ac..7c1f3f2
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
> @@ -68,6 +68,32 @@
>  /* Unicast Filter MAC Address Register - High */
>  #define MTK_GDMA_MAC_ADRH(x)	(0x50C + (x * 0x1000))
>  
> +/* PDMA RX Base Pointer Register */
> +#define MTK_PRX_BASE_PTR0	0x900
> +
> +/* PDMA RX Maximum Count Register */
> +#define MTK_PRX_MAX_CNT0	0x904
> +
> +/* PDMA RX CPU Pointer Register */
> +#define MTK_PRX_CRX_IDX0	0x908
> +
> +/* PDMA Global Configuration Register */
> +#define MTK_PDMA_GLO_CFG	0xa04
> +#define MTK_MULTI_EN		BIT(10)
> +
> +/* PDMA Reset Index Register */
> +#define MTK_PDMA_RST_IDX	0xa08
> +#define MTK_PST_DRX_IDX0	BIT(16)
> +
> +/* PDMA Delay Interrupt Register */
> +#define MTK_PDMA_DELAY_INT	0xa0c
> +
> +/* PDMA Interrupt Status Register */
> +#define MTK_PDMA_INT_STATUS	0xa20
> +
> +/* PDMA Interrupt Mask Register */
> +#define MTK_PDMA_INT_MASK	0xa28
> +
>  /* PDMA Interrupt grouping registers */
>  #define MTK_PDMA_INT_GRP1	0xa50
>  #define MTK_PDMA_INT_GRP2	0xa54
> @@ -119,13 +145,16 @@
>  
>  /* QDMA Interrupt Status Register */
>  #define MTK_QMTK_INT_STATUS	0x1A18
> +#define MTK_RX_DONE_INT3	BIT(19)
> +#define MTK_RX_DONE_INT2	BIT(18)
>  #define MTK_RX_DONE_INT1	BIT(17)
>  #define MTK_RX_DONE_INT0	BIT(16)
>  #define MTK_TX_DONE_INT3	BIT(3)
>  #define MTK_TX_DONE_INT2	BIT(2)
>  #define MTK_TX_DONE_INT1	BIT(1)
>  #define MTK_TX_DONE_INT0	BIT(0)
> -#define MTK_RX_DONE_INT		(MTK_RX_DONE_INT0 | MTK_RX_DONE_INT1)
> +#define MTK_RX_DONE_INT		(MTK_RX_DONE_INT0 | MTK_RX_DONE_INT1 | \
> +				 MTK_RX_DONE_INT2 | MTK_RX_DONE_INT3)
>  #define MTK_TX_DONE_INT		(MTK_TX_DONE_INT0 | MTK_TX_DONE_INT1 | \
>  				 MTK_TX_DONE_INT2 | MTK_TX_DONE_INT3)
>  
> 

^ permalink raw reply

* [RESEND PATCH net 10/10] net: ethernet: mediatek: fix error handling inside mtk_mdio_init
From: Sean Wang @ 2016-08-25 10:45 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, keyhaede, Sean Wang
In-Reply-To: <1472121901-15629-1-git-send-email-sean.wang@mediatek.com>

return -ENODEV if no child is found in MDIO bus.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 05d85da..2d547c2 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -300,7 +300,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
 	}
 
 	if (!of_device_is_available(mii_np)) {
-		err = 0;
+		err = -ENODEV;
 		goto err_put_node;
 	}
 
-- 
1.9.1

^ permalink raw reply related

* [RESEND PATCH net 09/10] net: ethernet: mediatek: use devm_mdiobus_alloc instead of mdiobus_alloc inside mtk_mdio_init
From: Sean Wang @ 2016-08-25 10:45 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, keyhaede, Sean Wang
In-Reply-To: <1472121901-15629-1-git-send-email-sean.wang@mediatek.com>

a lot of parts in the driver uses devm_* APIs to gain benefits from the
device resource management, so devm_mdiobus_alloc is also used instead
of mdiobus_alloc to have more elegant code flow.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index e3baa63..05d85da 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -304,7 +304,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
 		goto err_put_node;
 	}
 
-	eth->mii_bus = mdiobus_alloc();
+	eth->mii_bus = devm_mdiobus_alloc(eth->dev);
 	if (!eth->mii_bus) {
 		err = -ENOMEM;
 		goto err_put_node;
@@ -318,18 +318,9 @@ static int mtk_mdio_init(struct mtk_eth *eth)
 
 	snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name);
 	err = of_mdiobus_register(eth->mii_bus, mii_np);
-	if (err)
-		goto err_free_bus;
-	of_node_put(mii_np);
-
-	return 0;
-
-err_free_bus:
-	mdiobus_free(eth->mii_bus);
 
 err_put_node:
 	of_node_put(mii_np);
-	eth->mii_bus = NULL;
 	return err;
 }
 
@@ -339,8 +330,6 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
 		return;
 
 	mdiobus_unregister(eth->mii_bus);
-	of_node_put(eth->mii_bus->dev.of_node);
-	mdiobus_free(eth->mii_bus);
 }
 
 static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
-- 
1.9.1

^ permalink raw reply related

* [RESEND PATCH net 08/10] net: ethernet: mediatek: fix the missing of_node_put() after node is used done inside mtk_mdio_init
From: Sean Wang @ 2016-08-25 10:44 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, keyhaede, Sean Wang
In-Reply-To: <1472121901-15629-1-git-send-email-sean.wang@mediatek.com>

This patch adds the missing of_node_put() after finishing the usage
of of_get_child_by_name.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index c573475..e3baa63 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -320,6 +320,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
 	err = of_mdiobus_register(eth->mii_bus, mii_np);
 	if (err)
 		goto err_free_bus;
+	of_node_put(mii_np);
 
 	return 0;
 
-- 
1.9.1

^ permalink raw reply related

* [RESEND PATCH net 07/10] net: ethernet: mediatek: fix issue of driver removal with interface is up
From: Sean Wang @ 2016-08-25 10:44 UTC (permalink / raw)
  To: john, davem; +Cc: nbd, netdev, linux-mediatek, keyhaede, Sean Wang
In-Reply-To: <1472121901-15629-1-git-send-email-sean.wang@mediatek.com>

1) mtk_stop() must be called to stop for freeing DMA resources
acquired and restoring state changed by mtk_open() when module
removal.

2) group clock disabled related function into mtk_hw_deinit which
could be reused with others functionality such as the whole ethernet
reset that would be posted in the later series of patches.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 0a4c782..c573475 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -1478,6 +1478,16 @@ static int __init mtk_hw_init(struct mtk_eth *eth)
 	return 0;
 }
 
+static int mtk_hw_deinit(struct mtk_eth *eth)
+{
+	clk_disable_unprepare(eth->clk_esw);
+	clk_disable_unprepare(eth->clk_gp1);
+	clk_disable_unprepare(eth->clk_gp2);
+	clk_disable_unprepare(eth->clk_ethif);
+
+	return 0;
+}
+
 static int __init mtk_init(struct net_device *dev)
 {
 	struct mtk_mac *mac = netdev_priv(dev);
@@ -1919,11 +1929,15 @@ err_free_dev:
 static int mtk_remove(struct platform_device *pdev)
 {
 	struct mtk_eth *eth = platform_get_drvdata(pdev);
+	int i;
 
-	clk_disable_unprepare(eth->clk_ethif);
-	clk_disable_unprepare(eth->clk_esw);
-	clk_disable_unprepare(eth->clk_gp1);
-	clk_disable_unprepare(eth->clk_gp2);
+	/* stop all devices to make sure that dma is properly shut down */
+	for (i = 0; i < MTK_MAC_COUNT; i++) {
+		if (!eth->netdev[i])
+			continue;
+		mtk_stop(eth->netdev[i]);
+	}
+	mtk_hw_deinit(eth);
 
 	netif_napi_del(&eth->tx_napi);
 	netif_napi_del(&eth->rx_napi);
-- 
1.9.1

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox