Skip to contentSkip to conversation

Fix warning, issue and give some enhancements

PATCH Superseded Sean Wang 2 participants 7 messages Aug 15, 2016

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sean Wang

author
#0 lore raw

v2 cover Fix warning, issue and give some enhancements

This patch set fixes the following warning and issues and gives some enhancements about RX path handling.

v1 -> v2: fix message typos and add coverletter

Sean Wang (5):
net: ethernet: mediatek: add REVMII and fix RMII mode supported by
GMAC
net: ethernet: mediatek: fix flow control settings on GMAC0 is not
being enabled properly
net: ethernet: mediatek: fix runtime warning raised by inconsistent
struct device pointers passed to DMA API
net: ethernet: mediatek: enhance RX path by reducing the frequency of
the memory barrier used
net: ethernet: mediatek: enhance RX path by aggregating more skbs
into NAPI

 drivers/net/ethernet/mediatek/mtk_eth_soc.c |   70 ++++++++++++++++-----------
 1 file changed, 42 insertions(+), 28 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 1/5 net: ethernet: mediatek: add REVMII and fix RMII mode supported by GMAC

The patch adds the supplement for the setup of reverse MII (REVMII) on GMAC, fixes up the incorrect setup of reduced MII (RMII) on GMAC and rearranges the error handling for invalid phy argument.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +12 -3
index 88b04dd..f19b8b9 100644
@@ -245,12 +245,16 @@ static int mtk_phy_connect(struct mtk_mac *mac)
 	case PHY_INTERFACE_MODE_MII:
 		ge_mode = 1;
 		break;
-	case PHY_INTERFACE_MODE_RMII:
+	case PHY_INTERFACE_MODE_REVMII:
 		ge_mode = 2;
 		break;
+	case PHY_INTERFACE_MODE_RMII:
+		if (!mac->id)
+			goto err_phy;
+		ge_mode = 3;
+		break;
 	default:
-		dev_err(eth->dev, "invalid phy_mode\n");
-		return -1;
+		goto err_phy;
 	}
 
 	/* put the gmac into the right mode */
@@ -272,6 +276,11 @@ static int mtk_phy_connect(struct mtk_mac *mac)
 	of_node_put(np);
 
 	return 0;
+
+err_phy:
+	of_node_put(np);
+	dev_err(eth->dev, "invalid phy_mode\n");
+	return -EINVAL;
 }
 
 static int mtk_mdio_init(struct mtk_eth *eth)
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v2 2/5 net: ethernet: mediatek: fix flow control settings on GMAC0 is not being enabled properly

In reply to Sean Wang

Commit 08ef55c6f257acf3bdc6940813f80e8f0f5d90ec ("net-next: mediatek: fix gigabit and flow control advertisement") had supported proper flow control settings for GMAC1. But for GMAC0,

1.GMAC0 shares the common logic with GMAC1 inside mtk_phy_link_adjust() to adapt various settings for the target phy.

2.GMAC0 uses fixed-phy to connect to a builtin gigabit switch with fixed link speed as commit 0c72c50f6f93b0c3daa9ea35d89ab3a933c7b5a0 ("net-next: mediatek: add fixed-phy support") describes.

3.However, fixed-phy doesn't enable SUPPORTED_Pause & SUPPORTED_Asym_Pause supported flag on default that would cause mtk_phy_link_adjust() not to enable flow control setting on GMAC0 properly and cause packet dropped when high traffic.

Due to these reasons, the patch adds SUPPORTED_Pause & SUPPORTED_Asym_Pause supported flags on fixed-phy used by driver to have proper handling on the both GMAC with the shared common logic.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
index f19b8b9..eb59a73 100644
@@ -267,6 +267,11 @@ static int mtk_phy_connect(struct mtk_mac *mac)
 	mac->phy_dev->autoneg = AUTONEG_ENABLE;
 	mac->phy_dev->speed = 0;
 	mac->phy_dev->duplex = 0;
+
+	if (of_phy_is_fixed_link(mac->of_node))
+		mac->phy_dev->supported |=
+		SUPPORTED_Pause | SUPPORTED_Asym_Pause;
+
 	mac->phy_dev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
 				   SUPPORTED_Asym_Pause;
 	mac->phy_dev->advertising = mac->phy_dev->supported |
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH v2 3/5 net: ethernet: mediatek: fix runtime warning raised by inconsistent struct device pointers passed to DMA API

