USB Gadget EEM Suspend/Resume

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I was hoping for some input  on how USB Ethernet Gadget drivers should handle USB suspend/resume  events.  We have a case where the USB suspend hook is being called for  an EEM Gadget; but since that hook is currently unimplemented, the interface remains in an active/enabled state.  I have  attached a patch that seems to fix this issue for EEM devices by  calling gether_disconnect() on suspend and gether_connect() on resume;  but I do not if this is actually correct behavior, so I was looking for some advice on that.  It seems that since the gadget driver cannot send data until the USB host resumes the USB link,  that the interface should be considered disconnected.

Thanks,
-Bowe
    
From 7cdc1cebe4092393e1de33f59fd2f1cd4355d494 Mon Sep 17 00:00:00 2001
From: Bowe Neuenschwander <bowe.neuenschwander@xxxxxxxxxx>
Date: Tue, 10 Nov 2020 15:55:51 -0600
Subject: [PATCH 1/2] usb: gadget: eem: Add suspend/resume handling

Add suspend/resume handling to the USB Gadget EEM driver.  On suspend,
disconnect the interface; on resume, attempt to reconnect the interface.

Change-Id: I1c7a2bb1d68a99c774a415b13f6cdabb507ada92
---
 drivers/usb/gadget/function/f_eem.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c
index cad35a502d3f..4fbdbb8ee295 100644
--- a/drivers/usb/gadget/function/f_eem.c
+++ b/drivers/usb/gadget/function/f_eem.c
@@ -238,6 +238,33 @@ static void eem_disable(struct usb_function *f)
 		gether_disconnect(&eem->port);
 }
 
+static void eem_suspend(struct usb_function *f)
+{
+	struct f_eem		*eem = func_to_eem(f);
+	struct usb_composite_dev *cdev = f->config->cdev;
+
+	DBG(cdev, "eem suspended\n");
+
+	if (eem->port.in_ep->enabled)
+		gether_disconnect(&eem->port);
+}
+
+static void eem_resume(struct usb_function *f)
+{
+	struct f_eem		*eem = func_to_eem(f);
+	struct usb_composite_dev *cdev = f->config->cdev;
+	struct net_device	*net;
+
+	DBG(cdev, "eem resumed\n");
+
+	if (!eem->port.in_ep->enabled) {
+		net = gether_connect(&eem->port);
+		if (IS_ERR(net))
+			ERROR(cdev, "%s: eem resume failed, err %d\n",
+			      f->name, PTR_ERR(net));
+	}
+}
+
 /*-------------------------------------------------------------------------*/
 
 /* EEM function driver setup/binding */
@@ -636,6 +663,8 @@ static struct usb_function *eem_alloc(struct usb_function_instance *fi)
 	eem->port.func.set_alt = eem_set_alt;
 	eem->port.func.setup = eem_setup;
 	eem->port.func.disable = eem_disable;
+	eem->port.func.suspend = eem_suspend;
+	eem->port.func.resume = eem_resume;
 	eem->port.func.free_func = eem_free;
 	eem->port.wrap = eem_wrap;
 	eem->port.unwrap = eem_unwrap;
-- 
2.29.2


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux