USB: android: Don't disable configuration for every adb close
Certain ADB commands like "adb usb" and "adb root" restart the
adb daemon running on the device. These commands require USB
bus reset, otherwise adb commands on the host side would stuck
for ever.
USB bus reset can be forced from device side by re-enabling the
same composition. Earlier, configuration is disabled when adb
daemon closes /dev/android_usb device file. The configuration
is enabled again after adb daemon opens the device file. This
approach solves the "adb usb" problem with the below side effects.
1. When USB cable is disconnected, the Rx request is flushed and
an error code is returned to user space. The adb daemon is simply
restarted in this case which cause an unnecessary rebinding of
all functions.
2. The above scenario can happen if host reset the bus when device
is in configured state. If device disable pull-up during, bus
reset, USB CV CH9 test cases are failing.
The commit d9b1897 (USB: android: Avoid re-enabling the same
configuration) fixed the above side effects. But silently ignores the
original "adb usb" problem.
This commit is another attempt to solve all the above mentioned problems
by forcing re-enumeration only when device is in connected state. That
means, "adb usb" and "adb root" commands force usb bus reset where as
plugging out a cable does not.
(cherry picked from commit 1aa235a6c0a3d67bff24609766baf5a7d5d8e3e4)
(cherry picked from commit 81fefe664ab6333f05209bed959a599a47baf71f)
Change-Id: Id3a40f62dd51aba6ec690d3326ed67ced32b946a
CRs-Fixed: 407882
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
diff --git a/drivers/usb/gadget/f_adb.c b/drivers/usb/gadget/f_adb.c
index 3f6234c..7aebc06 100644
--- a/drivers/usb/gadget/f_adb.c
+++ b/drivers/usb/gadget/f_adb.c
@@ -55,6 +55,7 @@
wait_queue_head_t write_wq;
struct usb_request *rx_req;
int rx_done;
+ bool notify_close;
};
static struct usb_interface_descriptor adb_interface_desc = {
@@ -423,8 +424,10 @@
/* clear the error latch */
atomic_set(&_adb_dev->error, 0);
- adb_ready_callback();
+ if (_adb_dev->notify_close)
+ adb_ready_callback();
+ _adb_dev->notify_close = true;
return 0;
}
@@ -432,7 +435,16 @@
{
pr_info("adb_release\n");
- adb_closed_callback();
+ /*
+ * ADB daemon closes the device file after I/O error. The
+ * I/O error happen when Rx requests are flushed during
+ * cable disconnect or bus reset in configured state. Disabling
+ * USB configuration and pull-up during these scenarios are
+ * undesired. We want to force bus reset only for certain
+ * commands like "adb root" and "adb usb".
+ */
+ if (_adb_dev->notify_close)
+ adb_closed_callback();
adb_unlock(&_adb_dev->open_excl);
return 0;
@@ -561,6 +573,12 @@
struct usb_composite_dev *cdev = dev->cdev;
DBG(cdev, "adb_function_disable cdev %p\n", cdev);
+ /*
+ * Bus reset happened or cable disconnected. No
+ * need to disable the configuration now. We will
+ * set noify_close to true when device file is re-opened.
+ */
+ dev->notify_close = false;
atomic_set(&dev->online, 0);
atomic_set(&dev->error, 1);
usb_ep_disable(dev->ep_in);
@@ -607,6 +625,7 @@
atomic_set(&dev->open_excl, 0);
atomic_set(&dev->read_excl, 0);
atomic_set(&dev->write_excl, 0);
+ dev->notify_close = true;
INIT_LIST_HEAD(&dev->tx_idle);