diff mbox

[net,1/2] r8152: add pre_reset and post_reset

Message ID 1394712342-15778-157-Taiwan-albertk@realtek.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Hayes Wang July 28, 2015, 7:36 a.m. UTC
Add rtl8152_pre_reset() and rtl8152_post_reset() which are used when
calling usb_reset_device(). The two functions could reduce the time
of reset when calling usb_reset_device() after probe().

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

Comments

Oliver Neukum July 28, 2015, 8:52 a.m. UTC | #1
On Tue, 2015-07-28 at 15:36 +0800, Hayes Wang wrote:
> Add rtl8152_pre_reset() and rtl8152_post_reset() which are used when
> calling usb_reset_device(). The two functions could reduce the time
> of reset when calling usb_reset_device() after probe().
> 
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>
> ---
>  drivers/net/usb/r8152.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 68 insertions(+)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 144dc64..a6caa60 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -3342,6 +3342,72 @@ static void r8153_init(struct r8152 *tp)
>  	r8153_u2p3en(tp, true);
>  }
>  
> +static int rtl8152_pre_reset(struct usb_interface *intf)
> +{
> +	struct r8152 *tp = usb_get_intfdata(intf);
> +	struct net_device *netdev;
> +	int ret;
> +
> +	if (intf->condition != USB_INTERFACE_BOUND || !tp)

If the interface weren't bound, you wouldn't be called.

> +		return 0;
> +
> +	netdev = tp->netdev;
> +	if (!netif_running(netdev))
> +		return 0;
> +
> +	ret = usb_autopm_get_interface(intf);
> +	if (ret < 0)
> +		return ret;

What sense does this make?

> +
> +	napi_disable(&tp->napi);
> +	clear_bit(WORK_ENABLE, &tp->flags);
> +	usb_kill_urb(tp->intr_urb);
> +	cancel_delayed_work_sync(&tp->schedule);
> +	if (netif_carrier_ok(netdev)) {
> +		netif_stop_queue(netdev);
> +		mutex_lock(&tp->control);
> +		tp->rtl_ops.disable(tp);
> +		mutex_unlock(&tp->control);
> +	}
> +
> +	usb_autopm_put_interface(intf);
> +
> +	return 0;
> +}
> +
> +static int rtl8152_post_reset(struct usb_interface *intf)
> +{
> +	struct r8152 *tp = usb_get_intfdata(intf);
> +	struct net_device *netdev;
> +	int ret;
> +
> +	if (intf->condition != USB_INTERFACE_BOUND || !tp)

Again unnecessary

> +		return 0;
> +
> +	netdev = tp->netdev;
> +	if (!netif_running(netdev))
> +		return 0;
> +
> +	ret = usb_autopm_get_interface(intf);

The device will be awake.

> +	if (ret < 0)
> +		return ret;
> +
> +	set_bit(WORK_ENABLE, &tp->flags);
> +	if (netif_carrier_ok(netdev)) {
> +		mutex_lock(&tp->control);
> +		tp->rtl_ops.enable(tp);
> +		rtl8152_set_rx_mode(netdev);
> +		mutex_unlock(&tp->control);
> +		netif_wake_queue(netdev);
> +	}
> +
> +	napi_enable(&tp->napi);
> +
> +	usb_autopm_put_interface(intf);
> +
> +	return ret;
> +}
> +

	HTH
		Oliver


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hayes Wang July 28, 2015, 9:52 a.m. UTC | #2
Oliver Neukum [mailto:oneukum@suse.com]
> Sent: Tuesday, July 28, 2015 4:53 PM

[...]
> > +		return 0;

> > +

> > +	netdev = tp->netdev;

> > +	if (!netif_running(netdev))

> > +		return 0;

> > +

> > +	ret = usb_autopm_get_interface(intf);

> > +	if (ret < 0)

> > +		return ret;

> 

> What sense does this make?

> 

[...]
> > +		return 0;

> > +

> > +	netdev = tp->netdev;

> > +	if (!netif_running(netdev))

> > +		return 0;

> > +

> > +	ret = usb_autopm_get_interface(intf);

> 

> The device will be awake.


I don't sure if the device would be in runtimesuspend, so I wake it up by myself.
I think you mean I don't have to do this. I would remove them and resend the
patch. Thanks.

