[RFC 1/2] USB: Notify OTG errors to user space via uevents

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

 



OTG specification mandates no silent failures and all errors should
be reported to the user.  The spec itself does not give the exact
error description. But recommends the error message to be self
explanatory.  Provide otg_notify_error() utility for USB core and
OTG driver to send the error codes to user space.  All the error
code values are described in include/linux/usb/ch9.h.  The user space
application can listen to netlink socket and parse the buffer for
"MODULE=OTG" and "ERROR=n", where 'n' contains the error code.

Signed-off-by: Pavankumar Kondeti <pkondeti@xxxxxxxxxxxxxx>
---
 Documentation/ABI/testing/uevent-otg_errors |   12 +++++++++++
 drivers/usb/otg/otg.c                       |   26 +++++++++++++++++++++++++
 include/linux/usb/ch9.h                     |   28 +++++++++++++++++++++++++++
 include/linux/usb/otg.h                     |    6 +++++
 4 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/uevent-otg_errors

diff --git a/Documentation/ABI/testing/uevent-otg_errors b/Documentation/ABI/testing/uevent-otg_errors
new file mode 100644
index 0000000..85b6d3b
--- /dev/null
+++ b/Documentation/ABI/testing/uevent-otg_errors
@@ -0,0 +1,12 @@
+What:		OTG error codes
+Date:		December 2010
+Contact:	linux-usb@xxxxxxxxxxxxxxx
+Description:
+		USB OTG specification mandates no silent failures.  It also
+		recommends the error message to be self explanatory.  All
+		the OTG error codes are described in include/linux/usb/ch9.h
+
+		The error code is notified to user space via uevent. User
+		space application can listen to netlink socket and parse
+		the buffer for "MODULE=OTG" and "ERROR=n" where n has the
+		error code value.
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 0a43a7d..8532a39 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -64,3 +64,29 @@ int otg_set_transceiver(struct otg_transceiver *x)
 	return 0;
 }
 EXPORT_SYMBOL(otg_set_transceiver);
+
+/**
+ * otg_notify_error - Notify the error to userspace via uevent
+ * @err: Error code
+ * Context: can sleep
+ *
+ * This function sends an uevent with the following extra env
+ * variables.
+ *
+ * MODULE=OTG
+ * ERROR=err
+ */
+int otg_notify_error(unsigned err)
+{
+	char module_name[16], error_code[16];
+	char *envp[] = { module_name, error_code, NULL };
+
+	if (!xceiv)
+		return -ENODEV;
+
+	snprintf(module_name, 16, "MODULE=%s", "OTG");
+	snprintf(error_code, 16, "ERROR=%u", err);
+
+	return kobject_uevent_env(&xceiv->dev->kobj, KOBJ_CHANGE, envp);
+}
+EXPORT_SYMBOL(otg_notify_error);
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index ab46194..4053d3b 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -884,4 +884,32 @@ enum usb_device_state {
  */
 #define USB_SELF_POWER_VBUS_MAX_DRAW		100
 
+/*
+ * OTG specification mandates no silent failures. The following errors must
+ * be reported to the user.
+ *
+ * USB_OTG_DEV_CONNECT_TIMEOUT_ERROR: When B-device is not attached to the
+ * A-device within Ta_WAIT_BCON time.
+ *
+ * USB_OTG_HNP_ENABLE_ERROR: When B-device is failed to accept B_HNP_ENABLE
+ * feature request.
+ *
+ * USB_OTG_DEV_NOT_SUPPORTED_ERROR: When the attached peripheral is not found
+ * in the Targeted Peripheral List (TPL) of the host device.
+ *
+ * USB_OTG_HUB_NOT_SUPPORTED_ERROR: When HUB class devices are not supported by
+ * the host device.
+ *
+ * USB_OTG_HNP_FAILED_ERROR: When an error occurred during HNP.
+ *
+ * USB_OTG_NO_RESP_FOR_SRP_ERROR: When A-device does not respond to B-device's
+ * SRP request.
+ */
+#define USB_OTG_DEV_CONNECT_TIMEOUT_ERROR	1
+#define USB_OTG_HNP_ENABLE_ERROR		2
+#define USB_OTG_DEV_NOT_SUPPORTED_ERROR		3
+#define USB_OTG_HUB_NOT_SUPPORTED_ERROR		4
+#define USB_OTG_HNP_FAILED_ERROR		5
+#define USB_OTG_NO_RESP_FOR_SRP_ERROR		6
+
 #endif /* __LINUX_USB_CH9_H */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 0a5b371..3a91776 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -167,6 +167,7 @@ otg_shutdown(struct otg_transceiver *otg)
 #ifdef CONFIG_USB_OTG_UTILS
 extern struct otg_transceiver *otg_get_transceiver(void);
 extern void otg_put_transceiver(struct otg_transceiver *);
+extern int otg_notify_error(unsigned err);
 #else
 static inline struct otg_transceiver *otg_get_transceiver(void)
 {
@@ -176,6 +177,11 @@ static inline struct otg_transceiver *otg_get_transceiver(void)
 static inline void otg_put_transceiver(struct otg_transceiver *x)
 {
 }
+
+static int otg_notify_error(unsigned err)
+{
+	return -ENODEV;
+}
 #endif
 
 /* Context: can sleep */
-- 
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

  Powered by Linux