Skip to content

Commit 7480888

Browse files
committed
Merge branch 'r8152-napi-fixes'
Hayes Wang says: ==================== r8152: fix scheduling napi v3: simply the argument for patch #3. Replace &tp->napi with napi. v2: Add smp_mb__after_atomic() for patch #1. v1: Scheduling the napi during the following periods would let it be ignored. And the events wouldn't be handled until next napi_schedule() is called. 1. after napi_disable and before napi_enable(). 2. after all actions of napi function is completed and before calling napi_complete(). If no next napi_schedule() is called, tx or rx would stop working. In order to avoid these situations, the followings solutions are applied. 1. prevent start_xmit() from calling napi_schedule() during runtime suspend or after napi_disable(). 2. re-schedule the napi for tx if it is necessary. 3. check if any rx is finished or not after napi_enable(). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents f154be2 + 7489bda commit 7480888

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

drivers/net/usb/r8152.c

+24-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define NETNEXT_VERSION "08"
3333

3434
/* Information for net */
35-
#define NET_VERSION "7"
35+
#define NET_VERSION "8"
3636

3737
#define DRIVER_VERSION "v1." NETNEXT_VERSION "." NET_VERSION
3838
#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
@@ -1936,6 +1936,9 @@ static int r8152_poll(struct napi_struct *napi, int budget)
19361936
napi_complete(napi);
19371937
if (!list_empty(&tp->rx_done))
19381938
napi_schedule(napi);
1939+
else if (!skb_queue_empty(&tp->tx_queue) &&
1940+
!list_empty(&tp->tx_free))
1941+
napi_schedule(napi);
19391942
}
19401943

19411944
return work_done;
@@ -3155,17 +3158,21 @@ static void set_carrier(struct r8152 *tp)
31553158
if (!netif_carrier_ok(netdev)) {
31563159
tp->rtl_ops.enable(tp);
31573160
set_bit(RTL8152_SET_RX_MODE, &tp->flags);
3161+
netif_stop_queue(netdev);
31583162
napi_disable(&tp->napi);
31593163
netif_carrier_on(netdev);
31603164
rtl_start_rx(tp);
31613165
napi_enable(&tp->napi);
3166+
netif_wake_queue(netdev);
3167+
netif_info(tp, link, netdev, "carrier on\n");
31623168
}
31633169
} else {
31643170
if (netif_carrier_ok(netdev)) {
31653171
netif_carrier_off(netdev);
31663172
napi_disable(&tp->napi);
31673173
tp->rtl_ops.disable(tp);
31683174
napi_enable(&tp->napi);
3175+
netif_info(tp, link, netdev, "carrier off\n");
31693176
}
31703177
}
31713178
}
@@ -3515,12 +3522,12 @@ static int rtl8152_pre_reset(struct usb_interface *intf)
35153522
if (!netif_running(netdev))
35163523
return 0;
35173524

3525+
netif_stop_queue(netdev);
35183526
napi_disable(&tp->napi);
35193527
clear_bit(WORK_ENABLE, &tp->flags);
35203528
usb_kill_urb(tp->intr_urb);
35213529
cancel_delayed_work_sync(&tp->schedule);
35223530
if (netif_carrier_ok(netdev)) {
3523-
netif_stop_queue(netdev);
35243531
mutex_lock(&tp->control);
35253532
tp->rtl_ops.disable(tp);
35263533
mutex_unlock(&tp->control);
@@ -3548,12 +3555,15 @@ static int rtl8152_post_reset(struct usb_interface *intf)
35483555
rtl_start_rx(tp);
35493556
rtl8152_set_rx_mode(netdev);
35503557
mutex_unlock(&tp->control);
3551-
netif_wake_queue(netdev);
35523558
}
35533559

35543560
napi_enable(&tp->napi);
3561+
netif_wake_queue(netdev);
35553562
usb_submit_urb(tp->intr_urb, GFP_KERNEL);
35563563

3564+
if (!list_empty(&tp->rx_done))
3565+
napi_schedule(&tp->napi);
3566+
35573567
return 0;
35583568
}
35593569

@@ -3585,10 +3595,15 @@ static int rtl8152_rumtime_suspend(struct r8152 *tp)
35853595
struct net_device *netdev = tp->netdev;
35863596
int ret = 0;
35873597

3598+
set_bit(SELECTIVE_SUSPEND, &tp->flags);
3599+
smp_mb__after_atomic();
3600+
35883601
if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
35893602
u32 rcr = 0;
35903603

35913604
if (delay_autosuspend(tp)) {
3605+
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
3606+
smp_mb__after_atomic();
35923607
ret = -EBUSY;
35933608
goto out1;
35943609
}
@@ -3605,6 +3620,8 @@ static int rtl8152_rumtime_suspend(struct r8152 *tp)
36053620
if (!(ocp_data & RXFIFO_EMPTY)) {
36063621
rxdy_gated_en(tp, false);
36073622
ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr);
3623+
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
3624+
smp_mb__after_atomic();
36083625
ret = -EBUSY;
36093626
goto out1;
36103627
}
@@ -3624,8 +3641,6 @@ static int rtl8152_rumtime_suspend(struct r8152 *tp)
36243641
}
36253642
}
36263643

3627-
set_bit(SELECTIVE_SUSPEND, &tp->flags);
3628-
36293644
out1:
36303645
return ret;
36313646
}
@@ -3681,12 +3696,15 @@ static int rtl8152_resume(struct usb_interface *intf)
36813696
if (netif_running(tp->netdev) && tp->netdev->flags & IFF_UP) {
36823697
if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
36833698
tp->rtl_ops.autosuspend_en(tp, false);
3684-
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
36853699
napi_disable(&tp->napi);
36863700
set_bit(WORK_ENABLE, &tp->flags);
36873701
if (netif_carrier_ok(tp->netdev))
36883702
rtl_start_rx(tp);
36893703
napi_enable(&tp->napi);
3704+
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
3705+
smp_mb__after_atomic();
3706+
if (!list_empty(&tp->rx_done))
3707+
napi_schedule(&tp->napi);
36903708
} else {
36913709
tp->rtl_ops.up(tp);
36923710
netif_carrier_off(tp->netdev);

0 commit comments

Comments
 (0)