Best Regards,
Hayes
Oliver Neukum July 28, 2015, 12:05 p.m. UTC | #3
On Tue, 2015-07-28 at 09:52 +0000, Hayes Wang wrote:
> Oliver Neukum [mailto:oneukum@suse.com]
> > Sent: Tuesday, July 28, 2015 4:53 PM
> [...]
> > > +		return 0;
> > > +
> > > +	netdev = tp->netdev;
> > > +	if (!netif_running(netdev))
> > > +		return 0;
> > > +
> > > +	ret = usb_autopm_get_interface(intf);
> > > +	if (ret < 0)
> > > +		return ret;
> > 
> > What sense does this make?
> > 
> [...]
> > > +		return 0;
> > > +
> > > +	netdev = tp->netdev;
> > > +	if (!netif_running(netdev))
> > > +		return 0;
> > > +
> > > +	ret = usb_autopm_get_interface(intf);
> > 
> > The device will be awake.
> 
> I don't sure if the device would be in runtimesuspend, so I wake it up by myself.
> I think you mean I don't have to do this. I would remove them and resend the
> patch. Thanks.

Usbcore will resume the device.

	HTH
		Oliver

     A. 
        /* Prevent autosuspend during the reset */
        usb_autoresume_device(udev);

        if (config) {
                for (i = 0; i < config->desc.bNumInterfaces; ++i) {
                        struct usb_interface *cintf = config->interface[i];
                        struct usb_driver *drv;
                        int unbind = 0;

                        if (cintf->dev.driver) {
                                drv = to_usb_driver(cintf->dev.driver);
                                if (drv->pre_reset && drv->post_reset)
                                        unbind = (drv->pre_reset)(cintf);




--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 144dc64..a6caa60 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -3342,6 +3342,72 @@  static void r8153_init(struct r8152 *tp)
 	r8153_u2p3en(tp, true);
 }
 
+static int rtl8152_pre_reset(struct usb_interface *intf)
+{
+	struct r8152 *tp = usb_get_intfdata(intf);
+	struct net_device *netdev;
+	int ret;
+
+	if (intf->condition != USB_INTERFACE_BOUND || !tp)
+		return 0;
+
+	netdev = tp->netdev;
+	if (!netif_running(netdev))
+		return 0;
+
+	ret = usb_autopm_get_interface(intf);
+	if (ret < 0)
+		return ret;
+
+	napi_disable(&tp->napi);
+	clear_bit(WORK_ENABLE, &tp->flags);
+	usb_kill_urb(tp->intr_urb);
+	cancel_delayed_work_sync(&tp->schedule);
+	if (netif_carrier_ok(netdev)) {
+		netif_stop_queue(netdev);
+		mutex_lock(&tp->control);
+		tp->rtl_ops.disable(tp);
+		mutex_unlock(&tp->control);
+	}
+
+	usb_autopm_put_interface(intf);
+
+	return 0;
+}
+
+static int rtl8152_post_reset(struct usb_interface *intf)
+{
+	struct r8152 *tp = usb_get_intfdata(intf);
+	struct net_device *netdev;
+	int ret;
+
+	if (intf->condition != USB_INTERFACE_BOUND || !tp)
+		return 0;
+
+	netdev = tp->netdev;
+	if (!netif_running(netdev))
+		return 0;
+
+	ret = usb_autopm_get_interface(intf);
+	if (ret < 0)
+		return ret;
+
+	set_bit(WORK_ENABLE, &tp->flags);
+	if (netif_carrier_ok(netdev)) {
+		mutex_lock(&tp->control);
+		tp->rtl_ops.enable(tp);
+		rtl8152_set_rx_mode(netdev);
+		mutex_unlock(&tp->control);
+		netif_wake_queue(netdev);
+	}
+
+	napi_enable(&tp->napi);
+
+	usb_autopm_put_interface(intf);
+
+	return ret;
+}
+
 static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
 {
 	struct r8152 *tp = usb_get_intfdata(intf);
@@ -4164,6 +4230,8 @@  static struct usb_driver rtl8152_driver = {
 	.suspend =	rtl8152_suspend,
 	.resume =	rtl8152_resume,
 	.reset_resume =	rtl8152_resume,
+	.pre_reset =	rtl8152_pre_reset,
+	.post_reset =	rtl8152_post_reset,
 	.supports_autosuspend = 1,
 	.disable_hub_initiated_lpm = 1,
 };