In reply to Sean Wang

Runtime warning occurs if DMA-API debug feature is enabled that would be raised by pointers passed to DMA API as arguments to inconsistent struct device objects, so that the patch makes them usage aligned between dma operations such as dma_map_*() and dma_unmap_*() to eliminate the warning.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +13 -13
index eb59a73..b782330 100644
@@ -557,15 +557,15 @@ static inline struct mtk_tx_buf *mtk_desc_to_tx_buf(struct mtk_tx_ring *ring,
 	return &ring->buf[idx];
 }
 
-static void mtk_tx_unmap(struct device *dev, struct mtk_tx_buf *tx_buf)
+static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf)
 {
 	if (tx_buf->flags & MTK_TX_FLAGS_SINGLE0) {
-		dma_unmap_single(dev,
+		dma_unmap_single(eth->dev,
 				 dma_unmap_addr(tx_buf, dma_addr0),
 				 dma_unmap_len(tx_buf, dma_len0),
 				 DMA_TO_DEVICE);
 	} else if (tx_buf->flags & MTK_TX_FLAGS_PAGE0) {
-		dma_unmap_page(dev,
+		dma_unmap_page(eth->dev,
 			       dma_unmap_addr(tx_buf, dma_addr0),
 			       dma_unmap_len(tx_buf, dma_len0),
 			       DMA_TO_DEVICE);
@@ -610,9 +610,9 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
 	if (skb_vlan_tag_present(skb))
 		txd4 |= TX_DMA_INS_VLAN | skb_vlan_tag_get(skb);
 
-	mapped_addr = dma_map_single(&dev->dev, skb->data,
+	mapped_addr = dma_map_single(eth->dev, skb->data,
 				     skb_headlen(skb), DMA_TO_DEVICE);
-	if (unlikely(dma_mapping_error(&dev->dev, mapped_addr)))
+	if (unlikely(dma_mapping_error(eth->dev, mapped_addr)))
 		return -ENOMEM;
 
 	WRITE_ONCE(itxd->txd1, mapped_addr);
@@ -638,10 +638,10 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
 
 			n_desc++;
 			frag_map_size = min(frag_size, MTK_TX_DMA_BUF_LEN);
-			mapped_addr = skb_frag_dma_map(&dev->dev, frag, offset,
+			mapped_addr = skb_frag_dma_map(eth->dev, frag, offset,
 						       frag_map_size,
 						       DMA_TO_DEVICE);
-			if (unlikely(dma_mapping_error(&dev->dev, mapped_addr)))
+			if (unlikely(dma_mapping_error(eth->dev, mapped_addr)))
 				goto err_dma;
 
 			if (i == nr_frags - 1 &&
@@ -694,7 +694,7 @@ err_dma:
 		tx_buf = mtk_desc_to_tx_buf(ring, itxd);
 
 		/* unmap dma */
-		mtk_tx_unmap(&dev->dev, tx_buf);
+		mtk_tx_unmap(eth, tx_buf);
 
 		itxd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
 		itxd = mtk_qdma_phys_to_virt(ring, itxd->txd2);
@@ -850,11 +850,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 			netdev->stats.rx_dropped++;
 			goto release_desc;
 		}
-		dma_addr = dma_map_single(&eth->netdev[mac]->dev,
+		dma_addr = dma_map_single(eth->dev,
 					  new_data + NET_SKB_PAD,
 					  ring->buf_size,
 					  DMA_FROM_DEVICE);
-		if (unlikely(dma_mapping_error(&netdev->dev, dma_addr))) {
+		if (unlikely(dma_mapping_error(eth->dev, dma_addr))) {
 			skb_free_frag(new_data);
 			netdev->stats.rx_dropped++;
 			goto release_desc;
@@ -869,7 +869,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 		}
 		skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
 
-		dma_unmap_single(&netdev->dev, trxd.rxd1,
+		dma_unmap_single(eth->dev, trxd.rxd1,
 				 ring->buf_size, DMA_FROM_DEVICE);
 		pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
 		skb->dev = netdev;
@@ -951,7 +951,7 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget)
 			done[mac]++;
 			budget--;
 		}
-		mtk_tx_unmap(eth->dev, tx_buf);
+		mtk_tx_unmap(eth, tx_buf);
 
 		ring->last_free = desc;
 		atomic_inc(&ring->free_count);
@@ -1106,7 +1106,7 @@ static void mtk_tx_clean(struct mtk_eth *eth)
 
 	if (ring->buf) {
 		for (i = 0; i < MTK_DMA_SIZE; i++)
-			mtk_tx_unmap(eth->dev, &ring->buf[i]);
+			mtk_tx_unmap(eth, &ring->buf[i]);
 		kfree(ring->buf);
 		ring->buf = NULL;
 	}
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH v2 4/5 net: ethernet: mediatek: enhance RX path by reducing the frequency of the memory barrier used

In reply to Sean Wang

The patch makes moving wmb() to outside the loop that could help RX path handling more faster although that RX descriptors aren't freed for DMA to use as soon as possible, but based on my experiment and the result show it still can reach about 943Mbpis without performance drop that is tested based on the setup with one port using gigaphy and 256 RX descriptors for DMA to move.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +6 -5
index b782330..53e24c1 100644
@@ -893,14 +893,15 @@ release_desc:
 		rxd->rxd2 = RX_DMA_PLEN0(ring->buf_size);
 
 		ring->calc_idx = idx;
-		/* make sure that all changes to the dma ring are flushed before
-		 * we continue
-		 */
-		wmb();
-		mtk_w32(eth, ring->calc_idx, MTK_QRX_CRX_IDX0);
 		done++;
 	}
 
+    /* make sure that all changes to the dma ring are flushed before
+     * we continue
+     */
+	wmb();
+	mtk_w32(eth, ring->calc_idx, MTK_QRX_CRX_IDX0);
+
 	if (done < budget)
 		mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
 
Signature · 1 line
1.7.9.5
author
#5 lore raw

PATCH v2 5/5 net: ethernet: mediatek: enhance RX path by aggregating more skbs into NAPI

In reply to Sean Wang

The patch adds support for aggregating more skbs feed into NAPI in order to get more benifits from generic receive offload (GRO) by peeking at the RX ring status and moving more packets right before returning from NAPI RX polling handler if NAPI budgets are still available.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +7 -8
index 53e24c1..742b9ec 100644
@@ -902,9 +902,6 @@ release_desc:
 	wmb();
 	mtk_w32(eth, ring->calc_idx, MTK_QRX_CRX_IDX0);
 
-	if (done < budget)
-		mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
-
 	return done;
 }
 
@@ -1023,8 +1020,10 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
 	struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi);
 	u32 status, mask;
 	int rx_done = 0;
+	int remain_budget = budget;
 
 	mtk_handle_status_irq(eth);
+poll_again:
 	mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
 	rx_done = mtk_poll_rx(napi, budget, eth);
 
@@ -1035,14 +1034,14 @@ static int mtk_napi_rx(struct napi_struct *napi, int budget)
 			 "done rx %d, intr 0x%08x/0x%x\n",
 			 rx_done, status, mask);
 	}
-
-	if (rx_done == budget)
+	if (rx_done == remain_budget)
 		return budget;
 
 	status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
-	if (status & MTK_RX_DONE_INT)
-		return budget;
-
+	if (status & MTK_RX_DONE_INT) {
+		remain_budget -= rx_done;
+		goto poll_again;
+	}
 	napi_complete(napi);
 	mtk_irq_enable(eth, MTK_RX_DONE_INT);
 
Signature · 1 line
1.7.9.5
maintainer
#6 lore raw
In reply to Sean Wang

From: Sean Wang <[email protected]>
Date: Tue, 16 Aug 2016 01:51:21 +0800

Quoted 4 lines

This patch set fixes the following warning and issues and gives some enhancements about RX path handling.

v1 -> v2: fix message typos and add coverletter

Please do not mix bug fixes and changes which are not bug fixes.

Submit bug fixes as a series targetting 'net'.

Submit the rest targetting 'net-next'.

Thanks.