Skip to contentSkip to conversation

lan743x: clean up software_isr function

PATCH Applied Sven Van Asbroeck 2 participants 4 messages Nov 23, 2020 – Nov 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lan743x: clean up software_isr function

From: Sven Van Asbroeck <[email protected]>

For no apparent reason, this function reads the INT_STS register, and checks if the software interrupt bit is set. These things have already been carried out by this function's only caller.

Clean up by removing the redundant code.

---

Tree: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git # f9e425e99b07

To: Bryan Whitehead <[email protected]>
To: Jakub Kicinski <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Microchip Linux Driver Support <[email protected]>
Cc: [email protected]
Cc: [email protected]

 drivers/net/ethernet/microchip/lan743x_main.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +4 -9
index 87b6c59a1e03..bdc80098c240 100644
@@ -140,18 +140,13 @@ static int lan743x_csr_init(struct lan743x_adapter *adapter)
 	return result;
 }
 
-static void lan743x_intr_software_isr(void *context)
+static void lan743x_intr_software_isr(struct lan743x_adapter *adapter)
 {
-	struct lan743x_adapter *adapter = context;
 	struct lan743x_intr *intr = &adapter->intr;
-	u32 int_sts;
 
-	int_sts = lan743x_csr_read(adapter, INT_STS);
-	if (int_sts & INT_BIT_SW_GP_) {
-		/* disable the interrupt to prevent repeated re-triggering */
-		lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
-		intr->software_isr_flag = 1;
-	}
+	/* disable the interrupt to prevent repeated re-triggering */
+	lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
+	intr->software_isr_flag = 1;
 }
 
 static void lan743x_tx_isr(void *context, u32 int_sts, u32 flags)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 lan743x: replace polling loop by wait_event_timeout()

From: Sven Van Asbroeck <[email protected]>

The driver's ISR sends a 'software interrupt' event to the probe() thread using the following method:
- probe(): write 0 to flag, enable s/w interrupt
- probe(): poll on flag, relax using usleep_range()
- ISR : write 1 to flag

Replace with wake_up() / wait_event_timeout(). Besides being easier to get right, this abstraction has better timing and memory consistency properties.

---

To: Bryan Whitehead <[email protected]>
To: Jakub Kicinski <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Microchip Linux Driver Support <[email protected]>
Cc: [email protected]
Cc: [email protected]

 drivers/net/ethernet/microchip/lan743x_main.c | 28 +++++++++----------
 drivers/net/ethernet/microchip/lan743x_main.h |  3 +-
 2 files changed, 15 insertions(+), 16 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +13 -15
index bdc80098c240..96d34b001198 100644
@@ -146,7 +146,8 @@ static void lan743x_intr_software_isr(struct lan743x_adapter *adapter)
 
 	/* disable the interrupt to prevent repeated re-triggering */
 	lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
-	intr->software_isr_flag = 1;
+	intr->software_isr_flag = true;
+	wake_up(&intr->software_isr_wq);
 }
 
 static void lan743x_tx_isr(void *context, u32 int_sts, u32 flags)
@@ -344,27 +345,22 @@ static irqreturn_t lan743x_intr_entry_isr(int irq, void *ptr)
 static int lan743x_intr_test_isr(struct lan743x_adapter *adapter)
 {
 	struct lan743x_intr *intr = &adapter->intr;
-	int result = -ENODEV;
-	int timeout = 10;
+	int ret;
 
-	intr->software_isr_flag = 0;
+	intr->software_isr_flag = false;
 
-	/* enable interrupt */
+	/* enable and activate test interrupt */
 	lan743x_csr_write(adapter, INT_EN_SET, INT_BIT_SW_GP_);
-
-	/* activate interrupt here */
 	lan743x_csr_write(adapter, INT_SET, INT_BIT_SW_GP_);
-	while ((timeout > 0) && (!(intr->software_isr_flag))) {
-		usleep_range(1000, 20000);
-		timeout--;
-	}
 
-	if (intr->software_isr_flag)
-		result = 0;
+	ret = wait_event_timeout(intr->software_isr_wq,
+				 intr->software_isr_flag,
+				 msecs_to_jiffies(200));
 
-	/* disable interrupts */
+	/* disable test interrupt */
 	lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
-	return result;
+
+	return ret > 0 ? 0 : -ENODEV;
 }
 
 static int lan743x_intr_register_isr(struct lan743x_adapter *adapter,
@@ -538,6 +534,8 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter)
 		flags |= LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C;
 	}
 
+	init_waitqueue_head(&intr->software_isr_wq);
+
 	ret = lan743x_intr_register_isr(adapter, 0, flags,
 					INT_BIT_ALL_RX_ | INT_BIT_ALL_TX_ |
 					INT_BIT_ALL_OTHER_,
drivers/net/ethernet/microchip/lan743x_main.h +2 -1
index a536f4a4994d..b92864913e6c 100644
@@ -616,7 +616,8 @@ struct lan743x_intr {
 	int			number_of_vectors;
 	bool			using_vectors;
 
-	int			software_isr_flag;
+	bool			software_isr_flag;
+	wait_queue_head_t	software_isr_wq;
 };
 
 #define LAN743X_MAX_FRAME_SIZE			(9 * 1024)
Signature · 1 line
2.17.1
maintainer Applied
#2 lore raw
In reply to Sven Van Asbroeck
Quoted 10 lines · On Mon, 23 Nov 2020 14:15:28 -0500 Sven Van Asbroeck wrote:

From: Sven Van Asbroeck <[email protected]>

For no apparent reason, this function reads the INT_STS register, and checks if the software interrupt bit is set. These things have already been carried out by this function's only caller.

Clean up by removing the redundant code.

Applied both, thank you!

#3 lore raw
Quoted 2 lines · Jakub Kicinski

Applied both, thank you!

Thank you Jakub !