Skip to contentSkip to conversation

net: stmmac: Fix HW timestamping

PATCH In review Jose Abreu 2 participants 5 messages Oct 20, 2017 – Oct 22, 2017

Subsystems (4)
lore
Share & tools
lore

Jose Abreu

author
#0 lore raw

cover net: stmmac: Fix HW timestamping

Hi,

Three fixes for HW timestamping feature, all of them for RX side.

Best regards,
Jose Miguel Abreu

David,

I'm targeting this for -next but teel free to apply this in your -fixes tree if you think its needed. Though, I don't think anyone is using HW timestamping because these bugs would appear immediatly.

Cc David S. Miller <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>

Jose Abreu (3):
net: stmmac: Add missing call to dev_kfree_skb()
net: stmmac: Fix stmmac_get_rx_hwtstamp()
net: stmmac: Prevent infinite loop in get_rx_timestamp_status()

 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/3 net: stmmac: Add missing call to dev_kfree_skb()

When RX HW timestamp is enabled and a frame is discarded we are not freeing the skb but instead only setting to NULL the entry.

Add a call to dev_kfree_skb_any() so that skb entry is correctly freed.

Cc David S. Miller <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
index 0e1b0a3..f7b7906 100644
@@ -3358,6 +3358,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
 				 * them in stmmac_rx_refill() function so that
 				 * device can reuse it.
 				 */
+				dev_kfree_skb_any(rx_q->rx_skbuff[entry]);
 				rx_q->rx_skbuff[entry] = NULL;
 				dma_unmap_single(priv->device,
 						 rx_q->rx_skbuff_dma[entry],
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH 2/3 net: stmmac: Fix stmmac_get_rx_hwtstamp()

In reply to Jose Abreu

When using GMAC4 the valid timestamp is from CTX next desc but we are passing the previous desc to get_rx_timestamp_status() callback.

Fix this and while at it rework a little bit the function logic.

Cc David S. Miller <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +6 -7
index f7b7906..0d3fd3b 100644
@@ -473,19 +473,18 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
 				   struct dma_desc *np, struct sk_buff *skb)
 {
 	struct skb_shared_hwtstamps *shhwtstamp = NULL;
+	struct dma_desc *desc = p;
 	u64 ns;
 
 	if (!priv->hwts_rx_en)
 		return;
+	/* For GMAC4, the valid timestamp is from CTX next desc. */
+	if (priv->plat->has_gmac4)
+		desc = np;
 
 	/* Check if timestamp is available */
-	if (priv->hw->desc->get_rx_timestamp_status(p, priv->adv_ts)) {
-		/* For GMAC4, the valid timestamp is from CTX next desc. */
-		if (priv->plat->has_gmac4)
-			ns = priv->hw->desc->get_timestamp(np, priv->adv_ts);
-		else
-			ns = priv->hw->desc->get_timestamp(p, priv->adv_ts);
-
+	if (priv->hw->desc->get_rx_timestamp_status(desc, priv->adv_ts)) {
+		ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts);
 		netdev_dbg(priv->dev, "get valid RX hw timestamp %llu\n", ns);
 		shhwtstamp = skb_hwtstamps(skb);
 		memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
Signature · 1 line
1.9.1
author
#3 lore raw

PATCH 3/3 net: stmmac: Prevent infinite loop in get_rx_timestamp_status()

In reply to Jose Abreu

Prevent infinite loop by correctly setting the loop condition to break when i == 10.

Cc David S. Miller <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +1 -1
index e0ef02f..4b286e2 100644
@@ -275,7 +275,7 @@ static int dwmac4_wrback_get_rx_timestamp_status(void *desc, u32 ats)
 					goto exit;
 				i++;
 
-			} while ((ret == 1) || (i < 10));
+			} while ((ret == 1) && (i < 10));
 
 			if (i == 10)
 				ret = -EBUSY;
Signature · 1 line
1.9.1