1 From c5d66587b8900201e1530b7c18d41e87bd5812f4 Mon Sep 17 00:00:00 2001
2 From: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
3 Date: Thu, 15 Apr 2021 17:37:48 -0700
4 Subject: [PATCH] net: ethernet: mediatek: ppe: fix busy wait loop
6 The intention is for the loop to timeout if the body does not succeed.
7 The current logic calls time_is_before_jiffies(timeout) which is false
8 until after the timeout, so the loop body never executes.
10 Fix by using readl_poll_timeout as a more standard and less error-prone
13 Fixes: ba37b7caf1ed ("net: ethernet: mtk_eth_soc: add support for initializing the PPE")
14 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
15 Cc: Felix Fietkau <nbd@nbd.name>
16 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
19 drivers/net/ethernet/mediatek/mtk_ppe.c | 20 +++++++++-----------
20 drivers/net/ethernet/mediatek/mtk_ppe.h | 1 +
21 2 files changed, 10 insertions(+), 11 deletions(-)
23 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
24 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
26 /* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
28 #include <linux/kernel.h>
29 -#include <linux/jiffies.h>
30 -#include <linux/delay.h>
32 +#include <linux/iopoll.h>
33 #include <linux/etherdevice.h>
34 #include <linux/platform_device.h>
36 @@ -44,18 +43,17 @@ static u32 ppe_clear(struct mtk_ppe *ppe
38 static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
40 - unsigned long timeout = jiffies + HZ;
42 - while (time_is_before_jiffies(timeout)) {
43 - if (!(ppe_r32(ppe, MTK_PPE_GLO_CFG) & MTK_PPE_GLO_CFG_BUSY))
48 - usleep_range(10, 20);
50 + ret = readl_poll_timeout(ppe->base + MTK_PPE_GLO_CFG, val,
51 + !(val & MTK_PPE_GLO_CFG_BUSY),
52 + 20, MTK_PPE_WAIT_TIMEOUT_US);
54 - dev_err(ppe->dev, "PPE table busy");
56 + dev_err(ppe->dev, "PPE table busy");
62 static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
63 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
64 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
66 #define MTK_PPE_ENTRIES_SHIFT 3
67 #define MTK_PPE_ENTRIES (1024 << MTK_PPE_ENTRIES_SHIFT)
68 #define MTK_PPE_HASH_MASK (MTK_PPE_ENTRIES - 1)
69 +#define MTK_PPE_WAIT_TIMEOUT_US 1000000
71 #define MTK_FOE_IB1_UNBIND_TIMESTAMP GENMASK(7, 0)
72 #define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(23, 8)