Patch "fpga: microchip-spi: rewrite status polling in a time measurable way" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    fpga: microchip-spi: rewrite status polling in a time measurable way

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     fpga-microchip-spi-rewrite-status-polling-in-a-time-.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 245c2844cacdf51d69c0024936fdf334988e378b
Author: Ivan Bornyakov <i.bornyakov@xxxxxxxxxxx>
Date:   Fri Dec 30 12:29:21 2022 +0300

    fpga: microchip-spi: rewrite status polling in a time measurable way
    
    [ Upstream commit 88e705697e801299a13ecaf2ba54599964fe711c ]
    
    Original busy loop with retries count in mpf_poll_status() is not too
    reliable, as it takes different times on different systems. Replace it
    with read_poll_timeout() macro.
    
    While at it, fix polling stop condition to met function's original
    intention declared in the comment. The issue with original polling stop
    condition is that it stops if any of mask bits is set, while intention
    was to stop if all mask bits is set. This was not noticible because only
    MPF_STATUS_READY is passed as mask argument and it is BIT(1).
    
    Fixes: 5f8d4a900830 ("fpga: microchip-spi: add Microchip MPF FPGA manager")
    Signed-off-by: Ivan Bornyakov <i.bornyakov@xxxxxxxxxxx>
    Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
    Acked-by: Conor Dooley <conor.dooley@xxxxxxxxxxxxx>
    Acked-by: Xu Yilun <yilun.xu@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20221230092922.18822-3-i.bornyakov@xxxxxxxxxxx
    Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c
index bb69f5beefe78..137fafdf57a6f 100644
--- a/drivers/fpga/microchip-spi.c
+++ b/drivers/fpga/microchip-spi.c
@@ -6,6 +6,7 @@
 #include <asm/unaligned.h>
 #include <linux/delay.h>
 #include <linux/fpga/fpga-mgr.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/spi/spi.h>
@@ -33,7 +34,7 @@
 
 #define	MPF_BITS_PER_COMPONENT_SIZE	22
 
-#define	MPF_STATUS_POLL_RETRIES		10000
+#define	MPF_STATUS_POLL_TIMEOUT		(2 * USEC_PER_SEC)
 #define	MPF_STATUS_BUSY			BIT(0)
 #define	MPF_STATUS_READY		BIT(1)
 #define	MPF_STATUS_SPI_VIOLATION	BIT(2)
@@ -194,24 +195,25 @@ static int mpf_ops_parse_header(struct fpga_manager *mgr,
 	return 0;
 }
 
-/* Poll HW status until busy bit is cleared and mask bits are set. */
 static int mpf_poll_status(struct mpf_priv *priv, u8 mask)
 {
-	int status, retries = MPF_STATUS_POLL_RETRIES;
+	int ret, status;
 
-	while (retries--) {
-		status = mpf_read_status(priv);
-		if (status < 0)
-			return status;
-
-		if (status & MPF_STATUS_BUSY)
-			continue;
-
-		if (!mask || (status & mask))
-			return status;
-	}
+	/*
+	 * Busy poll HW status. Polling stops if any of the following
+	 * conditions are met:
+	 *  - timeout is reached
+	 *  - mpf_read_status() returns an error
+	 *  - busy bit is cleared AND mask bits are set
+	 */
+	ret = read_poll_timeout(mpf_read_status, status,
+				(status < 0) ||
+				((status & (MPF_STATUS_BUSY | mask)) == mask),
+				0, MPF_STATUS_POLL_TIMEOUT, false, priv);
+	if (ret < 0)
+		return ret;
 
-	return -EBUSY;
+	return status;
 }
 
 static int mpf_spi_write(struct mpf_priv *priv, const void *buf, size_t buf_size)



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux