Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <thesven73@gmail.com> # lan7430
Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
Link: https://lore.kernel.org/r/20201123191529.14908-2-TheSven73@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sven Van Asbroeck and committed by
Jakub Kicinski
470dfd80 c31799ba

+15 -16
+13 -15
drivers/net/ethernet/microchip/lan743x_main.c
··· 146 146 147 147 /* disable the interrupt to prevent repeated re-triggering */ 148 148 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); 150 151 } 151 152 152 153 static void lan743x_tx_isr(void *context, u32 int_sts, u32 flags) ··· 344 343 static int lan743x_intr_test_isr(struct lan743x_adapter *adapter) 345 344 { 346 345 struct lan743x_intr *intr = &adapter->intr; 347 - int result = -ENODEV; 348 - int timeout = 10; 346 + int ret; 349 347 350 - intr->software_isr_flag = 0; 348 + intr->software_isr_flag = false; 351 349 352 - /* enable interrupt */ 350 + /* enable and activate test interrupt */ 353 351 lan743x_csr_write(adapter, INT_EN_SET, INT_BIT_SW_GP_); 354 - 355 - /* activate interrupt here */ 356 352 lan743x_csr_write(adapter, INT_SET, INT_BIT_SW_GP_); 357 - while ((timeout > 0) && (!(intr->software_isr_flag))) { 358 - usleep_range(1000, 20000); 359 - timeout--; 360 - } 361 353 362 - if (intr->software_isr_flag) 363 - result = 0; 354 + ret = wait_event_timeout(intr->software_isr_wq, 355 + intr->software_isr_flag, 356 + msecs_to_jiffies(200)); 364 357 365 - /* disable interrupts */ 358 + /* disable test interrupt */ 366 359 lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_SW_GP_); 367 - return result; 360 + 361 + return ret > 0 ? 0 : -ENODEV; 368 362 } 369 363 370 364 static int lan743x_intr_register_isr(struct lan743x_adapter *adapter, ··· 532 536 flags |= LAN743X_VECTOR_FLAG_SOURCE_STATUS_R2C; 533 537 flags |= LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C; 534 538 } 539 + 540 + init_waitqueue_head(&intr->software_isr_wq); 535 541 536 542 ret = lan743x_intr_register_isr(adapter, 0, flags, 537 543 INT_BIT_ALL_RX_ | INT_BIT_ALL_TX_ |
+2 -1
drivers/net/ethernet/microchip/lan743x_main.h
··· 616 616 int number_of_vectors; 617 617 bool using_vectors; 618 618 619 - int software_isr_flag; 619 + bool software_isr_flag; 620 + wait_queue_head_t software_isr_wq; 620 621 }; 621 622 622 623 #define LAN743X_MAX_FRAME_SIZE (9 * 1024)