Skip to content

Commit

Permalink
net: ethernet: mediatek: ppe: fix busy wait loop
Browse files Browse the repository at this point in the history
The intention is for the loop to timeout if the body does not succeed.
The current logic calls time_is_before_jiffies(timeout) which is false
until after the timeout, so the loop body never executes.

Fix by using readl_poll_timeout as a more standard and less error-prone
solution.

Fixes: ba37b7c ("net: ethernet: mtk_eth_soc: add support for initializing the PPE")
Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
Cc: Felix Fietkau <nbd@nbd.name>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ilya Lipnitskiy authored and David S. Miller committed Apr 16, 2021
1 parent c133acf commit c5d6658
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 9 additions & 11 deletions drivers/net/ethernet/mediatek/mtk_ppe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */

#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/etherdevice.h>
#include <linux/platform_device.h>
#include "mtk_ppe.h"
Expand Down Expand Up @@ -44,18 +43,17 @@ static u32 ppe_clear(struct mtk_ppe *ppe, u32 reg, u32 val)

static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
{
unsigned long timeout = jiffies + HZ;

while (time_is_before_jiffies(timeout)) {
if (!(ppe_r32(ppe, MTK_PPE_GLO_CFG) & MTK_PPE_GLO_CFG_BUSY))
return 0;
int ret;
u32 val;

usleep_range(10, 20);
}
ret = readl_poll_timeout(ppe->base + MTK_PPE_GLO_CFG, val,
!(val & MTK_PPE_GLO_CFG_BUSY),
20, MTK_PPE_WAIT_TIMEOUT_US);

dev_err(ppe->dev, "PPE table busy");
if (ret)
dev_err(ppe->dev, "PPE table busy");

return -ETIMEDOUT;
return ret;
}

static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mediatek/mtk_ppe.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define MTK_PPE_ENTRIES_SHIFT 3
#define MTK_PPE_ENTRIES (1024 << MTK_PPE_ENTRIES_SHIFT)
#define MTK_PPE_HASH_MASK (MTK_PPE_ENTRIES - 1)
#define MTK_PPE_WAIT_TIMEOUT_US 1000000

#define MTK_FOE_IB1_UNBIND_TIMESTAMP GENMASK(7, 0)
#define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(23, 8)
Expand Down

0 comments on commit c5d6658

Please sign in to comment.