Skip to content

Commit 470dfd8

Browse files
Sven Van Asbroeckkuba-moo
authored andcommitted
lan743x: replace polling loop by wait_event_timeout()
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. Tested-by: Sven Van Asbroeck <[email protected]> # lan7430 Signed-off-by: Sven Van Asbroeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c31799b commit 470dfd8

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ static void lan743x_intr_software_isr(struct lan743x_adapter *adapter)
146146

147147
/* disable the interrupt to prevent repeated re-triggering */
148148
lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
149-
intr->software_isr_flag = 1;
149+
intr->software_isr_flag = true;
150+
wake_up(&intr->software_isr_wq);
150151
}
151152

152153
static void lan743x_tx_isr(void *context, u32 int_sts, u32 flags)
@@ -343,27 +344,22 @@ static irqreturn_t lan743x_intr_entry_isr(int irq, void *ptr)
343344
static int lan743x_intr_test_isr(struct lan743x_adapter *adapter)
344345
{
345346
struct lan743x_intr *intr = &adapter->intr;
346-
int result = -ENODEV;
347-
int timeout = 10;
347+
int ret;
348348

349-
intr->software_isr_flag = 0;
349+
intr->software_isr_flag = false;
350350

351-
/* enable interrupt */
351+
/* enable and activate test interrupt */
352352
lan743x_csr_write(adapter, INT_EN_SET, INT_BIT_SW_GP_);
353-
354-
/* activate interrupt here */
355353
lan743x_csr_write(adapter, INT_SET, INT_BIT_SW_GP_);
356-
while ((timeout > 0) && (!(intr->software_isr_flag))) {
357-
usleep_range(1000, 20000);
358-
timeout--;
359-
}
360354

361-
if (intr->software_isr_flag)
362-
result = 0;
355+
ret = wait_event_timeout(intr->software_isr_wq,
356+
intr->software_isr_flag,
357+
msecs_to_jiffies(200));
363358

364-
/* disable interrupts */
359+
/* disable test interrupt */
365360
lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_);
366-
return result;
361+
362+
return ret > 0 ? 0 : -ENODEV;
367363
}
368364

369365
static int lan743x_intr_register_isr(struct lan743x_adapter *adapter,
@@ -537,6 +533,8 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter)
537533
flags |= LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C;
538534
}
539535

536+
init_waitqueue_head(&intr->software_isr_wq);
537+
540538
ret = lan743x_intr_register_isr(adapter, 0, flags,
541539
INT_BIT_ALL_RX_ | INT_BIT_ALL_TX_ |
542540
INT_BIT_ALL_OTHER_,

drivers/net/ethernet/microchip/lan743x_main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ struct lan743x_intr {
616616
int number_of_vectors;
617617
bool using_vectors;
618618

619-
int software_isr_flag;
619+
bool software_isr_flag;
620+
wait_queue_head_t software_isr_wq;
620621
};
621622

622623
#define LAN743X_MAX_FRAME_SIZE (9 * 1024)

0 commit comments

Comments
 (0)