r8152: check RTL8152_UNPLUG

When the device is unplugged, the driver would try to disable the
device. Add checking the flag of RTL8152_UNPLUG to skip setting
the device when it is unplugged. This could shorten the time of
unloading the driver.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by hayeswang and committed by David S. Miller 6871438c cec9ae50

+48
+48
drivers/net/usb/r8152.c
··· 929 929 struct r8152 *tp = netdev_priv(netdev); 930 930 int ret; 931 931 932 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 933 + return -ENODEV; 934 + 932 935 if (phy_id != R8152_PHY_ID) 933 936 return -EINVAL; 934 937 ··· 951 948 void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val) 952 949 { 953 950 struct r8152 *tp = netdev_priv(netdev); 951 + 952 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 953 + return; 954 954 955 955 if (phy_id != R8152_PHY_ID) 956 956 return; ··· 1968 1962 1969 1963 static int rtl8152_enable(struct r8152 *tp) 1970 1964 { 1965 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 1966 + return -ENODEV; 1967 + 1971 1968 set_tx_qlen(tp); 1972 1969 rtl_set_eee_plus(tp); 1973 1970 ··· 2003 1994 2004 1995 static int rtl8153_enable(struct r8152 *tp) 2005 1996 { 1997 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 1998 + return -ENODEV; 1999 + 2006 2000 set_tx_qlen(tp); 2007 2001 rtl_set_eee_plus(tp); 2008 2002 r8153_set_rx_agg(tp); ··· 2017 2005 { 2018 2006 u32 ocp_data; 2019 2007 int i; 2008 + 2009 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) { 2010 + rtl_drop_queued_tx(tp); 2011 + return; 2012 + } 2020 2013 2021 2014 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2022 2015 ocp_data &= ~RCR_ACPT_ALL; ··· 2248 2231 { 2249 2232 u32 ocp_data; 2250 2233 int i; 2234 + 2235 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 2236 + return; 2251 2237 2252 2238 ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); 2253 2239 ocp_data &= ~RCR_ACPT_ALL; ··· 2480 2460 u32 ocp_data; 2481 2461 int i; 2482 2462 2463 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 2464 + return; 2465 + 2483 2466 rxdy_gated_en(tp, true); 2484 2467 r8153_teredo_off(tp); 2485 2468 ··· 2710 2687 2711 2688 static void rtl8152_down(struct r8152 *tp) 2712 2689 { 2690 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) { 2691 + rtl_drop_queued_tx(tp); 2692 + return; 2693 + } 2694 + 2713 2695 r8152_power_cut_en(tp, false); 2714 2696 r8152b_disable_aldps(tp); 2715 2697 r8152b_enter_oob(tp); ··· 2723 2695 2724 2696 static void rtl8153_down(struct r8152 *tp) 2725 2697 { 2698 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) { 2699 + rtl_drop_queued_tx(tp); 2700 + return; 2701 + } 2702 + 2726 2703 r8153_u1u2en(tp, false); 2727 2704 r8153_power_cut_en(tp, false); 2728 2705 r8153_disable_aldps(tp); ··· 2937 2904 { 2938 2905 u32 ocp_data; 2939 2906 2907 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 2908 + return; 2909 + 2940 2910 if (tp->version == RTL_VER_01) { 2941 2911 ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE); 2942 2912 ocp_data &= ~LED_MODE_MASK; ··· 2974 2938 { 2975 2939 u32 ocp_data; 2976 2940 int i; 2941 + 2942 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 2943 + return; 2977 2944 2978 2945 r8153_u1u2en(tp, false); 2979 2946 ··· 3252 3213 struct mii_ioctl_data *data = if_mii(rq); 3253 3214 int res; 3254 3215 3216 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 3217 + return -ENODEV; 3218 + 3255 3219 res = usb_autopm_get_interface(tp->intf); 3256 3220 if (res < 0) 3257 3221 goto out; ··· 3335 3293 3336 3294 static void rtl8152_unload(struct r8152 *tp) 3337 3295 { 3296 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 3297 + return; 3298 + 3338 3299 if (tp->version != RTL_VER_01) 3339 3300 r8152_power_cut_en(tp, true); 3340 3301 } 3341 3302 3342 3303 static void rtl8153_unload(struct r8152 *tp) 3343 3304 { 3305 + if (test_bit(RTL8152_UNPLUG, &tp->flags)) 3306 + return; 3307 + 3344 3308 r8153_power_cut_en(tp, true); 3345 3309 } 3346 3310